Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hi,
i have written a shell script that needs to be run from cron. Al i know about "cron" is that we can get it to run jobs periodically. The requirement of my assignment is that my script should be able to run from cron "unattended". I do not have access to cron and can't figure out how to modify my script so that it'll run fine from cron.Can anyone tell me how a script differs in behaviour when run interactively and when run from "cron" ? What do i need to add and/or change in my script in order to achieve the above

Chevy Chase, from Fletch - right?
Any job run from cron will mail to the user that runs it what would normally have gone to stdout. So you might want to make sure you minimize stdout output perhaps by directing the output to a file if your program is very verbose.

Many times in UNIX systems (at least were I've worked) the root login doesn't have the same path setting as other logins, so a script that runs fine under a normal login, fails as root because it can't find some program.
Typically, when I write for cron, I put the full path on every executable & script.

Yes, if running from a root cron the advice is sound... ensure that every path is explicitly stated. Also, ensure that you have specified the shell in which you want the job to run at the top of your file. root is normally Bourne shell... you may well want Korn or Csh.
Ensure that your output is redirected either to /dev/null (if you don't want output) or a logfile (again be sure to specify the logfile path), otherwise the output will probably be e-mailed to 'root' which (as the previous respondee stated) might upset your system administrators.
Cron is not rocket science... all it does is wait until a specific time and set a job running in the background. There's nothing special about a "cron script" -- you've just got to remember who is going to run it and ensure that you've got all bases covered!
Enjoy!
Sean

![]() |
Postfix and Relay
|
Question on shell scripti...
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |