-   Programming (
-   -   Issues while executing shell scripts through Cron job (

paragkalra 07-08-2008 09:59 AM

Issues while executing shell scripts through Cron job
First Script:
cat /data/backup/scripting/shell-scripts/cron-script/


sh /data/backup/scripting/shell-scripts/cron-script/ $var
Second Script:
cat /data/backup/scripting/shell-scripts/cron-script/


echo $1
touch $
When I manually run "" it successfully executes also executing "" but when I execute "" using cronjob it doesn't executes.

#cronjob -l
* * * * * /data/backup/scripting/shell-scripts/cron-script/

colucix 07-08-2008 10:11 AM

Is executable? How do you tell the script has not been executed? Take in mind that the command

touch $
creates the file in the HOME directory of the user who launched the crontab, since you did not specify a full path. Also check the user's mail: he would have received a mail from the cron daemon, containing the output of the echo command, since you did not redirected the standard output to a file.

jomen 07-08-2008 10:12 AM

Doesn't it work if you make the two scripts executable and then just use them by their name (without "sh" in front...)?
Why would you do it the way you described?

paragkalra 07-08-2008 10:35 AM

Yes both the files are executable.

I have changed the two files:

cat /data/backup/scripting/shell-scripts/cron-script/

/data/backup/scripting/shell-scripts/cron-script/ $var

cat /data/backup/scripting/shell-scripts/cron-script/

echo $1
touch /data/backup/scripting/shell-scripts/cron-script/$
When I am manually executing "" i.e when I am executing following command:
# /data/backup/scripting/shell-scripts/cron-script/

then "three" is being echoed & "" is also getting created in "/data/backup/scripting/shell-scripts/cron-script/"

colucix 07-08-2008 10:40 AM

Is the cron daemon running? Did you receive any mail from the cron daemon?

chrism01 07-08-2008 08:37 PM

Yep, check your email and or root's, depending on whose crontab this is.
However, just to point out that jobs in cron are not attached to a terminal, so 'echo' is a pointless cmd, unless you re-direct it to a file eg
echo "$var1" >/dir/somefile
Given that the default env/PATH var is minimal in cron, you should always specify the full path eg
/bin/touch /path/file

paragkalra 07-10-2008 02:09 PM

Thanks 2 all for your prompt replies........I got it resolved......It was a permission related issue....

tbarnes24 07-31-2008 01:53 PM

I'm having the same problem with FreeBSD
What was the permissions issue, and how did you resolve it? I've got a pair of scripts that I'm trying to run via the root cron, but they don't execute, even though I updated the cron normally.

paragkalra 08-02-2008 02:18 PM

The path variable that is set under cronjob is different from the one that is set under normal circumstances i.e cronjob path variable is different from the one "#env | grep -i path"

So execute the shell script by specifying full path name of the commands or explicitly export the path variable.

All times are GMT -5. The time now is 04:48 AM.