0

I'm running the following script on @reboot cron with root:

autossh -f -i /home/pi/.ssh/myRemote.pem -R 2210:localhost:22 ubuntu@server.com

When I run manually it works fine but from cron I see it show in the logs continually failing:

Nov 25 01:15:56 kirkins autossh[1936]: starting ssh (count 1)
Nov 25 01:15:56 kirkins autossh[1936]: ssh child pid is 1947
Nov 25 01:16:01 kirkins autossh[1936]: ssh exited prematurely with status 130; autossh exiting
Nov 25 01:16:40 kirkins autossh[605]: starting ssh (count 13)
Nov 25 01:16:40 kirkins autossh[605]: ssh child pid is 1949
Nov 25 01:16:40 kirkins autossh[605]: ssh exited with error status 255; restarting ssh
Nov 25 01:18:48 kirkins autossh[605]: starting ssh (count 14)
Nov 25 01:18:48 kirkins autossh[605]: ssh child pid is 1970
Nov 25 01:18:49 kirkins autossh[605]: ssh exited with error status 255; restarting ssh

Anyone know what's going wrong? I saw some related posts on other StackExchange sites but none of the solutions worked for me.

1

The reason is probably that ssh does not like the fact that it is started without a controlling terminal (cron children do not have one).

You could try ssh -tt. Or run it within screen / tmux.

  • For tmux would I just do tmux ssh ...? – Philip Kirkbride Nov 25 '17 at 1:27
  • no luck with autossh -tt – Philip Kirkbride Nov 25 '17 at 1:32
  • @PhilipKirkbride I am not familiar with tmux and thus do not know the syntax. The man page knows the answer. – Hauke Laging Nov 25 '17 at 1:40
  • @PhilipKirkbride Maybe it works if you execute a command via ssh which never (or after a long time) exists like sleep 100000. – Hauke Laging Nov 25 '17 at 1:42
  • I'm finding the combination of -tt with sleep infinity solves my issue, thanks. – Philip Kirkbride Nov 26 '17 at 22:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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