Monday, November 05, 2007

mdb display options (64-bit vs 32-bit) [42]

To see whether to use the \D or \E display option in mdb: You can run nm and see whether the variable is 4 or 8 bytes. If it's 8 bytes (64 bit) then you need to use /E otherwise /D.
-bash-3.00$ /usr/ccs/bin/nm /dev/ksyms |grep maxpgio
[23962] | 25553712| 8|OBJT |GLOB |0 |ABS |maxpgio
In the above example the third column tells us that this maxpgio is 8 byte object therefore we need to use /E
[root@db31:/] mdb -k
Loading modules: [ unix krtld genunix specfs dtrace ufs sd pcisch ip sctp usba fcp fctl ssd md fcip cpc random crypto logindmux ptm nfs ]
> maxpgio/E
maxpgio:
maxpgio: 40
> maxpgio/J
maxpgio:
maxpgio: 28

Use the option /J when you want the value to be displayed as hex.

Tuesday, August 08, 2006

Check disk space [41]

Check disk space (requires bssh)

sudo bssh `cat dbs | tr '\n' ','` 'df -h' > logs/disk_report.080806

Sunday, July 23, 2006

Managing Foreground and Background Jobs and Processes [32-40]

Unix system administrators often need to switch and move jobs from foreground to background and vice versa.
[32] To stop (not kill) a currently running job and return to shell, you can use Ctrl-z.
[33] Then to view the stopped jobs during the current session
jobs
[34] To kill a stopped job number 2
kill -9 %2
[35] Check the status of processes in all sessions running by user frankly
ps -u frankly
[36] Kill a process by its process id (822)
kill -9 822
[37] Bring the job that was sent most recently sent to run in background to foreground
fg
[38] Bring the background job with job id 2 to run in the foreground
fg %2
[39] Start running the most recently stopped job in the background
bg
[40] Run a job in the background
Add & to end of the command

Sunday, July 16, 2006

Copy MySQL tables between different hosts [31]

The following command will allow you to copy MySQL tables between different hosts


mysqldump -h ip -uuser -ppass from_db from_table | mysql -uuser -ppass target_db

Monday, June 19, 2006

Run a command on multiple MySQL hosts

cat /lists/dbs | while read i ; do echo $i; /path/to/mysql -h $i -e "SHOW variables like 'old%'"; done


This programming one liner allows you to run a command on multiple MySQL hosts. To use this command, simply create a file dbs with all the MySQL hosts (one per line). The sample command prints the value of whether the database is using old passwords.

Friday, March 10, 2006

IPCS remove semaphores

If you get an error message saying
"HTTPD dead but PID exists", your disk space is either full or all IPCS semaphores have been used up.

ipcs -s | awk ' $3 == "apache" {print $2, $3}' | awk '{ print $1}' | while read i; do ipcrm sem $i; done


Clean up ipcs semaphores

Thursday, March 09, 2006

Remove blank / empty lines PHP [29]

I found this great implementation to remove blank (empty lines) from a string at PHP web site.


function removeEmptyLines($string)
{
return preg_replace("/(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+/", "\n", $string);
}

Tuesday, January 24, 2006

PHP clean filename

Clean a string for filename


`echo "$clean" | tr A-Z a-z | tr "[]()&~@#$%^&*()_+=;:,.!' " "-" `;


This programming one liner allows you to clean the unwanted characters in a string. The list of characters is specified as the first parameter to the tr command.


Programming "One Liner" lookup terms:
str_replace tr

USE THIS PROGRAMMING ONE LINER AT OWN RISK AS AUTHOR CLAIMS NO RESPONSIBILITY.
If you would like more information on any of the commands, please feel free to contact me with your . You can also read other posts on programming code, lookup the programming terms displayed above or visit my network security blog. Other external programming blogs on Technorati and programming blogs on Google.

Wednesday, November 16, 2005

fr - Find and replace software tool for Linux

fr - find and replace text utility


##########################################################
### Find and Replace Script by Frank Mash ###
##########################################################
--> Usage: /sbin/fr [filename] [search] [replace] [b] [i]
--> ################# EXAMPLES #############################
--> EXAMPLE 1: Find 'Apples' and Replace with 'Oranges'. Create a backup of file and proceed in Interactive mode
----> fr /path/to/file.txt Apples Oranges b i
--> EXAMPLE 2: Find 'Apples' and Replace with 'Oranges'. Create a backup of file and proceed in Non-Interactive mode
----> fr /path/to/file.txt Apples Oranges b
--> EXAMPLE 3: Find 'Apples' and Replace with 'Oranges'. Don't create a backup of file and proceed in Non-Interactive mode
----> fr /path/to/file.txt Apples Oranges
--> ################# END EXAMPLES #########################
--> ################# NOTES ################################
----> Currently you cannot proceed in Interactive mode without creating a backup
--> ################# END NOTES ############################
--> You entered: /sbin/fr help


This custom programming one liner allows you to find and replace using one line. E-mail me at softwareengineer99 on Yahoo's e-mail service if you would like the source code.


Custom programming "One Liner" lookup terms:
fr sed grep

USE THIS PROGRAMMING ONE LINER AT OWN RISK AS AUTHOR CLAIMS NO RESPONSIBILITY.
If you would like more information on any of the commands, please feel free to contact me with your . You can also read other posts on programming code, lookup the programming terms displayed above or visit my network security blog. Other external and blogs on Technorati.

Sunday, November 13, 2005

AWK - Find - Delete Second Field/Column - One Liner 25 - 26

AWK


awk '/PATTERN/ {print "PATTERN FOUND"}' /var/awk_programming_test


This programming one liner allows you to search for PATTERN in awk_programming_test file. Once the pattern is found, the print statement is invoked .




AWK - Delete second column


Programming One Liner 26

awk ' BEGIN{FS=",";} { $2= ""; print}' /var/awk_programming_test


This programming one liner allows you to delete the second field in the specified CSV and the results are displayed on the screen. If the file /var/awk_programming_test had the following contents:



redhat,linux web server
fedora,linux web server
xp,windows dedicated server
windows 98,windows dedicated server
solaris,sun web server



Then invoking the one liner # 26 will produce the following results


redhat
fedora
xp
windows 98
solaris




Programming "One Liner" lookup terms:
awk





USE THIS PROGRAMMING ONE LINER AT OWN RISK AS AUTHOR CLAIMS NO RESPONSIBILITY.
If you would like more information on any of the commands, please feel free to contact me with your . You can also read other posts on programming code, lookup the programming terms displayed above or visit my network security blog. Other external , , and blogs.

GCC version - Programming One Liner 24

GCC: Finding the GCC Version


gcc --version


This programming one liner allows you to find which version of gcc (compiler) is installed on your linux server.


Programming "One Liner" lookup terms:
gcc

USE THIS PROGRAMMING ONE LINER AT OWN RISK AS AUTHOR CLAIMS NO RESPONSIBILITY.
If you would like more information on any of the commands, please feel free to contact me with your . You can also read other posts on programming code, lookup the programming terms displayed above or visit my network security blog. Other external , and blogs on Technorati .

List signal names - One liner 23

Signal Names


fuser -l


This programming one liner allows you to output signal names using fuser. Linux signal names are displayed as follows



[root@plain docs]# fuser -l
HUP INT QUIT ILL TRAP ABRT IOT BUS FPE KILL USR1 SEGV USR2 PIPE ALRM TERM
STKFLT CHLD CONT STOP TSTP TTIN TTOU URG XCPU XFSZ VTALRM PROF WINCH IO PWR SYS
UNUSED



Programming "One Liner" lookup terms:
fuser

USE THIS PROGRAMMING ONE LINER AT OWN RISK AS AUTHOR CLAIMS NO RESPONSIBILITY.
If you would like more information on any of the commands, please feel free to contact me with your programming questions. You can also read other posts on programming code, lookup the programming terms displayed above or visit my network security blog. Other external blogs on Technorati and blogs.


Wednesday, November 02, 2005

gunzip multiple files - Programming OneLiner 22

Gunzip


gunzip site*.gz


This programming one liner allows you to unzip / gunzip all files beginning with site and ending with .gz within the current directory


Programming "One Liner" lookup terms:
gunzip gzip

USE THIS PROGRAMMING ONE LINER AT OWN RISK AS AUTHOR CLAIMS NO RESPONSIBILITY.
If you would like more information on any of the commands, please feel free to contact me with your programming questions. You can also read other posts on programming code, lookup the programming terms displayed above or visit my network security blog. Other external blogs on Technorati and blogs on Google.

Sunday, October 30, 2005

Investigating all open ports on Linux web server - Programming One Liner 18 - 21

Unneeded open ports can be costly for your business!


If you have unneeded and unexplained ports open on your server, you are calling for trouble.


nmap -p 1-65535 localhost


This programming one liner allows you to look for all open ports (ports that are currently listening) on your Linux server.


Programming "One Liner" lookup terms:
nmap fuser

Output of running the above command will produce something similar to:


Starting nmap V. 3.00 ( www.insecure.org/nmap/ )
Interesting ports on localhost.localdomain (127.0.0.1):
(The 65517 ports scanned but not shown below are in state: closed)
Port State Service
21/tcp open ftp
22/tcp open ssh
53/tcp open domain
80/tcp open http
110/tcp open pop-3
143/tcp open imap2
199/tcp open smux
443/tcp open https
631/tcp open ipp
783/tcp open hp-alarm-mgr
953/tcp open rndc
993/tcp open imaps
995/tcp open pop3s
3306/tcp open mysql
5981/tcp open unknown
6001/tcp open X11:1

Nmap run completed -- 1 IP address (1 host up) scanned in 155 seconds


Investigating a port


Which process is using the port? Programming One Liner 19

If you are interested in looking up which process is using the port, use the following fuser command. We are investigating port 783 which is currently open for the service named hp-alarm-mgr.


fuser -n tcp 783


The output of fuser is as follows

783/tcp: 2385




Finding the process owner


Who owns the process? Programming One Liner 20

Now that we know the process id (pid), we can find out details about the process.


cat /proc/2385/status


The status information will include a lot of details about the process.

Name: spamd
State: S (sleeping)
Tgid: 2385
Pid: 2385
PPid: 1
TracerPid: 0
Uid: 0 0 0 0
Gid: 0 0 0 0
FDSize: 32
Groups:
VmSize: 22920 kB
VmLck: 0 kB
VmRSS: 716 kB
VmData: 16664 kB
VmStk: 72 kB
VmExe: 12 kB
VmLib: 3944 kB
SigPnd: 0000000000000000
ShdPnd: 0000000000000000
SigBlk: 0000000000000000
SigIgn: 0000000000010080
SigCgt: 0000000080005002
CapInh: 0000000000000000
CapPrm: 00000000fffffeff
CapEff: 00000000fffffeff



We can see the software package running the process is spamd and its owned by uid 0 (super user).



What command was used to run the process? Programming One Liner 21

The status information will include a lot of details about the process.



To find further details, such as the command used to invoke the process:


ps 2385



We can see the following details:


PID TTY STAT TIME COMMAND
2385 ? S 0:00 /usr/bin/spamd -d -c -a



Programming "One Liner" lookup terms:
nmap fuser cat




USE THIS PROGRAMMING ONE LINER AT OWN RISK AS AUTHOR CLAIMS NO RESPONSIBILITY.
If you would like more information on any of the commands, please feel free to contact me with your . You can also read other posts on programming code, lookup the programming terms displayed above or visit my network security blog. Other external programming blogs on Technorati and programming blogs on Google.

Watch /var/log/messages for SSH intruders - Programming One Liner 17

Monitoring /var/log/messages


date >> /user/security/ssh-intruders.log ; cat /var/log/messages* | grep -i "sshd.*authentication failure" | sort | awk '{FS="rhost="; print $2}' | awk '{FS="user="; print $1}' | grep ".*\..*\." | grep -v "knownhost.com" | grep -v "knownhost2.com" | sort | uniq | while read i; do counter=`grep -i "$i" /var/log/messages* | wc -l` ; echo "$counter attempts by $i"; done >> /user/security/ssh-intruders.log ; cat /user/security/ssh-intruders.log


This programming one liner allows you to query /var/log/messages files for break-in attempts. Prints the total count of attempts by each intruder.


The following output (sample) is produced


3 attempts by 163.27.207.193
2 attempts by 84.243.73.25
14 attempts by ali.2kads.cz
17 attempts by c66.110.175-222.clta.globetrotter.net
9 attempts by pro-177.im.cju.edu.tw
9 attempts by pro-177.im.cju.edu.tw


Programming "One Liner" lookup terms:
cat awk sed sort uniq wc date

USE THIS PROGRAMMING ONE LINER AT OWN RISK AS AUTHOR CLAIMS NO RESPONSIBILITY.
If you would like more information on any of the commands, please feel free to contact me with your . You can also read other posts on programming code, lookup the programming terms displayed above or visit my network security blog. Other external programming blogs on Technorati and programming blogs on Google.

Saturday, October 29, 2005

Query RPM packages for information - Programming One Liner 16

Get information about a RPM


[root@plain home]# rpm -qip gnome-desktop-2.2.2-2.2E.src.rpm
Name : gnome-desktop Relocations: (not relocatable)
Version : 2.2.2 Vendor: Red Hat, Inc.
Release : 2.2E Build Date: Wed 20 Jul 2005 04:12:27 PM CDT
Install Date: (not installed) Build Host: crowe.devel.redhat.com
Group : System Environment/Libraries Source RPM: (none)
Size : 1081813 License: GPL
Signature : DSA/SHA1, Wed 10 Aug 2005 03:04:49 AM CDT, Key ID 219180cddb42a60e
Packager : Red Hat, Inc.
URL : http://www.gnome.org
Summary : Package containing code shared among gnome-panel, gnome-session, nautilus, etc.
Description :
The gnome-desktop package contains an internal library
(libgnomedesktop) used to implement some portions of the GNOME
desktop, and also some data files and other shared components of the
GNOME user environment.


This programming one liner allows you to display RPM (Red Hat package manager) information.


Programming "One Liner" lookup terms:
rpm
Options used
-q = query
-i = information
-p = packages

USE THIS PROGRAMMING ONE LINER AT OWN RISK AS AUTHOR CLAIMS NO RESPONSIBILITY.
If you would like more information on any of the commands, please feel free to contact me with your . You can also read other posts on programming code, lookup the programming terms displayed above or visit my network security blog. Other external programming blogs on Technorati and programming blogs on Google.

Send a message to all users - Programming One Liner 15

Broadcasting a message


wall


This programming one liner allows you to everyone connected to a terminal. Simply type wall, enter the message and press Ctrl-d to send it.



[root@plain user]# wall
fixed

Broadcast message from root (pts/0) (Sat Oct 29 22:52:36 2005):

fixed



Programming "One Liner" lookup terms:
wall

USE THIS PROGRAMMING ONE LINER AT OWN RISK AS AUTHOR CLAIMS NO RESPONSIBILITY.
If you would like more information on any of the commands, please feel free to contact me with your . You can also read other posts on programming code, lookup the programming terms displayed above or visit my network security blog. Other external programming blogs on Technorati and programming blogs on Google.

Create and verify a tarball for a directory - Programming One Liner 14

tar - working with tarballs


tar -Wcvf /user/backups/site6-fst.tar etc home var >/designerz/backups/log.site6.fst.bk


This programming one liner allows you to create a verified archive. The command generates all files processed to the screen.


Programming "One Liner" lookup terms:
tar

USE THIS PROGRAMMING ONE LINER AT OWN RISK AS AUTHOR CLAIMS NO RESPONSIBILITY.
If you would like more information on any of the commands, please feel free to contact me with your . You can also read other posts on programming code, lookup the programming terms displayed above or visit my network security blog. Other external programming blogs on Technorati and programming blogs on Google.

Process Information - Programming One Liner 12 - 13

ps - process information


ps 316


For a currently running process, you can use ps with the process id (pid) to see information about the process and to verify that its still running.


Programming "One Liner" lookup terms:
ps


Programming One Liner 13
See all processing currently running (started by you)

[root@plain html]# ps
PID TTY TIME CMD
20056 pts/5 00:00:05 bash
316 pts/5 00:07:53 tar
3302 pts/5 00:00:00 ps



USE THIS PROGRAMMING ONE LINER AT OWN RISK AS AUTHOR CLAIMS NO RESPONSIBILITY.
If you would like more information on any of the commands, please feel free to contact me with your . You can also read other posts on programming code, lookup the programming terms displayed above or visit my network security blog. Other external programming blogs on Technorati and programming blogs on Google.

Restoring files from an old hard drive to new drive - Programming One Liner 11

Using rsync to restoring directories between two drives


rsync -vrplogDtH /olda/dir /home/dir


This programming one liner allows you to restore / copy files from one hard drive to another. This can be useful in cases when you have a hacked hard drive as slave attached to your web server and now you want to restore files.


Programming "One Liner" lookup terms:
rsync rcp
Brief explanation of options used with rsync for restoring files between hard drives.
-v, --verbose increase verbosity
-r, --recursive recurse into directories
-p, --perms preserve permissions
-l, --links copy symlinks as symlinks
-o, --owner preserve owner (root only)
-g, --group preserve group
-D, --devices preserve devices (root only)
-t, --times preserve times
-H, --hard-links preserve hard links


USE THIS PROGRAMMING ONE LINER AT OWN RISK AS AUTHOR CLAIMS NO RESPONSIBILITY.
If you would like more information on any of the commands, please feel free to contact me with your . You can also read other posts on programming code, lookup the programming terms displayed above or visit my network security blog. Other external programming blogs on Technorati and programming blogs on Google.