Permission denied with bash.sh to run cron

前端 未结 5 539
忘掉有多难
忘掉有多难 2020-11-29 12:19

How to run a cron with bash script here.What i did as follows and here with errors.I want to know how to do that in ubuntu.I was struck with it now

bash.sh file

5条回答
  •  误落风尘
    2020-11-29 12:45

    TL;DR: Insert "bash" before the script in crontab and in any scripts called by the script.

    I have a fix for this. None of the previous answers worked for me. I have two Asus laptops running Kubuntu (updated to kernel v5.8) with virtually identical configurations. I don't know why one has the problem and the other doesn't. However, after 2 days of experimentation I found a fix. Hopefully, someone more knowledgeable than I can find the cause.

    Cron is using sh instead of bash. I tried adding SHELL=/bin/bash and defining PATH above the commands in crontab and it had no effect. All of my scripts have the #!/bin/bash shebang at the beginning, also with no effect. My scripts' (and their directories') permissions are 777. The scripts don't run for cron or users, no matter what combination of user:group I tried on the files. Using full pathnames is cron and inside the scripts had no effect that was different from using environment variables.

    My fix was to insert "bash" before the script filename in crontab. E.g.:

    00 01 * * * bash $BASH_SCRIPTS/backup_os.sh

    (Yes, cron has no problem with using my environment variables defined in /etc/environment.) Also, in cron, when a script runs another script, the second script will get "permission denied" unless that script is modified to have "bash" before the 2nd script's filename, or use "source" if that'll work with your script.

提交回复
热议问题