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:

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:

Mgr IP=

The result should be:

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

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.

Corona688,
Placing the line:

. /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.

Found a solution:

in /etc/rc.local file:

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:

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

This looks like a run-on command to me (means needs spaces)

# 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.