crontab entry modification using shell script

hi Friends,

iam trying to write a script which will grep the particular entry in crontab of root and enable/disable it .iam a novice in scripting. your suggestions are most welcome..please help

Cheers!!

You can doing using perl or sed.

To edit cron jobs of any user you will need to edit the file with corresponding username under /var/spool/cron (assuming Red Hat linux.. you can find this path for different *nix systems).

Hope that helps you.

My suggestion is do not do that! First of all, simply changing the crontab file is NOT correct. You must use the crontab command or cron will not notice the change.

But what you should do is make the entry in root's crontab a shell script. And the shell script should, at the top, do something like:

if [ -f /var/root-crontab-control/inhibit-file1 ] ; then
        exit 0
fi

This is much cleaner than having scripts that fiddle with root crontab. Sooner or later the scripts fail and root is left with no crontab. With the inhibit-file concept, you just touch a file to inhibit the corresponding cronjob and then later you remove the inhibit file when you the script to run all the way.

thats seems to be sth smart work Perderabo,but that would be much better if you can explain the inhibit-file concept with an example.

Thanks in Advance..

Per, I have a doubt here.

Modifying the cron entries via scripts and not through crontab command and touching the cron file.

Won't that enable crond to understand that cron file for a user has been changed ?

Won't that work ... ? Assuming that the user script is not going to mess up with the cron file won't the above logic work ?