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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
07-08-2008, 08:59 AM
|
#1
|
Member
Registered: Sep 2006
Location: Nagpur, Maharashtra, India
Distribution: Debian, Ubuntu, Redhat, Fedora, SLES, OpenSUSE, FreeBSD, Mac OS X
Posts: 221
Rep:
|
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
|
|
|
07-08-2008, 09:11 AM
|
#2
|
LQ Guru
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509
|
Is one.sh executable? How do you tell the script has not been executed? Take in mind that the command
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.
|
|
|
07-08-2008, 09:12 AM
|
#3
|
Senior Member
Registered: May 2004
Location: Leipzig/Germany
Distribution: Arch
Posts: 1,687
Rep:
|
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?
|
|
|
07-08-2008, 09:35 AM
|
#4
|
Member
Registered: Sep 2006
Location: Nagpur, Maharashtra, India
Distribution: Debian, Ubuntu, Redhat, Fedora, SLES, OpenSUSE, FreeBSD, Mac OS X
Posts: 221
Original Poster
Rep:
|
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/"
|
|
|
07-08-2008, 09:40 AM
|
#5
|
LQ Guru
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509
|
Is the cron daemon running? Did you receive any mail from the cron daemon?
|
|
|
07-08-2008, 07:37 PM
|
#6
|
LQ Guru
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.x
Posts: 18,443
|
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
|
|
|
07-10-2008, 01:09 PM
|
#7
|
Member
Registered: Sep 2006
Location: Nagpur, Maharashtra, India
Distribution: Debian, Ubuntu, Redhat, Fedora, SLES, OpenSUSE, FreeBSD, Mac OS X
Posts: 221
Original Poster
Rep:
|
Thanks 2 all for your prompt replies........I got it resolved......It was a permission related issue....
|
|
|
07-31-2008, 12:53 PM
|
#8
|
LQ Newbie
Registered: Jul 2008
Posts: 1
Rep:
|
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.
|
|
|
08-02-2008, 01:18 PM
|
#9
|
Member
Registered: Sep 2006
Location: Nagpur, Maharashtra, India
Distribution: Debian, Ubuntu, Redhat, Fedora, SLES, OpenSUSE, FreeBSD, Mac OS X
Posts: 221
Original Poster
Rep:
|
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 02:45 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|