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
Answer
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.
No comments:
Post a Comment