I have a script that checks my home rpi2 for a file using ssh, pk auth, if the file exists it deletes it (again ssh pk auth) and opens a reverse ssh with:
ssh -fN -R xxxx:localhost:22 user@myhomepiserver.com

when running the script from the command line it works well i get the reverse shell.

When running from systemd-cron, i don't get the process up! checking with ps -efwww|grep "ssh -f"|grep -v grep

the crontab is simply: */1 * * * * /home/me/my_r_ssh_script.sh

I verified that:

  1. happens on both arch arm and arch x86 with systemd-cron installed.
  2. does not happen on ubuntu with crontab installed.

BTW, i have verified that the script runs as use 'me' and indeed it does do i'm sure it uses the right key, also i tried logging g with -vvv and what i saw was that unlike from command line seems like the remote does not answer when i run from cron OR maybe the answer doesn't get to the client for some reason, not sure why.

Any help\hint is appreciated!

  • seems like systemd kills every process created by the cron scripts from some reason. Jul 31 '18 at 11:51
  • put on hold ? this is an office solution for managing my iot usb hub in the office to work from home, don't be quick to judge :-\ Aug 1 '18 at 4:07

systemd-cron is not an official systemd package. It does not seem to offer any detailed configuration of the executed systemd units, so I recommend configuring the timers yourself, see for example https://wiki.archlinux.org/index.php/Systemd/Timers#As_a_cron_replacement .

Then you can play with the following options: KillMode, Type, RemainAfterExit, PIDFile, .. to prevent the process from being killed.

  • 1. wanted to save me the hassle of creating my own timed service 2. changing the code in systemd-cron to be KillMode=process is actually a good idea as it will behave like normal crontab does. didn't know about that option. 3. the document apprently offers a solution i couldn't see till i looked for it. i'll still accept this answer as it's more creative and can contain a real solution to systemd-cron Aug 1 '18 at 4:06
  • 1
    solution i've found: * drop the systemd-cron and use real cron client. * don't run ssh is the background with '-f' this way the process says a live just like normal systemd process, issue is, i don't have anyone to kill it except issusing a kill on the remote myself. Aug 1 '18 at 4:09
  • @codeScriber thanks for your feedback. I wondered why the ssh client would be forking but I couldn't ask this due to not enough points to post comments and asking questions in an answer being against the site policy :) (I also noticed only now you actually included the -f in the ps command you posted in your question) Stil, I'm glad my answer managed to help you find a solution!
    – mx1up
    Aug 1 '18 at 9:30

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