Need to write a cron jon(tcsh)....Help me out!!


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need to write a cron jon(tcsh)....Help me out!!
# 1  
Old 02-22-2007
Need to write a cron job(tcsh)....Help me out!!

The question I personally have is will it be possible to design the cron job according to this ‘wish list':

1)Every time cron starts (I mean files are found and processing begins) - email send to a user or to a group of users.
2)The job is divided into 2 separate parts, 2nd jobs starts only after first one has completed
a) All xxx, yyy and zzz(file names)
b) aaa and bbb files
3)At the end of an each job an email is sent to me &co, notifying that job completed.
4) If job fails for whatever reason an email is send to me &co with description (as useful as possible) with a problem.


Please help me...me new to scripting....'
thanks in advance...

Last edited by kumarsaravana_s; 02-22-2007 at 02:34 PM..
# 2  
Old 02-22-2007
Bug

Yes, It is possible to achieve your requirements.

1)Every time cron starts (I mean files are found and processing begins) - email send to a user or to a group of users.

Ans. try this command
Code:
ls filename >output 
if [ -s output ]; then

echo "THE FILE FOUND" | mailx -s "The file  found" userid@domainname.com 
else
echo "THE FILE NOT FOUND" |mailx -s "The file not found" userid@domainname.com 
fi

2)The job is divided into 2 separate parts, 2nd jobs starts only after first one has completed
a) All xxx, yyy and zzz(file names)
b) aaa and bbb files


ANS: you could have a wrapper script where in you could call other scripts something like this

in the wrapper script:
Code:
. /xxx

if [ $? -ne 0 ]; then
echo "ERROR xxx failed to execute"
exit 1
fi

# below code will run only when xxx is complete
. /aaa 

if [ $? -ne 0 ]; then
echo "ERROR xxx failed to execute"
exit 1
fi

Note: Make sure you put an exit 0 at the end of the script and exit 1 where ever you exit with error.

3)At the end of an each job an email is sent to me &co, notifying that job completed.

Ans: continuing with the pervious code you could add and else statement in the if condition something like this
Code:
. /xxx

if [ $? -ne 0 ]; then
echo "ERROR xxx failed to execute"
exit 1
else 
echo "JOB xxx EXECUTED SUCCESSFULLY" | mailx -s "JOB aaa executed successfully" email@email.com
fi

# below code will run only when xxx is complete
. /aaa 

if [ $? -ne 0 ]; then
echo "ERROR aaa failed to execute"
exit 1
else 
echo "JOB aaa EXECUTED SUCCESSFULLY" | mailx -s "JOB aaa executed successfully" email@email.com
fi

4) If job fails for whatever reason an email is send to me &co with description (as useful as possible) with a problem.

ANS: in the previous code you could add the mail command in the if condition itself

Code:
. /xxx

if [ $? -ne 0 ]; then
echo "ERROR xxx failed to execute"
echo "JOB xxx FAILED" |mailx -s "JOB aaa FAILED" email@email.com
exit 1
else 
echo "JOB xxx EXECUTED SUCCESSFULLY" |mailx -s "JOB aaa executed successfully" email@email.com
fi

# below code will run only when xxx is complete
. /aaa 

if [ $? -ne 0 ]; then
echo "ERROR xxx failed to execute"
echo "aaa JOB FAILED" |mailx -s "JOB aaa FAILED" email@email.com
exit 1
else 
echo "JOB aaa EXECUTED SUCCESSFULLY" | mailx -s "JOB aaa executed successfully" email@email.com
fi


Last edited by ahmedwaseem2000; 02-22-2007 at 03:04 PM..
# 3  
Old 02-22-2007
Thanks a lot Ahmed

Hey Ahmed...Thanks for ur immediate reply...i really appreciate it...Thanks a ton...i will try this and will get back to you if i come up with some issues...
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Add TimeStamp to cron job and write file name sent

Hello, I have written a cron job to automate the sftp of files using key authentication. I wanted to add a timeStamp and name of file sent to a log file and append each these details to the same file each time files are sent and if possible include whether the files were sent successfully or not.... (3 Replies)
Discussion started by: KidKoder
3 Replies

2. Shell Programming and Scripting

Is it possible to write write multiple cronjobs in shellscript??

Hi All, I need the answer of below question? 1) How to write multiple cronjobs in shellscript? Is there any way or we cant write in shellscript... Regards, Priyanka (2 Replies)
Discussion started by: pspriyanka
2 Replies

3. Shell Programming and Scripting

How to write cron job for calling sql function database is postgres

Hi, Please help me to write cron job for calling sql function daily. I have Postgres database. (1 Reply)
Discussion started by: kulbhushan
1 Replies

4. IP Networking

read/write,write/write lock with smbclient fails

Hi, We have smb client running on two of the linux boxes and smb server on another linux system. During a backup operation which uses smb, read of a file was allowed while write to the same file was going on.Also simultaneous writes to the same file were allowed.Following are the settings in the... (1 Reply)
Discussion started by: swatidas11
1 Replies

5. AIX

AIX and cron logs filtering ?: /etc/cronlog.conf, /var/adm/cron/log

Hi, I can use 'crontabs –e' and do all the scheduling I like. However I would like to auto send myself just the cronjobs logs that fail. That is to say the PIDs that fail and the related lines with those PID’s only. (Not the full set of logs) Has anyone done this work? Or does an AIX 5.3 tool... (0 Replies)
Discussion started by: Keith Johnson
0 Replies

6. UNIX for Dummies Questions & Answers

Can I write a cron to do this?

OK, I'm new to UNIX so please be patient. I'm wondering if I can set up a cron task on my web server(unix) to control a flash based mp3 player like xspf. What I would like to accomplish is to have xspf player (on my web site) play one new mp3 every 24hrs. So song one would start at 00:02 and... (2 Replies)
Discussion started by: kvk
2 Replies

7. UNIX for Dummies Questions & Answers

Write a cron script

Hi all techie geniuses, I am new to the tehc field and need some help badly. I need a ksh script. Every time a file is dropped in a folder, there should be a script running at all times. What this script does is, simply copies this file in a different folder with timestamps as part of the new... (0 Replies)
Discussion started by: ketanr
0 Replies

8. News, Links, Events and Announcements

Jon Johansen cleared in landmark DVD case

http://www.cnn.com/2003/TECH/01/07/dvd.johansen/index.html (1 Reply)
Discussion started by: Neo
1 Replies
Login or Register to Ask a Question