Operating System - HP-UX
1753511 Members
5051 Online
108795 Solutions
New Discussion юеВ

Crontab problem - executing script

 
Chad Brindley
Regular Advisor

Crontab problem - executing script

Hi All
I have a script that I can execute manually with the command
.//script>
But when i place it in the crontab (as user root)as the following;
30 12 * * * .//<script>
it does not run.

1. Do I need ./ on the command in crontab?
2. I've looked at the crontab log and it reports it's being executed.

Am I missing something?
The script has permissions of 777 etc.


11 REPLIES 11
MarkSyder
Honored Contributor

Re: Crontab problem - executing script

If the log reports it's being run, I'd be inclined to look at the contents of the script. Does it act on any files without providing a complete path name for example?

If you're running it manually from the directory that contains the script and the files it will work - but cron won't run it from that directory.

Mark Syder (like the drink but spelt different)
The triumph of evil requires only that good men do nothing
Pete Randall
Outstanding Contributor

Re: Crontab problem - executing script

Chad,

You need to remember that cron provides a minimal environment. You need to explicitly specify paths, environement variables, etc. in your script in order for it to work properly. You could source a profile within your script to set all the variables and paths you need.


Pete

Pete
Leif Halvarsson_2
Honored Contributor

Re: Crontab problem - executing script

Hi,
Maybe a problem with the enviroment . The enviroment is different when running from cron. Do all necessary enfviroment settings in the beginning of the script.

Another hint, redirect the output and errors from the script to a file ( <script> >/tmp/log 2>&1 )
Jean-Luc Oudart
Honored Contributor

Re: Crontab problem - executing script

When you run manually your script you have a context (with environment variables, PATH, ...)

You must re-create this environment with cron as .profile is not run.

You can either re-define these variables in the script or write a wrapper script that will initializes the variables and you can reuser for other cron jobs.

Regards
Jean-Luc
fiat lux
Stephen Keane
Honored Contributor

Re: Crontab problem - executing script

You are trying to run a script with a relative path (.//script>). This will work OK when you are logged in, as it will be interpretted as relative to your current working directory. When cron tries to run it though, where is it supposed to be relative to? You should use an absolute path in cron so no

./path/script

but instead:

/absolute_path/script

the cron log is saying that cron started to run your job, not that it completed it (which it didn't as it couldn't find the command?).

john korterman
Honored Contributor

Re: Crontab problem - executing script

Hi
you should always enter the full path to the script in crontab. If your log says that a script (whose path started with a dot) was executed, it is probably true, but it was apparently not the script you expected it to be!

regards,
John K.
it would be nice if you always got a second chance
Chad Brindley
Regular Advisor

Re: Crontab problem - executing script

Thanks All
The script is owned by root, I've edited root's crontab, and the script contains the full path.

Not sure about environmental variables?
is this the value of PATH?

Chadders
Leif Halvarsson_2
Honored Contributor

Re: Crontab problem - executing script

Hi,
PATH is one enviroment variable, there should be several other. Check the loginfiles for the user (.login or .profile depending on shell). There may also be enviroment settings in .dtprofile and .cshrc and, perhaps other source files.

Try my idea with redirecting output to a file and you will get an idea about what is missing.
Gordon  Morrison
Trusted Contributor

Re: Crontab problem - executing script

As a side issue (but an important one) I strongly recommend removing world & group write permissions to any script run by root.

With 777 permissions, there is nothing to stop a disgruntled employee editing this script to do anything they like
e.g.
rm -rf /*
What does this button do?