Thursday, 27 March 2008

Argument list too long

If there are many files and your ls, rm or mv commands not working you can use one of these

find /path/to -name 'yourfiles*' | xargs rm
find /path/to -name 'yourfiles*' | xargs -i mv {} anildel/
find /path/to -name 'yourfiles*' -exec rm '{}' \;
find /path/to -name 'yourfiles*' -exec rm '{}' +

Wednesday, 12 March 2008

Sendmail Troubleshooting

First of all I recommend enabling logging. Edit /etc/syslog.conf and be careful about using tab between entries.
mail.debug /var/log/mail.log

Restart syslog daemon
/etc/init.d/syslog restart

Check /var/log/mail.log.
You can find brief information about sendmail Email flow

Also some troubleshooting docs from HP

Shell script Get the time difference

Get difference

date1=`date +%s`
date2=`date +%s`
date -d "00:00:00 $(( ${date2} - ${date1} )) seconds" +"%H:%m:%S"

Wednesday, 5 March 2008

Sed and awk, find pattern and get next lines

Search pattern and print next two lines. You can add more getline and print here for awk and n;p for sed. Also you can do it via +2p

awk '/pattern/{getline;print;getline;getline;print}' file
sed -n '/pattern/{n;p;n;p;}' file
sed -n '/pattern/,+2p' file

Get between two pattern

awk '/pattern1/,/pattern2/' file
sed -n '/pattern1/,/pattern2/p' file

This is small script do same another way.

bgn=$(grep -n $pattern scsconfig.log awk -F: {'print $1'})
ed=`expr $bgn + 3`
cat scsconfig.log sed -n ''$bgn','$ed'p'