I've created a script that has to be executed on boot and has to run another script (which sets some variables) before executing other commands.
After writing the script, I've successfully executed it in the console, but if the script is added to crontab, the other script inside this one is not executed.
The script (main-script.sh) that has been added to crontab is the following:
#!/bin/bash
source /home/pi/test-script.sh
python mycustompythonscript.py
and the test-script.sh is the following (I replaced the actual script with this one for testing):
#!/bin/bash
echo "greetings from test script" > test.txt
So when i run main-script.sh from console, test-script.sh is executed (the file is created) and the python script is executed. Upon rebooting the RPi, however, the python script is executed, but the test-script.sh is not executed (test.txt file is not created).
Does anyone know what could be the possible reason that test-script.sh is not executed in case the main-script.sh is executed by cron?
main-script.shin crontab, it might be executed via/bin/shinstead of/bin/bash. In case ofsourcecommand it's bash-specific. Try to replace that with. /home/pi/test-script.sh- that should work across the board on all POSIX compliant, bourne-like shells. Let me know if that works for you, and if it does I'll post it as a proper answerSHELL=/bin/bashin your crontab which makes life easier.#!/bin/bash, so a modernshwill launchbash.sh /path/to/main.shdefinitely won't like bashisms (unless it's CentOS where/bin/shis/bin/bash).