HYDT: Useful Unix commands

crontab -e [ e for edit ],  -l [ l for list ] ,  -r [ remove crontab ]

#Remove old backup files ( Say every Saturday 11.00 pm)
00 23 * * 6 find /home/backup/logs -name “*.log” -mtime +1 -exec rm -f ‘{}’ \; >> /tmp/rmlog.out

##  Script . cron tab entry to run a script – Runs every 10 Minutes 9 am to 7 pm , Mon to Fri
0,10,20,30,40,50 9-17 * * 1-5 cd /home/user1; ./myscript.sh > /tmp/myscriptlog.out

===========================================

How much space a directory and its contents are taking up
du -ksh <directory>
What unix mount?
df -k <directory>
What version of OS?
uname -a

Display all processes running on box
Linux
ps -auwwxx
Solaris
ps -eaf | grep <login>

==================================================

Sample code to compose and Send email using send mail

varINFile=`ls -l /home/mydata/IN`
varFileName=`echo $varINFile | cut -d ‘ ‘ -f11`
varDateFromFileName=`echo $varFileName | cut -d ‘_’ -f3`
varProcessDate=`echo $varDateFromFileName | cut -d ‘.’ -f1`
varProcessRunDate=`date -d $varProcessDate +”%d-%m-%Y”`
(
echo “Subject: Job Processing Status report | $varProcessRunDate”
echo “MIME-Version: 1.0”
echo “Content-Type: text/html”
echo “Content-Disposition: inline”
echo “Reply-to: abc@xyz.com”
cat /path/to/HTML/File/email.html
) | /usr/sbin/sendmail -f”me@mailing.com” To:”abc@xyz.com” Cc:”aaa@def.com”

How much space a directory and its contents are taking up
du -ksh <directory>
What unix mount?
df -k <directory>
What version of OS?
uname -a
cat /etc/*-release
Display all processes running on box (for logged in username)

Linux
ps -auwwxx | grep username

Solaris
ps -eaf | grep username

Advertisements