Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write a shell script that starts tmux session, and then runs a ruby script

I want to write a shell script that does this:

  • First, create a tmux session
  • Second, run a ruby script called "run.rb" INSIDE the tmux session

In pseudo-code, what I want to do:

tmux new -s my_session ruby run.rb     # NOTE: I want this to run inside the my_session tmux session. tmux detach 

How do I do this? (More posts I read, more confusing it gets.)

like image 514
hackstar15 Avatar asked Aug 09 '15 09:08

hackstar15


People also ask

How can I set my default shell to start up tmux?

Configure Terminal to start tmux by defaultbash_profile shell startup file, just above your aliases section. Save the file and close it. Then close and reopen the terminal to start using tmux by default, every time you open a terminal window.

How do I Untach a session in tmux?

Detach From A Session To detach (meaning exit the window to come back to later) from the tmux session, use CTRL + b then d (hold ctrl, press b, let go of both of the keys, and press d).


1 Answers

#!/bin/bash tmux new-session -d -s my_session 'ruby run.rb' 
  1. Create a file named my_script.sh and give it the above contents.

  2. Make the file executable by running:

    chmod 755 my_script.sh or chmod +x my_script.sh

  3. Then run the shell script:

    ./my_script.sh

Making the shell script executable

When you perform the chmod 755 filename command you allow everyone to read and execute the file, and the file owner is allowed to write to the file as well. You may need this for Perl and other scripts that should be run via a webserver. If you apply 755 to a directory, it means that everyone can go to it and get its file listing.

These permissions are usually translated into textual representation of rwxr-xr-x.

You can alternatively use chmod +x file_name on a file to make it executable.

like image 178
K M Rakibul Islam Avatar answered Sep 18 '22 06:09

K M Rakibul Islam