Simple scripts

I would like to share my simple scripts that I found useful while working for the Open Systems Lab(OSL) as a System Administrator

lsof

Sometimes my system is in trouble with the high loadaverage of the web server because of the attack of some malicious IPs.
I have tried to look for a command to get the IPs which make this kind of trouble by looking into its pid.

      lsof -nP -w -T -i tcp | grep httpd | grep <PROCESS_ID_TO_CHECK>

diff

Sometimes I want to find the diffs between my local file and remote file or between remote files. Here is a simple trick.

      diff <LOCAL_FILE <(ssh remote_host_1 cat REMOTE_FILE)
      diff <(ssh remote_host_1 cat REMOTE_FILE_1)  <(ssh remote_host_2 cat REMOTE_FILE_2)

(Note, where remote_host_1 and remote_host_2 should be setup with your ssh-key stuff and you should not need to put your password or passphrase. Unfortunately, this works only on bash)

dump and restore

dump and restore are a sysadmin's friend. They really make it easy for sysadmin to handle the backup of a system. There may be some applications to replace the command dump and restore but I would like to be stuck with them untli I find something better than them.
Do you know that we can simply dump the whole partition and restore it on the remote machine? So, we can migrate the whole system with a following simple script using dump and restore

      ssh remote_host(_IP) -n dump 0cf - / | restore xf -

I found this tip when Bruce, the CS sysadmins at IU, helped to migrate one of the very important servers of the OSL. I would like to give special thanks to Bruce.

Note

  • The target machine where you want to migrate a system should be clean(or empty) to take the whole system of the remote machine assuming it has enough space to restore the dump file.
  • Reboot your target machine to go to a single-user mode. (e.g., I usually do with my linux installation CD)
  • Run the above script at the target machine.
  • Of course, the ssh-key stuff should be setup without having to put your password or passphrase.

Mount ISO file

mount -o loop -t iso9660 file.iso /mnt/test
blog/linux/simple_scripts.txt · Last modified: 2008/02/06 07:28 by donginn
Back to top
Open Systems Lab
Indiana University Computer Science Department
Lindley Hall 215
150 S. Woodlawn Ave.
Bloomington, IN 47405-7104

chimeric.de = chi`s home Creative Commons License Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0