1

Is anyone familiar with how to run programs from crontab in tmux instead of a screen session?

For instance what would be the command line equivalent of this:

@reboot cd /home/morggin/mcserver && screen -dmS McMyAdmin ./MCMA2_Linux_x86_64
  • tmux new -d -s McMyAdmin ./MCMA2_Linux_x86_64... – jasonwryan Mar 3 '15 at 5:07
  • Thank you jasonwryan!! so that would be -d to demonize or start it as a detached session and -s McMyAdmin to name the panel correct? – morggin Mar 3 '15 at 5:40
  • No. I have never used screen much. – anyone Mar 3 '15 at 6:14
2

You can do that from one command as Jason indicated. You can do

 tmux new-session -d -s session_name your_command

The -d detaches the new session from the terminal. It might not needed when not started from a cron job instead from a terminal, but it won't hurt. (new is short for new-session)

This has one major disadvantage in that it closes that session ifyour_command terminates, and if anything useful is written to the session, that info is lost. I suggest you use a multi-line script to start these kind of commands and start that from your cron at reboot:

#!/bin/bash
cd /home/morggin/mcserver
tmux new-session -d -s McMyAdmin -n McMyAdmin
tmux send-keys "./MCMA2_Linux_x86_64"

which starts the program in the bash session tmux creates anyway (there are other ways to prevent program exit to close a window, but from what I recall some involve double bash startups). The -n names the window within the session, useful in case you decide to add creation of multiple windows in the session.

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.