1834485 Members
3482 Online
110067 Solutions
New Discussion

Scripting Crontab

 
SOLVED
Go to solution
David Land
Frequent Advisor

Scripting Crontab

I am in the process of creating a simple script to FTP over the cron file from one server to another. However, I am having problems figuring out how to automate crontab through this script.

Do you have any ideas on how to make this work?
9 REPLIES 9
Michael Schulte zur Sur
Honored Contributor

Re: Scripting Crontab

Hi,

somewhat like
ftp -in << EOF
user u1 p1
cd
dir
get test1
quit
EOF

look for other threads with the search machine!

Michael
Kent Ostby
Honored Contributor

Re: Scripting Crontab

The only way I can thing to do this is a brute force method which has some risk if you happen to have cron jobs set to start up on the target system at that time, and that would be to do a remsh to the target system and have it do:

/sbin/init.d/cron stop
/sbin/init.d/cron start.

"Well, actually, she is a rocket scientist" -- Steve Martin in "Roxanne"
Dave Hutton
Honored Contributor

Re: Scripting Crontab

One quick point, anything that you envoke from crontab you want to make sure you fully path all your commands. For example /usr/bin/ftp or make sure you set up your environment so it knows where to look for your binaries (PATH=$PATH:/usr/bin).

Dave Hutton
Honored Contributor

Re: Scripting Crontab

I think I was on the same page as Michael was. Which after rereading it, is the wrong page.

David Land
Frequent Advisor

Re: Scripting Crontab

I take it there is no way to stop and start Cron through FTP? I would like to keep away from using rcp or rlogin to perform this.
Mel Burslan
Honored Contributor

Re: Scripting Crontab

stopping any process using FTP is not possible under normal circumstances, but a creative way of accomplishing this is to run a cron job like every minute and checking for existence of a file, for example /var/adm/killcron. And upon existence of this file, your script can stop/kill the cron process and delete the file. The file can be uploaded using FTP. I hope this helps.
________________________________
UNIX because I majored in cryptology...
David Land
Frequent Advisor

Re: Scripting Crontab

Okay I believe that would work, Mel. My only question now is how do you check for the existance of that file?
A. Clay Stephenson
Acclaimed Contributor

Re: Scripting Crontab

You do not want to simply copy the crontab over because the cron daemon itself won't have a clue that you have changed the file. The cron daemon needs a kill -1 to know to reread its configuration files. The smart way to do this is through the use of the crontab command.

I would do send your new cron file into a remsh that invokes crontab on the remote host. Crobtab reads the stdin so this is a good fit. As a bonus, crontab automatically send a kill -1 to the cron daemon.
If it ain't broke, I can fix that.
Mel Burslan
Honored Contributor
Solution

Re: Scripting Crontab

David,

an example would be :

#!/usr/bin/ksh
if [ -a /var/adm/killcron ]
then
rm /var/adm/killcron
/sbin/init.d/cron stop
sleep 1
/sbin/init.d/cron start # if you want to restart it
fi

put this snippet of code into a script and call this script from cron at pre-designated intervals that you wish.

everytime you upload a file named /var/adm/killcron (change at your wish but make sure it is in a root-only access directory, unless you may have unexplained cron disappearances) using any method, ftp, scp, rcp and what-have-you, your cron will recycle on the next run of this script.

Hope this helps.
________________________________
UNIX because I majored in cryptology...