Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

share|improve this question

marked as duplicate by Iain, Scott Pack, RobM, Chris S, MDMarra Jan 11 '12 at 15:15

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

4 Answers 4

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.

share|improve this answer

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

which mon-put-data

share|improve this answer

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.

share|improve this answer
    
The obsolescence of the backticks is worth mentioning indeed... –  ℝaphink Jan 11 '12 at 10:18

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

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

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