student_XML786
student_XML786

Reputation: 51

cronjob not executing script as expected

I have this script running on a Juniper router which essentially is running Freebsd 10. Problem i am facing is the when cronjob is running this script variable ($current_mem) doesn't show any value as a result logger is also not able to log that value. Anyone have any clue what is going on.

#!/bin/bash
localpid=$$
renice -n +1 $localpid &
current_mem="test"
echo "$current_mem" <<<<shows right value 
current_mem=$(cli -c "show task memory" | grep "Currently In Use" | awk 
'{print $5}' | grep -o '[0-9]*')
echo "$current_mem" <<<<<<<<<<"when cron is running it show's nothing"
if [ "$current_mem" -gt "65" ]
then
echo "$current_mem" <<<<<"shows nothing"
logger -t JTASK_OS_MEM_HIGH -p "external.notice" "Using more then 65 
percent of available memory Current utilization:$current_mem" <<<<<

else
echo "$current_mem"
logger -t JTASK_OS_MEM_NORMAL -p "external.notice" "Using less then 65 
percent of available memory Current utilization: $current_mem"

fi

When i run this script with sh task_mem.sh, script works perfectly but when i run it through cron it doesn't show/dump the value of variable. This what i have for the cron job

# crontab -l
*/1 * * * * sh /var/tmp/task_mem.sh >> 
/var/tmp/task_mem_cron.log

Upvotes: 1

Views: 191

Answers (1)

student_XML786
student_XML786

Reputation: 51

@GordonDavisson that was it "cli" was in /usr/sbin/cli not in /bin as a result cron was not able to execute it. Once i added the full path it started working. Thank you so much for your help

Upvotes: 1

Related Questions