Shell Programming and Scripting

BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

Can we edit crontab using a shell script

👤 Login to reply

    #1  
Old 03-31-2005
rudrarajumk rudrarajumk is offline
Registered User
 
Join Date: Mar 2005
Last Activity: 8 May 2005, 3:26 AM EDT
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
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
Sponsored Links
    #2  
Old 03-31-2005
muthukumar muthukumar is offline
Registered User
 
Join Date: Feb 2005
Last Activity: 8 November 2005, 6:07 AM EST
Location: Coimbatore, Tamilnadu, India
Posts: 119
Thanks: 0
Thanked 1 Time in 1 Post
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.
Sponsored Links
    #3  
Old 03-31-2005
Just Ice's Unix or Linux Image
Just Ice Just Ice is offline Forum Advisor  
Lights on, brain off.
 
Join Date: Mar 2005
Last Activity: 18 October 2016, 12:06 PM EDT
Location: Philadelphia metro
Posts: 961
Thanks: 3
Thanked 67 Times in 61 Posts
have your script ...

a. crontab -l > $tmpfile
b. edit $tmpfile
c. crontab $tmpfile
d. rm $tmpfile
    #4  
Old 03-31-2005
rudrarajumk rudrarajumk is offline
Registered User
 
Join Date: Mar 2005
Last Activity: 8 May 2005, 3:26 AM EDT
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks a lot...... That made my life soooo easy......
Sponsored Links
    #5  
Old 06-15-2009
STOIE's Unix or Linux Image
STOIE STOIE is offline
Registered User
 
Join Date: Jun 2009
Last Activity: 3 July 2018, 1:52 PM EDT
Location: Canberra, Australia
Posts: 45
Thanks: 1
Thanked 0 Times in 0 Posts
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,
Sponsored Links
    #6  
Old 06-16-2009
methyl methyl is offline
Registered User
 
Join Date: Mar 2008
Last Activity: 8 June 2016, 9:58 PM EDT
Posts: 6,402
Thanks: 288
Thanked 676 Times in 645 Posts
"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.
Sponsored Links
    #7  
Old 06-16-2009
STOIE's Unix or Linux Image
STOIE STOIE is offline
Registered User
 
Join Date: Jun 2009
Last Activity: 3 July 2018, 1:52 PM EDT
Location: Canberra, Australia
Posts: 45
Thanks: 1
Thanked 0 Times in 0 Posts
Okay, kool...

Thanks for your help
Sponsored Links
👤 Login to reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
shell script to edit a file jacky29 Shell Programming and Scripting 2 04-01-2011 05:39 AM
Shell script to edit a file Titas Shell Programming and Scripting 3 02-14-2011 02:29 AM
edit columns in unix shell script kingpeejay Shell Programming and Scripting 10 06-22-2009 08:01 PM
Need help in a shell script to edit a tablespace creation script. rparavastu Shell Programming and Scripting 2 12-30-2008 10:07 AM
How to edit txt file by shell script? dupeng AIX 3 09-29-2005 03:43 AM



All times are GMT -4. The time now is 11:13 PM.

Unix & Linux Forums Content Copyright©1993-2018. All Rights Reserved.
×
UNIX.COM Login
Username:
Password:  
Show Password





Not a Forum Member?
Forgot Password?