我测试了以下script.sh文件。当我从命令提示符下调用时它起作用:
#!/bin/ksh
export file="test.txt"
export dir=$HOME
export exe_env="test"
export batch="1"
echo "info: `date` :Environment: ""$exe_env"
echo "info: inputfile: ""$dir/$file"
if [ -f $dir/$file ] ; then # check if input file exists
job_list=($( grep -e ':'"$batch"'$' "${dir}/${file}" ))
for job in "${job_list[@]}"
do
echo ${job}
done
fi
但是当我从crontab运行时,如下:
SHELL=/bin/ksh
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=
HOME=/
* * * * * script.sh >> nohup_1.out 2>&1
我得到了错误-
第11行的语法错误:`('意外
我尝试使用双括号。没有解决。任何帮助。
答案 0 :(得分:0)
从cron运行任务时,通常会定义一小组环境变量。 $ HOME可能会丢失。尝试使用文件或命令的绝对路径运行脚本。