Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Crontab file 1

Status
Not open for further replies.

apr1004

Programmer
May 1, 2003
10
SG
Hi,

Is it possible to cron a script which is editing crontab file.

eg:
test1.sh
Submitting the following jobs to crontab based on some condition (either 1.sh or 2.sh )
10 10 * * * * $input

test2.sh
submitting the test1.sh to crontab everyday
0 1 * * * * test2.sh

Can anyone help me,

Thanks,

apr1004.


 
Don't really understand what you mean - are you trying to edit the crontab file using cron as the means to kick off the script to edit it, or is that a misunderstanding?
 
I want to schedule a job every day moring 1am which inturn shedule another job at a perticular time based on some condition.



 
You might be better off including in your script a test for the condition, then running it as an at job from within the script. Alternatively, test the condition then let your script sleep for the desired time before kicking off the other job. HTH.
 
Thanks,

I'll try it out and let you,


thanks for the reply,
apr1004.

 
You could do what you originally asked by doing the following -


echo "30 * * * * your command" >> /var/spool/cron/crontabs/username

Make sure all file permissions & ownerships are the same after the the echo.

The only problem I can see is removing the line, you'd have to create some sed or do something like

a=`wc -l /var/spool/cron/crontabs/username|awk '{print $1}'
b=$(($a-1))
tail -$b /var/spool/cron/crontabs/username > /var/spool/cron/crontabs/username.new
mv /var/spool/cron/crontabs/username.new /var/spool/cron/crontabs/username

and again check file perms - ABOVE NOT TESTED

Kens is a much cleaner way of doing things as its not generally a good idea to edit the crontabs manually.

Another way would be to kick off the job at 1am but include a sleep that could be changed depending on a condition, but again Kens solution is favorite.

Mike

--
| Mike Nixon
| Unix Admin
|
----------------------------
 

Try do a Script something like this

my_cron.sh

crontab -l > /tmp/new_cron.out

if [ $COND = "VARIABLE" ]
then
echo "00 23 * * * command" >> /tmp/new_cron.out
crontab /tmp/new_cron.sh
else
echo "Cron will not be changed this time - condition not meet" | mailx -s "my cr
on message" xxxxxx@mail.com
fi
 
Hi,

I had another problem,

crontab -l > temp_cron
I want to edit this crontab file

temp_cron is as follwos:

10 10 08 05 * /usr/people/xxxx/rrsch.sh
10 02 09 05 * /usr/people/xxxx/rrsch.sh
02 01 08 05 * /isr/people/xxxx/1.sh
03 01 08 05 * /usr/people/xxxx/2.sh


then,
read dd_mm
get day & month as input (dd_mm )

If the input date is dd_mm = "08 05"
&
job_name = /usr/people/xxxx/rrsch.sh

then delete the line fron temp_cron


I don't know how to do it.

Can any one help me.


apr1004
 
hi,
I've solved using awk

Anyway, thanks.

apr1004

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top