What would be the right way to declare an array within a script that will be called by cron?

自闭症网瘾萝莉.ら 提交于 2019-12-25 12:05:52

问题


I have written a KornShell (ksh) script that sets an array the following way:

set -A fruits Apple Orange Banana Strawberry

but when I am trying to run it from within cron, it raises the following error:

Your "cron" job on myhost
/myScript.sh

produced the following output:

myScript.sh: -A: bad option(s)

I have tried many crontab syntax variants, such as:

Attempt 1:

0,5,10,15,20,25,30,35,40,45,50,55 * * * * /path/to/script/myScript.sh

Attempt 2:

0,5,10,15,20,25,30,35,40,45,50,55 * * * * /path/to/script/./myScript.sh

Attempt 3:

0,5,10,15,20,25,30,35,40,45,50,55 * * * * cd /path/to/script && ./myScript.sh

Any workaround would be sincerely appreciated. Thanks much in advance!


回答1:


*/5 * * * * cd /path/to/script && ksh ./myScript.sh :- it will run every 5 mins. Define Path variables also in the cron itself.




回答2:


Does myScript.sh start with

#!/bin/ksh

(or whatever the path is for your ksh)?




回答3:


Although I'm not sure it's the best way to do it, I've managed to solve it this way:

Attempt 4:

0,5,10,15,20,25,30,35,40,45,50,55 * * * * cd /path/to/script && ksh ./myScript.sh


来源:https://stackoverflow.com/questions/306531/what-would-be-the-right-way-to-declare-an-array-within-a-script-that-will-be-cal

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!