Last active
August 21, 2024 15:15
-
-
Save rudolfovich/26604ba416bf607d91b60cb183c0270d to your computer and use it in GitHub Desktop.
Startup cron + tmux script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Cron + tmux statup script | |
# Approach was taken from http://www.nburles.co.uk/linux/starting-a-process-in-a-tmux-session-using-cron | |
# Sleep for 5 seconds. If you are starting more than one tmux session | |
# "at the same time", then make sure they all sleep for different periods | |
# or you can experience problems | |
/bin/sleep 5 | |
# Ensure the environment is available | |
source $HOME/.bashrc | |
source $HOME/.profile | |
SESSION_NAME=mystartup | |
/usr/bin/tmux set-option -g default-shell /bin/bash | |
# Run bash without command | |
/usr/bin/tmux new-session -ds $SESSION_NAME "source $HOME/.bashrc; source $HOME/.profile; bash" | |
# Execute <COMMAND #1> and then run bash to save output. Without bash tmux window will close and you can't see any errors if they occured. | |
/usr/bin/tmux new-window -dt $SESSION_NAME:91 -n "geth" "source $HOME/.bashrc; source $HOME/.profile; <COMMAND #1>; bash" | |
/usr/bin/tmux new-window -dt $SESSION_NAME:92 -n "video" "source $HOME/.bashrc; source $HOME/.profile; <COMMAND #2>; bash" | |
/usr/bin/tmux new-window -dt $SESSION_NAME:95 -n "analyzer" "source $HOME/.bashrc; source $HOME/.profile; <COMMAND #3>; bash" | |
# Installing script: | |
# touch $HOME/startup.cron | |
# chmod +x $HOME/startup.cron | |
# crontab -e | |
# @reboot $HOME/startup.cron | |
# vim $HOME/startup.cron | |
# and insert this file content... | |
# Attaching | |
#tmux attach-session -t mystartup |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi @jerlich, thanks for question.
I've added comments with explanation why
bash
is written after command.If
bash
will be before<COMMAND #1>
, then<COMMAND #1>
will be executed only if you exitbash
manually.