Shell script not getting called through cron job but executes fine manually.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell script not getting called through cron job but executes fine manually.
# 15  
Old 07-05-2012
From post #12:
Code:
Output for ls -lad /home/myfolder/abc.sh :
 
-rw-rw-rw- 1 myname myname 296 Jul 4 19:06 /home/myname/abc.sh

The script is not executable. There should have been an error in unix mail for the owner of the cron.

The way you are running scripts from the command line by starting a new shell with a script name as a parameter sh scriptname rather than ./scriptname or /home/myfolder/abc.sh is masking the problem. You were not typing the same command as you gave to cron.

The current permissions are 555 (i.e. not executable by anybody, and that includes cron). You need to make your scripts executable if you want to run them from cron:
Code:
chmod 755 /home/myfolder/abc.sh


Last edited by methyl; 07-05-2012 at 12:35 PM..
This User Gave Thanks to methyl For This Post:
# 16  
Old 07-05-2012
Quote:
Originally Posted by methyl
From post #12:
Code:
Output for ls -lad /home/myfolder/abc.sh :
 
-rw-rw-rw- 1 myname myname 296 Jul 4 19:06 /home/myname/abc.sh

The script is not executable. There should have been an error in unix mail for the owner of the cron.

The way you are running scripts from the command line by starting a new shell with a script name as a parameter sh scriptname rather than ./scriptname or /home/myfolder/abc.sh is masking the problem. You were not typing the same command as you gave to cron.

The current permissions are 555 (i.e. not executable by anybody, and that includes cron). You need to make your scripts executable if you want to run them from cron:
Code:
chmod 755 /home/myfolder/abc.sh


Thanks Methyl, The script is now working through cron.
the issue was with the permissions on the script. After providing permissions- chmod 755 the issue got resolved.
This User Gave Thanks to Dejavu20 For This Post:
# 17  
Old 07-05-2012
Quote:
Originally Posted by Dejavu20
the issue was with the permissions on the script. After providing permissions- chmod 755 the issue got resolved.
How were you ever able to execute your script if it was set 555? Smilie You can't have been running it with ./scriptname in the shell either.
# 18  
Old 07-05-2012
@Corona688
Didn't pick up the way the O/P runs scripts until post #14 , though the permissions were in post #12 (my bad). I've just highlighted the command in post #14 because it was in the middle of a sentence.
I concentrated on the fact the the original script didn't execute anything except the echo. It was of course the redirect on the crontab line which would have created the empty log whether or not the script actually ran.
Obviously the O/P doesn't see unix mail because if the original cron has been running for a couple of days there will be quite a few emails (288 per day)!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell Script has different ouput via cron vs when run Manually

Hello Lads, I deployed a script on my mac to start and stop EC2 instances on AWS console. The script when started manually on the terminal does the expected stop and start. Problem is when i try to schedule it on a cron, it fails to recognize the AWS Keys which i set up as ENV variable by... (2 Replies)
Discussion started by: Irishboy24
2 Replies

2. Shell Programming and Scripting

Calling bash script works when called manually but not via Cron?

Hi, I've got a Bash backup script I'm trying to run on a directory via a cron job nightly. If I ssh in and run the script manually it works flawlessly. If I set up the cron to run evertything is totally messed up I don't even know where to begin. Basically the path structure is ... (6 Replies)
Discussion started by: wyclef
6 Replies

3. Shell Programming and Scripting

Output differs when run manually and when cron job executes it

I get a different output when i manually run the .sh script and when it is run by a cron job. Please help me .. TMP1="/lhome/bbuser/script/wslog/sar.t1" TMP2="/lhome/bbuser/script/wslog/sar.t2" TMP3="/lhome/bbuser/script/wslog/sar.t3" OUTPUT="/lhome/bbuser/script/wslog/sar.out"... (8 Replies)
Discussion started by: nithinankam
8 Replies

4. Shell Programming and Scripting

Part of the Shell script is not running via crontab, runs fine manually

Hello Team, As a part of my job we have made a script to automate a service to restart frequently. Script having two functions when executing it's should find the existing service and kill it, then start the same service . Verified the script it's working fine when executing... (18 Replies)
Discussion started by: gowthamakanthan
18 Replies

5. Shell Programming and Scripting

Script not working in cron but working fine manually

Help. My script is working fine when executed manually but the cron seems not to catch up the command when registered. The script is as follow: #!/bin/sh for file in file_1.txt file_2.txt file_3.txt do awk '{ print "0" }' $file > tmp.tmp mv tmp.tmp $file done And the cron... (2 Replies)
Discussion started by: jasperux
2 Replies

6. Shell Programming and Scripting

Script runs fine manually but not in crontab

Hello Guys, I have scratched my head alot on this but couldn't find clue what's wrong. Can you please help me with this? My problem is as following. 1) When I manually execute following script it runs successfully with below output. bash-3.00# more smssend #!/bin/bash echo -e "<Request... (16 Replies)
Discussion started by: umarsatti
16 Replies

7. Shell Programming and Scripting

Getting issue while running it from cron while manually working fine

Hello, I am working one one script where I am using the below code which is using to connect with MKS client when I run my script manually it works effiecently i.e. it connects with MKS client but when I run it from CRON it doesn't connect. 1)Can some one tell when it is running from cron... (1 Reply)
Discussion started by: anuragpgtgerman
1 Replies

8. AIX

Script not getting executed via cron but executes when executed manually.

Hi Script not getting executed via cron but executes successfully when executed manually. Please assist cbspsap01(appuser) /app/scripts > cat restart.sh #!/bin/ksh cd /app/bin date >>logfile.out echo "Restart has been started....." >>logfile.out date >>logfile.out initfnsw -y restart... (3 Replies)
Discussion started by: samsungsamsung
3 Replies

9. Shell Programming and Scripting

Cron job fails, but works fine from command line

I have a very basic script that essentially sends a log file, via FTP, to a backup server. My cron entry to run this every night is: 55 23 * * * /usr/bin/archive_logs The script runs perfectly when executed manually, and actually worked via cron for about three weeks. However, it mysteriously... (3 Replies)
Discussion started by: cdunavent
3 Replies

10. Shell Programming and Scripting

How to determine if a script (perl) was called from a CRON job or commandline

Hi, Is there a way to determine if a Script is called from a CRON job or from a commandline Gerry. (2 Replies)
Discussion started by: jerryMcguire
2 Replies
Login or Register to Ask a Question