我在基本上运行Freebsd 10的Juniper路由器上运行此脚本,我面临的问题是cronjob运行此脚本变量($ current_mem)时不显示任何值,因为结果记录器也无法显示记录该值。任何人都知道发生了什么事。
#!/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
当我使用sh task_mem.sh运行此脚本时,脚本可以完美运行,但是当我通过cron运行它时,它不会显示/转储变量的值。这就是我要做的Cron工作
# crontab -l
*/1 * * * * sh /var/tmp/task_mem.sh >>
/var/tmp/task_mem_cron.log
答案 0 :(得分:1)
@GordonDavisson就是“ cli”,它位于/ usr / sbin / cli中,而不位于/ bin中,因此cron无法执行它。一旦我添加了完整路径,它便开始工作。非常感谢您的帮助