我有一台运行Linux操作系统的服务器。我正在尝试在crontab文件中安排一项cron作业,以每两周(两周)在周二上午9点运行一个任务。我试图运行以下命令:
0 9 * * 2 root test $((10#$(date +\%V)\%2)) -eq 0 && ( java -jar /email/emailRemind.jar )
此脚本不起作用,它显示此消息
/bin/sh: 1: arithmetic expression: expecting EOF: 10#24%2"
有什么想法吗?
似乎您的表达是错误的,我在bash中尝试了一些步骤:
$((10#$(date +\%V))) -> 24
$((10#$(date +\%V)\%2)) -> bash: 10#24\%2: syntax error: invalid arithmetic operator (error token is "\%2")
我不明白\%2对您意味着什么,您想做什么?Mod,是的!感谢您的回答!
与https://stackoverflow.com/questions/5688576/how-to-use-mod-operator-in-bash#5688592相同
我尝试了这个,它起作用了。
$((10#$(date +\%V)%2))
我的cron
* * * * * echo $((10#$(date +\%V)%2)) >> test.log
希望这会有所帮助!