0

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

Jeevan Dongre
  • 711
  • 2
  • 15
  • 33

4 Answers4

1

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.

raphink
  • 11,337
  • 6
  • 36
  • 47
0

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

which mon-put-data

toppledwagon
  • 4,215
  • 24
  • 15
0

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

Bart De Vos
  • 17,761
  • 6
  • 62
  • 81
daya
  • 271
  • 1
  • 6
0

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.

adaptr
  • 16,479
  • 21
  • 33