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
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.Sign up to join this community
You can do that from one command as Jason indicated. You can do
tmux new-session -d -s session_name your_command
-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
This has one major disadvantage in that it closes that session if
your_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.