0

I'm having a heck of a time getting a tmux session to be created from a script executed by crontab. The script executes and the session is created without fail from just running it but if I run it from crontab the session isn't created and it doesn't run.

Cron command looks like:

<time> /home/Startup.sh

That script just has this one line in it.

sudo /usr/bin/tmux new-session -d -s mysession 'bash /home/pathtolaunchscript.sh'

Inside that other script is an application that just runs and does its thing.

I've made sure it's executing as the right user (in my case I'm testing as sudo) and even if I couldn't find the session I'd be able to tell if it was running anywhere by virtue of the application.

Don't really know what else to try. Other cron operations work besides this one and the scripts work outside of crontab. Thanks in advance

Edit 1: It was asked if it worked executing sleep, so I ran the following but it didn't create the session either.

sudo /usr/bin/tmux new-session -d -s mysession 'sleep 1000'

Edit 2: All paths in the scripts and in cron are complete, absolute paths.

  • Does tmux start if you have it run "sleep 1000" instead of the bash command? – Nicholas Marriott Jul 23 '19 at 22:23
  • I'll try that in just a moment. Thanks in advance – Tyler C Jul 23 '19 at 22:25
  • No, I get the same error @NicholasMarriott Just error connecting to tmux-0/default or no sessions error – Tyler C Jul 23 '19 at 22:35
  • Is the job running as a user that can use sudo passwordless? – Gordon Davisson Jul 24 '19 at 0:59
  • @GordonDavisson I'll double check but I ran it under "sudo crontab -e" which I was led to believe would be able to. I'd like for it all to eventually run under a single user but I've had issues so I changed it all to root to try and fix it. – Tyler C Jul 24 '19 at 3:11

Your Answer

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

Browse other questions tagged or ask your own question.