crontab job not executed with variables


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting crontab job not executed with variables
# 1  
Old 09-20-2012
crontab job not executed with variables

Hi,

I am trying to execute a script (for once) during the booting time in Ubuntu system. However, the result is only showing the strings without without the variables.

Here is the script:

Code:
MgrIp=$(ec2-describe-instances --filter tag:Name=Mgr --filter instance-state-name=running | egrep disabled | cut -f18)
echo "Mgr IP="$MgrIp >> /home/ubuntu/myLog

The result in the output file (myLog) is the following:
Code:
Mgr IP=

The result should be:
Code:
Mgr IP=xxx.xxx.xxx.xxx <---- (an IP address)

But,when I execute the script manually by invoking the command:
./myScript.sh
it executes perfectly and providing me all the correct outputs (the strings and the variables).

the crontab entry is the following:
@reboot /home/ubuntu/myScript.sh

Also, the permission on the myScript.sh is 777

Am not sure if this is the only way to execute script for once after the booting time.

Thank you in advance

Last edited by Corona688; 09-20-2012 at 07:31 PM..
# 2  
Old 09-20-2012
777 is not the magic sledgehammer to fix all permissions problems. 750 ought to do.

You probably don't have that application in your PATH, so it can't run anything, leaving the variable blank. . /etc/profile at the top of your script perhaps to make sure it loads a complete one.
# 3  
Old 09-22-2012
Corona688,
Placing the line:
Code:
. /etc/profile

at the top of the script didn't solve the problem.

I even moved the calling of the script to /etc/rc.local
but again same issue. Still receiving empty variable values.

Last edited by turki_00; 09-22-2012 at 09:47 AM..
# 4  
Old 10-04-2012
Found a solution:

in /etc/rc.local file:
Code:
export EC2_PRIVATE_KEY=/home/ubuntu/pk.pem
export EC2_CERT=/home/ubuntu/cert.pem
export EC2_HOME=/usr/bin

I also placed the calling for the script with the redirecting the stderr in /etc/rc.local:

Code:
/home/ubuntu/tt.sh >> /home/ubuntu/myLog 2>&1

# 5  
Old 10-04-2012
This looks like a run-on command to me (means needs spaces)
Code:
# old
MgrIp=$(ec2-describe-instances --filter tag:Name=Mgr --filter instance-state-name=running | egrep disabled | cut -f18)
# with spaces
MgrIp=$(ec2 -describe -instances --filter tag:Name=Mgr --filter instance-state-name=running | egrep disabled | cut -f18)
# the way I would do it assuming ec2 is actually a command or script:
MgrIp=$(/path/to/ec2 -describe -instances --filter tag:Name=Mgr --filter instance-state-name=running | /usr/bin/egrep disabled | /usr/bin/cut -f18)

The last line leaves no doubt to the shell where to look for commands.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to detect and fix why crontab job is not executed?

I have set several cron jobs. I recently added a new cron job that copies a file of last day from another server and is executed each day (for example at 04:00 am) but when I check next day the file hasn't been copied. I'm working in GNU/Linux CentOS (2.6.32) system. The files that I need to... (23 Replies)
Discussion started by: Ophiuchus
23 Replies

2. UNIX for Dummies Questions & Answers

Cron job executed at wrong time

Dear *nix users. I'm on Mac OS 10.6 / Terminal and try to use crontab to schedule two scripts every 30 minutes and every 41 minutes. I followed the man instructions and created / installed a crontab file for the current user:crontab -e with the following content */30 * * * *... (4 Replies)
Discussion started by: moxnos
4 Replies

3. Shell Programming and Scripting

Users who desire to have their .profile executed must explicitly do so in the crontab entry. Why?

The .profile file should be read when the user logs in. So, there should be no need to execute .profile file again in a cron job (since the cron job is run after the user logs in). Doesn't the cron require login from the user. Then, from where does the cron execute? Please help!! (1 Reply)
Discussion started by: thulasidharan2k
1 Replies

4. UNIX and Linux Applications

Log files to view job executed in Autosys -- Help ASAP

Hi all, I really need your help ASAP on this. Below is the description of my problem and a sketch of Autosys Job Activity Console ++++++++++++++++++++++++++++++++ File View Options +++++++++++++++++++++++++++++++ Job Name Description Status Command Machine... (1 Reply)
Discussion started by: sakal_woman
1 Replies

5. Shell Programming and Scripting

sed: command garbled - when executed with $variables

I have got a file job_tree.lst , which contains 1 line as below $ cat job_tree.lst ABC_D_EQ_XXXXX_YYYY_PRD_UX 05/08/2009 05:47 05/08/2009 05:50 IN 13412850/0 I want to get a child job string 3 characters offset from the parent job string (i.e. ABC_D_EQ_XXXXX_YYYY_PRD_UX 05/08/2009... (4 Replies)
Discussion started by: Armaan_S
4 Replies

6. Shell Programming and Scripting

Script errors out only when its executed via job

I wrote a script to shutdown the oracle database. The script works fine when I manually run the script. However, when i schedule a job, i get the following error. Shutting Down cmismart .................... ORA-01034: ORACLE not available ORA-27101: shared memory realm does not exist SVR4... (6 Replies)
Discussion started by: mrx1350
6 Replies

7. Shell Programming and Scripting

Routine doesn't give output when executed in crontab

I have a script running in the crontab that gets data from a database every hour. Now I would like to execute a fortran routine to process the data in some way, after getting it and saving it locally. I have added the following commands to my script: set convert =... (1 Reply)
Discussion started by: SharkM
1 Replies

8. Shell Programming and Scripting

bash scripting cannot executed in crontab

hi guys, i have a problem. a week ago i made a successful crontab that execute bash scripting daily, it worked well but now, it doesn't work at all, in the mail i have: " /home/jimmy/cha/scripts/cekpderr produced the following output: lagi jalan /home/jimmy/cha/scripts/cekpderr:... (6 Replies)
Discussion started by: jimmbp
6 Replies

9. Shell Programming and Scripting

Shell script doesn't get executed using crontab

I have the following crontab entry to run a shell script for every 30 minutes of every day: 30 * * * * $HOME/main.sh > $HOME/main.log 2>$HOME/error.log after I created the crontab file I have also done: $crontab my_crontab I also check to make sure it exists, by using the following... (11 Replies)
Discussion started by: radhika
11 Replies

10. Shell Programming and Scripting

ant not being executed as cron job

i have a script that uses an ant build.xml and its targets to pull a project from a cvs server, attempt to build the project, and then email me the results. When I run the script (either @ CLI or as a cron job) while I am logged in, everything works fine. However, if the script is set up to run... (5 Replies)
Discussion started by: kingfinny
5 Replies
Login or Register to Ask a Question