Home Shell snippets

shell snippets

Attention: open in a new window. PDFPrintE-mail

Here you will find Bash, Perl, PHP and other useful code snippets.


m4 /usr/share/sendmail-cf/m4/cf.m4 sendmail.mc > sendmail.cf

m4 /usr/share/sendmail-cf/m4/cf.m4 submit.mc > submit.cf

Mount ISO image

mount -o loop image.iso /mnt/mountpoint

Create ISO image with dd from DVD or CD

dd if=/dev/dvd of=/tmp/image.iso

Create ISO image from a directory

mkisofs -o /tmp/image.iso /tmp/directory/

Compare iso image with original DVD or CD

cmp /dev/dvd /tmp/image.iso

Unpack rpm file

rpm2cpio < package.rpm > temp.cpio

cpio --make-directories -F temp.cpio -i

rm -f temp.cpio

Get sizes of a Veritas VM managed diskgroup

vxassist -g [diskgroup] maxgrow [volume]

vxassist -g [diskgoup] maxsize

vxdisk list #list all disks

vxprint -hrt #get disk and volume information

vxprint -l #get extendet disk and volume information

Get the whole size of all disks
vxprint -ht | grep cx700 | grep dm | awk 'BEGIN {s=0} {s=s+$6} END {print s/2097152, "GB"}'
Get the used size
vxprint -ht | grep cx700 | grep sd | awk 'BEGIN {s=0} {s=s+$6} END {print s/2097152, "GB"}'

If you grep for a device like c2t2d2 you will get the result only for this device not for the whole LUN

Execute a code on many machines

open a file and edit.


hostlist="host1 host2 host3 host4 host5 host6";
for i in $hostlist do
ssh -l root $i "tail -10 /var/log/messages" >> $i.log

MySQL dump

mysqldump -u username --password=secret --opt database > backup.sql

Pack with tar and GZip

tar czf backup.tar.gz /var/log

Find and delete 7 days old core and dead.letter files

find / -xdev -type f '(' -name core -o -name dead.letter ')' -atime +7 -mtime +7 -exec rm -i '{}' ';'

Check for open Ports on remote machines

nmap -sT -O hostname

nmap -sT -O -p 23 hostname #check only for telnet port 23