1833315 Members
3066 Online
110051 Solutions
New Discussion

Re: shell script

 
SOLVED
Go to solution
vas  bolpali
Advisor

shell script

hello,
i need to create a shell script
step 1. look for the file - mail_file.dat in '/watch' directory.
step 2. rename with time stamp. move it to '/log' directory.
step 3. run a job(script) 'cst101.shl' as the abou file as input parameter.
like - cst101.shl mail_file_mmddyy.da0t
step 4. if it fails send the 'unable to run script at step 1/step2/step3'
to a 'scott@mail.com, lance@mail.com'

one more question

5. how to send a command(like 'df') output to ' scott@mail.com'


thanks in advance.

vasu
keeping you ahead of the learning curve
3 REPLIES 3
Kevin Wright
Honored Contributor

Re: shell script

these man pages should help
grep
mv
mailx sendmail

for the script..
grep file /watch
mv file /log
touch -t /log/file

df -k > /tmp/dfout
/usr/lib/sendmail user@domain.com < /tmp/dfout

Andreas Voss
Honored Contributor

Re: shell script

Hi,

here my suggestions:

if [ -s /watch/mail_file.dat ]
then
newname=/log/mail_file_$(date +%m%d%y.dat).dat
mv /watch/mail_file.dat $newname
cst101.shl $newname
if [ $? != 0 ]
then
echo "unable to run script $newname"|mail scott@mail.com lance@mail.com
fi
fi

Qestion 5: df | mail scott@mail.com

Regards
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: shell script

Hi Vasu:

I've attached a 2 minute script that should be very close (with a little more work, you coud make a cron job out of it):

to send mail:
df | mail scott@mail.com

That does make the big assumption that you have sendmail configured.

Clay
If it ain't broke, I can fix that.