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.