在crontab中运行时出现bash问题



希望有人能为我解决这个问题指明正确的方向。我对if语句进行了抨击。

checkPID=(MySQL queries to count columns)
if [[ $checkPID -eq 1 ]]
then
echo "PID already exist, running update queries instead"
(MySQL update queries here)
else
echo "PID does not exist, running insert queries"
(MySQL insert queries here)
fi

当我在命令行上运行这个bash脚本时,一切都按预期进行,但当我通过crontab自动执行时,无论checkPID变量的值如何,它都不遵循if条件。

您的crontab行使用dash(/bin/sh(而不是bash

*/10 * * * * sh /home/servo/scripts/slavereport.sh –
change to:
*/10 * * * * bash /home/servo/scripts/slavereport.sh –

由于您使用的是bash操作,请记住将#!/bin/bash作为脚本中的第一行。

修复其中任何一个也应该解决问题。不需要两者都做。

最新更新