Steps to create and execute the bash script
Step 1: Open the terminal window.
$ gedit tmux_script.sh
Step 3: Now use the following code in the script.
- tmux_script.sh
#creates new session
tmux new-session -d -s my_ruby_session
# Creates the session for the running ruby script
tmux send-keys -t my_ruby_session "ruby ruby_script.rb" C-m
# Attaches to session
tmux attach-session -t my_ruby_session
Step 4: Make the script executable using the following command.
$ chmod +x tmux_session.sh
Step 5: Execute the script.
$ ./tmux_session.sh
Output:
Execute the script which we have previously created, by making the script executable.
Here once we run the script, a new tmux session opens up. The below green strip indicates that we are currently in a tmux session. This automatically runs the ruby script that we created before. The Tmux session status bar informs you that you are currently within a Tmux session, which allows for enhanced control over the terminal. Additionally, as part of the Tmux session’s setup, it automatically executes the Ruby script that we created previously. This means that as soon as the Tmux session is created, your Ruby script starts running within it without any manual intervention.
How to write a shell script that starts tmux session, and then runs a ruby script
Scripts are important for streamlining workflows and automating tasks. One such way to streamline workflow is by using Tmux [Terminal Multiplexer]. When used along with shell scripts we will be able to automatically commence a Tmux session and perform certain tasks. In this article, we shall see how to use a shell script that will automatically start a tmux session and then run a ruby script.