i have got a bash file which i want to toggle via the sudo crontab list. Problem is, that it does not work, because when i run the script with sudo, there is a syntax error message on this line:
size=(`du -h $backupDir --summarize`)
If i run the same script without, i have to type the sudo pw, but it works without any problems. I allready tried a few variations with brackets, with or without backticks, with or without spaces, etc but nothing helped. The error message is:
Syntax error: "(" unexpected (expecting ";;")
Any help?
The problem here is that you use bash-syntax, and the script (when it is executed from cron) is interpreted by
/bin/sh
(that known nothing about arrays and the()
construction.).You must either specify
bash
as an interpreter of the script using she-bang notation:or run the script explicitly with
bash
from cron:or rewrite script so, that it could run without arrays.