1830061 Members
2738 Online
109998 Solutions
New Discussion

adding a script to cron

 
SOLVED
Go to solution
Jason Reed
Occasional Advisor

adding a script to cron

I wrote a script that will compress files that haven't been modified in a certain amount of days. I want to add it to cron so that the system will run it on a schedule. How do I do this? By using crontab, perhaps? And if so does it matter if it is down as root or no?
6 REPLIES 6
Dan Hetzel
Honored Contributor

Re: adding a script to cron

Hi Jason,

You should use 'crontab -e' to modify the crontab.
You should run it as a user who has read/write access to the files and the directory where your compressed files will be (same as uncompressed dir, if you run gzip without extra flags)
If you run it as root, make sure nobody has write access to your script, as this could lead to a major security issue.

Best regards,

Dan


Everybody knows at least one thing worth sharing -- mailto:dan.hetzel@wildcroft.com
Alex Glennie
Honored Contributor

Re: adding a script to cron

checkout man crontab & the egs .... i suspect if you can run the command line as a non-root user from the command line it won't matter.
Steven Sim Kok Leong
Honored Contributor

Re: adding a script to cron

Hi

Use "crontab -e" to modify your cron jobs and "crontab -l" to list your cron jobs under your userid.

It ownership of the crontab matters because only the cron jobs under the owner's crontab have the rights to modify files under his ownership.

man crontab (1) for more information on how to set the schedule. Briefly the syntax for an entry in the crontab is:
minute hour day-of-month month weekday command eg.

0 0 * * * /tools/compress.sh

to run the compress.sh script everyday at midnight.

Hope this helps. Regards.

Steven Sim Kok Leong
Brainbench MVP for Unix Admin
http://www.brainbench.com
Thomas Kollig
Trusted Contributor
Solution

Re: adding a script to cron

Hi!

An easy way is to use SAM -> Process Management -> Schedule cron jobs.
You also can use crontab for it. With "crontab -e" you can edit your crontab file. A line of such an crontab file has the follwing format: "minute hour monthday month weekday command". See man-pages.

If you want to use cron as user you have to make sure that you are allowed to do it (try "crontab"). The permission are determined by the files /var/adm/cron/cron.allow .../cron.deny.

Hope this helps.

Thomas
Jason Reed
Occasional Advisor

Re: adding a script to cron

Thanks guys. All your responses were very helpful.

Re: adding a script to cron

Jason,

I wrote a similar script for taring (compresing) my passwords directory, this is helpful because I have a recovery site, and the passwords somethimes are not the same In my production server.
To edit the crontab, just type this:

crontab -e

e: means edit, l: list,

Then add this line at the end of the file(go to the vi reference manual, cause it uses vi to edit the file).
typing i (insert).

00 23 * * * /usr/bin/ksh /scripts/passwords.ksh

This means that every day at 23:00 P.M executes using the shell ksh my script passwords.ksh located in /scripts/ if you have trouble understanding the date, just do a man crontab and you will see some help.

Hope this helps