Cronjob not working as intended


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Cronjob not working as intended
# 8  
Old 04-21-2014
That's correct, because your script not able to find the below cmd
ec2-describe-instances --> What is this cmd for?
I think you have to call it with full path... or you may have to define it in your script and call.
# 9  
Old 04-22-2014
When I've come up with a different behaviour in script vs. cronjob execution, it has turned out to be probably because of one these (presuming you are in the same machine):

- user executing the cron task is different from the one used for testing.
- user is the same for cron and testing BUT it's using different environments.

Logging with "su" instead of "su -" it does not load the user's environment. So when running cron, the system executes the script loading the user's environment, of course. Then if testing when same user but different environment, there are many chances that the script is not going to behave in the same way or in the way expected.

Alternatevely, you may have logged in using a non-interactive shell like ssh to test the script, and then the script run using the local environment.

So how do you log in in the system when testing the script?

K.
# 10  
Old 04-30-2014
Multiple reasons

1> Check full path of all executable in the script.

2> Ensure all environment variables are set accordingly

3> Check the script when run from the same user as the cron is executing.

Technically there is no difference between manually running a script and scheduling from cron

The script is working fine now using cron
# 11  
Old 06-12-2014
Seem like you are not using the full command path. You must reference the "ec2-describe-instances" command to where you installed your ec2 cli like

/location/to/folder/ec2-describe-instances

Are you creating the crontab under the same user account as you have test the shell script manually?
  1. Always use the full path to the command in crontab
  2. You also always want to include the same environment variables as you use when you execute your shell script manually.
SetCron
setcron.com
# 12  
Old 06-12-2014
Quote:
Originally Posted by Palak Sharma
I have tried your command but nothing is really working,

Yeah I checked out the output.txt, It shows

Code:
/EC2InstanceAuditScript.sh: line 20: ec2-describe-instances: command not found

How to resolve this?

---------- Post updated at 12:25 AM ---------- Previous update was at 12:16 AM ----------

Kindly see my edited reply
command not found means an executable file for the command (ec2-describe-instances) was not found in any of the directories listed in PATH.

Common mistake. Job submitted by cron do not inherit any environment. It is the responsibility of the submitted script to guarantee all necessary environment variables are set. That's why it executes fine when you submit it from a command line. When you logged on, your session had a lot of environment variables (including PATH) set, mostly from your .bash_profile (or .profile). When you submitted the script from the command line, that process inherited your environment.
This User Gave Thanks to edstevens For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

PHP cronjob not working but manual working

Hi, Can anyone help me on my PHP cron not working, but when i do the manual it work. # manual run working /usr/local/bin/php /root/dev/test.php # crontab not working 55 8 * * * /usr/local/bin/php /root/dev/test.php Thank in advances Regards, FSPalero Please use CODE tags as... (2 Replies)
Discussion started by: fspalero
2 Replies

2. Shell Programming and Scripting

Cronjob is NOT working

Hi; Here is the output from crontab -l: 2,7,12,17,22,27,32,37,42,47,52,57 * * * * /var/tmp/gcsw/jmap_samples/jmap_script.sh > /var/tmp/gcsw/jmap_samples/histo_`date '+%Y%m%d%H%M'`.txtWhen I manually run the line: /var/tmp/gcsw/jmap_samples/jmap_script.sh >... (2 Replies)
Discussion started by: gc_sw
2 Replies

3. UNIX for Dummies Questions & Answers

Cronjob not working

Hi, I am trying to run a script through crontab but it doesn't run. The script sends an email of the logfile created.When I reun through command line it works perfectly but doesn't send any email through cron. There are othe jobs in cron wich runs perfectly. Please let me know if I am doing... (3 Replies)
Discussion started by: Rossdba
3 Replies

4. Shell Programming and Scripting

while loop not working in cronjob

Hi , While loop is not working when running script as cronjob. #!/usr/bin/bash xyz sleep 30 var=0 while do xyz commands done This script is working if I run it manually. (7 Replies)
Discussion started by: ankush_mehra
7 Replies

5. UNIX for Advanced & Expert Users

cronjob not working intermittently

Hi there I have a cronjob running on a sol 10 U6 server which runs every 15 minutes. The cronjob is a perl script. But I have noticed that after every few weeks the job stops running all of a sudden. There are other cronjobs running on the system from the same user and from other users which... (3 Replies)
Discussion started by: sinfuldips
3 Replies

6. Solaris

cronjob not working

Hi All , I have a cron jobs that is not working while put inside cron. But on executing from manually, it works fine, Pl anyone find if there is anything wrong in the script. 30 22 * * 1-5 cd /home/ab90737/introscope/util/bin; ./batchgenerateReport.pl ../config/reps.config >... (1 Reply)
Discussion started by: jegaraman
1 Replies

7. Solaris

cronjob not working

I am trying to schedule a job via cronjob. Not sure what the problem is. below is my script and the error. 45 10 * * * /u01/app/oracle/jpark/sched_exp_mis.sh Error received. Your "cron" job on tama /u01/app/oracle/jpark/sched_exp_mis.sh produced the following output: ... (19 Replies)
Discussion started by: mrx1350
19 Replies

8. Shell Programming and Scripting

script not working as intended for password

Hi I have a script which uses expect and I run it on solaris 10 to set a common password for all users. I run it as `./script password` but when I tried to log into the system then I do not really have to type password, pressing ENTER on keyboard logs the user into system. (ssh) This below... (2 Replies)
Discussion started by: upengan78
2 Replies

9. UNIX for Advanced & Expert Users

cronjob not working

I created a file in /u01/oradata directory as cronjb.ksh which contains following script 30 12 * * * /export/home/oracle/u01/oradata/rman.ksh '/export/home/oracle' is my root directory. I then moved cronjb.ksh file to my '/export/home/oracle' directory. i typed crontab cronjb.ksh. However my... (8 Replies)
Discussion started by: manna
8 Replies

10. UNIX for Dummies Questions & Answers

sftp not working as cronjob

hi, I have a script that will automatically login into a server and get a file. it is working fine if i run it on a command line. however, when i tried to run it as a cron job, it is not working. what should i do? set timeout -1 spawn /usr/bin/sftp user1@server1 match_max 100000 expect... (3 Replies)
Discussion started by: tungaw2004
3 Replies
Login or Register to Ask a Question