Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Running KSH script from CRON

Status
Not open for further replies.

LGTOserv

IS-IT--Management
Aug 20, 2001
25
US
Hi All;

I have an issue trying to get a script written in the KSH. The script does not run from the cron entry:

00 10 * * * /bin/ksh /test.ksh

I think their is something to do with the environment... but most posts say something different. Can anyone help?

I need to use KSH seeing that for some reason the SH shell doesn't handly my variable properly.. for instance, i add bytes up to get MB's and TB's... the bytes value overflows and skews my values... KSH handles them no problem

thanks for the assistance.
 
Sorry.. found the answer on another thread. :|

solution:

in crontab use * * * * * su - root -c /path/to/script

works like a champ
 
You have a problem with your original cron entry. It should read:
Code:
[red]0[/red] 10 * * * /test.ksh

Use a bang inside the script file to specifiy korn shell.

You also havent't told cron what to do with stderr or stdout which can hose your system. Good practice would format the entry as
Code:
0 10 * * * /test.ksh > /dev/null 2>&1


[morning] needcoffee
 
> Use a bang inside the script file to specify korn shell.

This means the first line of /test.ksh should be

#!/bin/ksh

Now whatever shell you are under, it will invoke korn shell to run this script.


HTH,

p5wizard
 
Just as an aside, needcoffee, I think the minute entry can be either 0 or 00, cron doesn't care.

I want to be good, is that not enough?
 
In needcoffee's defense, 0 does use less space then 00 in the crontab file...

Every bit matters, right?

What's wrong with me?
 
cron does not provide an environment.

For my cronned scripts, I include the following 3 lines at the top on my AIX system:

. /etc/environment
. /etc/profile
. ~/.profile

Then my scripts work happily.
 
Ken,

I've never tried 00 a value in cron since man pages specifiy the valid range for minutes is 0-59 on AIX. Just wanted to make sure his job wasn't failing for an improperly formatted statement.

spamly, in honor of you...

Every byte is sacred.
Every byte is great.
If a byte is wasted,
God gets quite iraaaate!

[morning] needcoffee
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top