Possible Duplicate:
My cron tasks report command not found

I am trying to run a bash script

#!/bin/bash

export AWS_CLOUDWATCH_URL=https://monitoring.amazonaws.com

# get ec2 instance id
instanceid=`wget -q -O - http://169.254.169.254/latest/meta-data/instance-id`

memtotal=`free -m | grep 'Mem' | tr -s ' ' | cut -d ' ' -f 2`
memfree=`free -m | grep 'buffers/cache' | tr -s ' ' | cut -d ' ' -f 4`
let "memused=100-memfree*100/memtotal"

mon-put-data --metric-name "FreeMemoryMBytes" --namespace "System/Linux" --dimensions "InstanceId=$instanceid" --value "$memfree" --u$

mon-put-data --metric-name "UsedMemoryPercent" --namespace "System/Linux" --dimensions "InstanceId=$instanceid" --value "$memused" --$

I have added this bash script in the cron but when I checked the cron it says command not found thats "mon-put-data"

when I just type the commands it runs fine. Whats the problem

link|improve this question

feedback

closed as exact duplicate by Iain, Scott Pack, DJ Pon3, Chris S, MDMarra Jan 11 at 15:15

This question covers exactly the same ground as earlier questions on this topic; its answers may be merged with another identical question. See the FAQ for guidance on how to improve it.

4 Answers

up vote 1 down vote accepted

It is likely that the mon-put-data command is not in a standard path. From the terminal, you can check this by typing which mon-put-data, then try to use the full path in the script.

This is because a bash script launched from cron won't read your .bashrc or .bash_profile, which may override the default path.

link|improve this answer
feedback

Try to add the full path to mon-put-data. From your command line you can find this with:

which mon-put-data

link|improve this answer
feedback

The problem is that the user that executes the script does not have the same environment (specifically, not the same PATH) that you do.

Additionally, I would suggest you use $(command) instead of `command`, as the latter is deprecated and can cause problems with quoting.

link|improve this answer
The obsolescence of the backticks is worth mentioning indeed... – Raphink Jan 11 at 10:18
feedback

Are you using the same shell? Check. You might be using csh in terminal and the script might use bash.

link|improve this answer
the question has a 'bash' tag – glenn jackman Jan 11 at 11:56
feedback

Not the answer you're looking for? Browse other questions tagged or ask your own question.