Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Need help to schedule a job

 
Sam Saha
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wrote a script which basically capture the necessary lines from the stack of a source file and dump them into a destination file. Now I am executing this script manually (using chmod command in the command line) to create the destination file. I am wondering if I can add some script in my existing script to execute this script automatically once a day (I mean to say I want to run a scheduler to execute this script automatically in stead of manually which I am doing now). I would appreciate if someone can help me writing this script as I am really new and do not have much knowledge in Unix script. Thank you.

Here is my script:
 
Peter Johnson
author
Bartender
Posts: 5852
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try this: open a terminal and type:



Or try this: cron tutorial
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18008
47
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You don't need to "run a scheduler", since there's almost invariably a scheduler already running: cron, which as Peter pointed out, you can get more details on by using the "man" or "info" commands, looking at various websites, or consulting tldp.org (The Linux Documentation Project).

Cron is good for regularly repeating things. For a one-off delayed execution of a command/script, there's also the "at" command.

Two things above and beyond the usual docs that you might want to take note of, though:

1. It's best to include the absolute path of the command that you want to execute in your crontab entry, not just a relative path or for that matter, assuming that your normal command-shell path will apply.

2. Cron runs in 2 different ways. Individual users can each schedule their own cron jobs, but there are also a set of directories for system-level cron tasks: /etc/cron.daily, /etc/cron.weekly, and so forth. These directories contain scripts (or links to scripts). When their respective intervals elapse, cron will scan the directory and for each item whose "executable" bit is set, execute that file. This process is controlled by the master crontab, which is /etc/crontab.

Also note that there is a small difference in formats between the system crontab and user crontabs. The system crontab includes a field that indicates what userid to run the scheduled command under. This isn't explained very well in the man page, I'm afraid.

Oh. One last thing, for what it's worth. Modern Linux systems understand that not all machines are running 24x7 (laptops, for example). So instead of vanilla cron, they often run a system named "anacron". Anacron will ensure that if the machine was powered off when a cron event should have run that the cron event should be taken care of when the system comes back up.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic