I run a shell script at reboot, by having it in my crontab:
@daily apt-get update && apt-get upgrade -y
@reboot bash /root/Start.sh
@reboot /bin/bash -c 'sleep 10 && /bin/mount -a'
...
The shell script is executed, since it launches other .py-scripts successfully, but it does not launch all scripts (all except trouble.py) from within.
However, when I run the shell script myself, with:
bash Start.sh
all scripts within the .sh are executed.
This is my shell-script:
sleep 15
python3 /root/.../trouble.py > /root/error_log_bash.txt
python3 /root/.../working1.py &
python3 /root/.../working2.py &
I've tried so far:
- to change the order within the .sh
- different amounts of sleep before and after
- chmod +x the .py script
- to launch another similar script instead, which works as expected.
- to check the error_log_bash.txt, but it was empty
- sudo the launch in the .sh
Since it works with another script I was considering whether the script is the problem. However, since it works manually I find this difficult to imagine. Am I missing something? What could provoke such a behavior? I'm working on debian, as root.
#Edit @Waltinator Thank you for pointing out the differences between cron and regular env. When I run sh /root/Start.sh instead of bash /root/Start.sh with the manual console I receive no error.
trouble.py
. It could be a number of things, the first that springs to mind is that something it does requires atty
.. – tink Nov 29 '23 at 04:01sleep
in thecron
job - not in the script itself; i.e.@reboot sleep 15; bash /root/Start.sh
– Seamus Nov 29 '23 at 04:01apt upgrade
from cron, things in there frequently want a tty. This looks like an XY problem. There are better ways to do most of this. In particular,mount -a
should be done automatically at boot without cron and it may have dependencies that systemd would be better at sorting out. – user10489 Nov 29 '23 at 04:50echo "=== id ===";id;echo "=== set ===";set;echo "=== env ===";env | sort;echo "=== alias ===";alias
I get a huge output. which I'm also not sure how to find the differences. – Marco Nov 29 '23 at 19:38trouble.py
(that's run in the foreground, without&
) runs ok, but theworking.py
scripts (that are run in the background with&
) don't? Is it correct that you deduced they didn't run since you didn't see them active later? Or did you try to check if they started to begin with? What happens if you have the scripts open some file and write something to it right when they start, just to make a note of the fact they did start? What happens if you put something likesleep 900
at the end of the script, after the background processes are launched? – ilkkachu Nov 30 '23 at 06:48bash Start.sh
orsh Start.sh
from the terminal the script runs, and is visible withtop -c
. When I execute the same command with the cronjob only two of the three python scripts are visible withtop-c
– Marco Dec 01 '23 at 06:31