Computing.Net > Forums > Unix > Running a shell script from cron

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Running a shell script from cron

Reply to Message Icon

Name: Benn Dover
Date: October 25, 2002 at 02:53:39 Pacific
OS: unix
CPU/Ram: 1000000 meg
Comment:

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



Sponsored Link
Ads by Google

Response Number 1
Name: David Perry
Date: October 25, 2002 at 03:13:56 Pacific
Reply:

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.


0

Response Number 2
Name: Don Arnett
Date: October 25, 2002 at 11:38:54 Pacific
Reply:

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.


0

Response Number 3
Name: Sean Miller
Date: October 25, 2002 at 23:06:37 Pacific
Reply:

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


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


Postfix and Relay Question on shell scripti...



Post Locked

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


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: Running a shell script from cron

Want to run a shell script through cron job www.computing.net/answers/unix/want-to-run-a-shell-script-through-cron-job/8446.html

Run a Unix Script from VB or ASP www.computing.net/answers/unix/run-a-unix-script-from-vb-or-asp-/4384.html

Running a shell script as root www.computing.net/answers/unix/running-a-shell-script-as-root/8137.html