LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 11-18-2005, 06:55 PM   #1
Slith(++1)
Member
 
Registered: Sep 2005
Posts: 36

Rep: Reputation: 15
Setting a cron task in a script


How can I tell a bash script to set a cron task. Ie, I would like to write to the crontab from my script.

Not just copying a script in to the cron folder but rather writting to the crontab as you would by saying 'crontab -e'

Hope this isnt to confusing thanks.
 
Old 11-18-2005, 08:12 PM   #2
jailbait
Guru
 
Registered: Feb 2003
Location: Blue Ridge Mountain
Distribution: Debian Wheezy, Debian Jessie
Posts: 7,575

Rep: Reputation: 184Reputation: 184
"How can I tell a bash script to set a cron task. Ie, I would like to write to the crontab from my script.

Not just copying a script in to the cron folder but rather writting to the crontab as you would by saying 'crontab -e'"

You could use sed to edit /etc/crontab. See:
man sed
man cron

Note that man cron says that /etc/crontab is writable only by root.

---------------------------
Steve Stites
 
Old 11-19-2005, 04:38 PM   #3
eddiebaby1023
Member
 
Registered: May 2005
Posts: 378

Rep: Reputation: 33
Your best bet would be to save the output of crontab -l into a variable, then write the (double-quoted) variable and your new command to a temporary file which can then be submitted as "crontab file", or cut out the temporary file and echo the data into crontab with a filename of "-".

Last edited by eddiebaby1023; 11-19-2005 at 04:40 PM.
 
Old 11-21-2005, 05:17 AM   #4
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: FreeBSD, Debian, Mint, Puppy
Posts: 3,298

Rep: Reputation: 175Reputation: 175
you ain't supposed to directly write to crontab.

why not just have a named shell script called from a static
cron job which you can write to and change as required?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
shell script using /etc/cron.hourly to execute cron.php file? rioguia Programming 3 06-11-2008 09:09 AM
How to schedule *interactive* task with at or cron fast_rizwaan Linux - Newbie 4 09-09-2005 07:26 PM
Cron Job Syntax for a task in seconds AJones Linux - Software 2 07-22-2005 01:56 PM
PPPD Script problem when cron-scheduling the script andresurzagasti Linux - Networking 0 11-24-2004 03:54 PM
[cron][mdk9.1]cron deamon seems to ignore some task... yannrichet Linux - Newbie 5 06-26-2003 10:57 AM


All times are GMT -5. The time now is 10:32 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration