Can we edit crontab using a shell script

Tags
shell scripts

Login to Reply

 
Thread Tools Search this Thread
# 1  
Old 03-31-2005
Power Can we edit crontab using a shell script

Hi,


Can some one tell me if we can configure the jobs in crontab using a shell script.

I know it can be done easily by using "crontab -e", but i just want to know whether we can add a job into the crontab using a shell script.

If it can be done, plz suggest the procedure to do it.
If it cannot be done then why(reason)?

thanks
# 2  
Old 03-31-2005
IF you are using your own cron script file as,

crontab -f <filename>

so that installation and deinstallation will be based on that file. Else psuedo-random file will be used for this operation.

HTH.
# 3  
Old 03-31-2005
have your script ...

a. crontab -l > $tmpfile
b. edit $tmpfile
c. crontab $tmpfile
d. rm $tmpfile
# 4  
Old 03-31-2005
Thanks a lot...... Smilie That made my life soooo easy......
# 5  
Old 06-16-2009
Does one then have to restart cron daemon

Hi there,

First post on these forums can't believe it actually as I always end up browsing them... anyway...
Sorry to bounce a 4yo thread but it still has relevance.

I am actually doing exactly what is described in this thread but I have one further question and that is:

Do I then have to restart cron after making the change to have it take effect?

My guess is that since you are still using the actual crontab command, not just directly editing the cron file, then no, as I imagine it still runs the install / restart itself, as if you have just run a crontab -e?
Is this correct?

Any help would be much appreciated,

Thanks,
# 6  
Old 06-16-2009
"crontab -e username" edits the live crontab and notifies cron of the change. There is no need to restart cron.
The technique suggested by "Just Ice" can be improved by copying the crontab twice to different names. You then have the original crontab saved if something goes wrong and a baseline file to "diff" against.
# 7  
Old 06-16-2009
Okay, kool...

Thanks for your help Smilie
Login to Reply

|
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Similar Threads More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Open and edit a file using a shell script ektubbe Shell Programming and Scripting 1 07-04-2017 06:49 AM
Can't edit my Crontab mohtashims Shell Programming and Scripting 3 08-14-2015 11:33 PM
Edit the file in shell script Abdul Navaz Homework & Coursework Questions 3 04-17-2014 10:40 PM
shell script to edit a file jacky29 Shell Programming and Scripting 2 04-01-2011 06:39 AM
Shell script to edit a file Titas Shell Programming and Scripting 3 02-14-2011 03:29 AM
edit columns in unix shell script kingpeejay Shell Programming and Scripting 10 06-22-2009 09:01 PM
Need help in a shell script to edit a tablespace creation script. rparavastu Shell Programming and Scripting 2 12-30-2008 11:07 AM
Edit a config file using shell script rajeshomallur Shell Programming and Scripting 7 05-02-2008 03:57 PM
shell script to edit the content of a file tiger99 Shell Programming and Scripting 3 01-31-2008 04:43 AM
How to edit the crontab file rajus19 Shell Programming and Scripting 2 05-25-2007 09:34 AM
Edit Crontab juliet UNIX for Dummies Questions & Answers 11 09-28-2006 05:32 PM
edit crontab without -e d_swapneel14 Shell Programming and Scripting 8 04-11-2006 04:50 AM
Can't edit crontab FredSmith UNIX for Dummies Questions & Answers 1 10-24-2005 06:12 PM
How to edit txt file by shell script? dupeng AIX 3 09-29-2005 04:43 AM
Crontab - Recommended way to edit? frustrated1 UNIX for Advanced & Expert Users 3 08-26-2003 04:45 AM
All times are GMT -4. The time now is 11:12 AM.

Unix & Linux Forums Content Copyright 1993-2018. All Rights Reserved.