Differences between revisions 11 and 15 (spanning 4 versions)
Revision 11 as of 2013-05-29 07:35:58
Size: 2541
Editor: hgiger
Comment:
Revision 15 as of 2013-07-17 12:26:53
Size: 2641
Editor: bonaccos
Comment:
Deletions are marked like this. Additions are marked like this.
Line 13: Line 13:
There is one exception to this rule: '''cronbox.ee.ethz.ch''' here. Every user can create cronjobs on this machine just as he likes. The reason for imposing this restriction is to simplify the debugging of cronjob problems, as it will be clear that they occur on this particular machine. There is one exception to this rule: '''cronbox.ee.ethz.ch''' here. Every user can create cronjobs on this machine just as he likes. The reason for imposing this restriction is to simplify the debugging of cronjob problems, as it will be clear that they occur on this particular machine. Furthermore it helps us as admins to clean up cronjobs when a user is archived.
Line 43: Line 43:
The commands above, when entered into you shell will create '''cronscript.sh''' now run '''crontab -e''' to add it to your crontab. If you want the script to run every hour at 15 minutes past the hour it would look like this: The commands above, when entered into you shell will create {{{cronscript.sh}}} now run {{{crontab -e}}} to add it to your crontab. If you want the script to run every hour at 15 minutes past the hour it would look like this:
Line 48: Line 48:
With '''crontab -l''' you can check if the cronjob has been properly accepted With '''crontab -l''' you can check if the cronjob has been properly accepted.
Line 51: Line 51:
Learn more about cron with '''man cron''' and '''man crontab'''.

Learn more about cron with '''man cron''', '''man 1 crontab''' and '''man 5 crontab'''.
Line 55: Line 53:
[[CategoryLXCL]] [[CategoryLXBS]]

Cronjob

Cron-Box

If you have ever tried to create a cronjob on one of the tardis machines, you may have noticed that you are lacking the necessary permissions.

There is one exception to this rule: cronbox.ee.ethz.ch here. Every user can create cronjobs on this machine just as he likes. The reason for imposing this restriction is to simplify the debugging of cronjob problems, as it will be clear that they occur on this particular machine. Furthermore it helps us as admins to clean up cronjobs when a user is archived.

Cron Hints

A job that is started via cron is running under special conditions, so you must take the following into consideration:

  • The environment in your shell is not the same as the environment cron sets when executing its scripts. Especially the PATH variable may not be set the way you expect it to be set. Set an explicit path to make things work
  • Whenever your cronjob outputs anything, cron will send you this material by mail. The idea is that 'happy programs don't talk'. If they do talk this means there is trouble and the owner should know about it.
  • Since there are quite a number of things to observe when setting up a cronjob it is best to refrain from trying to press all this into a single line of code in the crontab. Rather write a little script that observes the rules above and add this script to the crontab.

Sample Cron-Script

mkdir -p ~/bin
cat <<SCRIPT >~/bin/cronscript.sh
#!/bin/sh
# shell scripts should be written in /bin/sh
# see also http://www.faqs.org/faqs/unix-faq/shell/csh-whynot
#
# uncomment the following line to get a running output of what
# the script does
#set -x
#
# set an absolut path to be sure that the script works everywhere
PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/sepp/bin
export PATH
# show me who is working on tardis-a15. if no one is working there be quiet.
rwho | grep tardis-a15
# end of script
SCRIPT
chmod 755 ~/bin/cronscript.sh

The commands above, when entered into you shell will create cronscript.sh now run crontab -e to add it to your crontab. If you want the script to run every hour at 15 minutes past the hour it would look like this:

15 * * * * $HOME/bin/cronscript.sh

With crontab -l you can check if the cronjob has been properly accepted.

And ...

Learn more about cron with man cron, man 1 crontab and man 5 crontab.


CategoryLXBS

Services/Cronjob (last edited 2020-09-10 09:10:42 by bonaccos)