LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 07-08-2008, 09:59 AM   #1
paragkalra
Member
 
Registered: Sep 2006
Location: Nagpur, Maharashtra, India
Distribution: Debian, Ubuntu, Redhat, Fedora, SLES, OpenSUSE, FreeBSD, Mac OS X
Posts: 221

Rep: Reputation: 31
Issues while executing shell scripts through Cron job


First Script: one.sh
cat /data/backup/scripting/shell-scripts/cron-script/one.sh

Quote:
#!/bin/sh
var=three
sh /data/backup/scripting/shell-scripts/cron-script/two.sh $var
Second Script: two.sh
cat /data/backup/scripting/shell-scripts/cron-script/two.sh

Quote:
#!/bin/sh
echo $1
touch $1.sh
When I manually run "one.sh" it successfully executes also executing "two.sh" but when I execute "one.sh" using cronjob it doesn't executes.

#cronjob -l
* * * * * /data/backup/scripting/shell-scripts/cron-script/one.sh
 
Old 07-08-2008, 10:11 AM   #2
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
Is one.sh executable? How do you tell the script has not been executed? Take in mind that the command
Code:
touch $1.sh
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.
 
Old 07-08-2008, 10:12 AM   #3
jomen
Senior Member
 
Registered: May 2004
Location: Leipzig/Germany
Distribution: Arch
Posts: 1,687

Rep: Reputation: 54
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?
 
Old 07-08-2008, 10:35 AM   #4
paragkalra
Member
 
Registered: Sep 2006
Location: Nagpur, Maharashtra, India
Distribution: Debian, Ubuntu, Redhat, Fedora, SLES, OpenSUSE, FreeBSD, Mac OS X
Posts: 221

Original Poster
Rep: Reputation: 31
Yes both the files are executable.

I have changed the two files:

cat /data/backup/scripting/shell-scripts/cron-script/one.sh
Quote:
#!/bin/sh
var=three
/data/backup/scripting/shell-scripts/cron-script/two.sh $var

cat /data/backup/scripting/shell-scripts/cron-script/two.sh
Quote:
#!/bin/sh
echo $1
touch /data/backup/scripting/shell-scripts/cron-script/$1.sh
When I am manually executing "one.sh" i.e when I am executing following command:
# /data/backup/scripting/shell-scripts/cron-script/one.sh

then "three" is being echoed & "three.sh" is also getting created in "/data/backup/scripting/shell-scripts/cron-script/"
 
Old 07-08-2008, 10:40 AM   #5
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
Is the cron daemon running? Did you receive any mail from the cron daemon?
 
Old 07-08-2008, 08:37 PM   #6
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.6, Centos 5.10
Posts: 16,324

Rep: Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041
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
 
Old 07-10-2008, 02:09 PM   #7
paragkalra
Member
 
Registered: Sep 2006
Location: Nagpur, Maharashtra, India
Distribution: Debian, Ubuntu, Redhat, Fedora, SLES, OpenSUSE, FreeBSD, Mac OS X
Posts: 221

Original Poster
Rep: Reputation: 31
Thanks 2 all for your prompt replies........I got it resolved......It was a permission related issue....
 
Old 07-31-2008, 01:53 PM   #8
tbarnes24
LQ Newbie
 
Registered: Jul 2008
Posts: 1

Rep: Reputation: 0
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.
 
Old 08-02-2008, 02:18 PM   #9
paragkalra
Member
 
Registered: Sep 2006
Location: Nagpur, Maharashtra, India
Distribution: Debian, Ubuntu, Redhat, Fedora, SLES, OpenSUSE, FreeBSD, Mac OS X
Posts: 221

Original Poster
Rep: Reputation: 31
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.
 
  


Reply

Tags
cronjob, parag, paragkalra


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Cron job and postmap issues TheDude05 Linux - Server 3 08-09-2007 08:13 PM
stop konqueror executing shell scripts ahh Linux - Software 2 03-27-2005 07:00 AM
Prevent konqueror from executing shell scripts Dave Farrance Mandriva 1 05-30-2004 09:37 PM
Executing Shell Scripts? l0f33t Linux - General 7 08-17-2003 04:36 PM
Executing shell scripts justinv Linux - General 6 01-26-2003 08:57 AM


All times are GMT -5. The time now is 11:51 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration