1

I'm trying to run two command at reboot on my raspberry pi. Here is what I tried :

@reboot sudo su - pi -c "screen -dm -S myscript_cron python ~/myfolder/myscript.py"
@reboot sudo su - pi -c "screen -dm -S autossh_cron autossh -M 30000 -N my_ssh_config -R 3030:localhost:3030 -C"

The first reboot command is working very well ! However the second one won't start. I activated the cron logs and everything seems correct.

Thanks for your time

Simon

3 Answers 3

2

It is likely that it cannot start SSH as soon as you have booted due to network connection not being established immediately

@reboot sleep 60; ssh user@hostname

For example should work

3
  • Nope it's not working either :/ Commented Apr 10, 2017 at 14:17
  • Could you please add the output of the logfile Commented Apr 10, 2017 at 14:18
  • 1
    It needed a bit more than 60 sec ;) Thx for your help ! Commented Feb 3, 2018 at 22:01
0

You could set wait for network connection before continuing boot, in case that is the cause. Find it in the raspi-config settings.

sudo raspi-config

Boot options - Wait for network at boot.

1
  • could you give a detailed solution? 😁
    – cregox
    Commented Jul 11, 2021 at 7:15
0

You can start autossh as early as you want as long as you set the AUTOSSH_GATETIME environment variable to 0, which will make it keep trying even if the very first connection attempt fails.

Also note that in case of using cron you probably should add the -f option to push autossh to the background. (This also automatically sets AUTOSSH_GATETIME to 0 as well).

Also there is absolutely no need to use -M other than 0. ServerAliveInterval + ServerAliveCountMax is better in basically every way (which is even said in the autossh man page itself).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.