1

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.

Tyler C
  • 119
  • 6
  • 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 00: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 03:11
  • @TylerC In that case, the job is in root's crontab and will run as root, so `sudo` is not needed in the script (although it shouldn't cause trouble either). On the other hand, if you put the job in a non-root user's crontab, `sudo` generally won't work. The only cases where `sudo` is useful in a cron job is when it's run under a non-root user that has a sudoers entry that allows passwordless `sudo`, or when a root job uses `sudo -u` to run something as a different user. So, it's not the current problem, but it's something you might run into later. – Gordon Davisson Jul 24 '19 at 05:16
  • lack of pty might cause this – asdmin Jul 27 '19 at 11:26

0 Answers0