Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Command Line Script to Run Multiple Commands in Different Tabs

Why Use a Script that Launches Multiple Command Line Tabs?

Imagine you just rebooted your computer now for some reason…

Do you have this feeling of “Ok… Ii just need to open again a bunch command line tabs, run a series of scripts, start the log tails, open the IDE and I will be good to go!”?

If you still find yourself having to run all these commands, launching all the Docker containers and mounting the entire setup when you reboot your Linux machine, then keep reading! The solution may be a few lines of bash script

How to Run Multiple Commands in Different Command Line Tabs

After struggling with this for some time, I decided to create a single script, that I could run on the system boot, to take care of mounting all this setup for me.

Creating the script to run multiple commands isn’t really a hard task. I wrote some articles before about this here and here.

The tricky part was that some of the commands, that I run on my setup, will keep running and output to the command line as I do my work (like Docker containers, log monitoring, etc…) and I wanted to have them in different Tabs so I can easily access each output for debugging purposes.

This part was the one who took me more time and therefore the reason of me writing this article. But although it took me some research to accomplish it, the solution is rather simple if your Linux machine has gnome-terminal installed. Here is an example:

#!/bin/bash

# Array of commands to run in different tabs
commands=(
    'cd ~/path/to/script1 && ./script1.sh'
    'cd ~/path/to/script2 && ./script2.sh'
    'cd ~/path/to/script3 && ./script3.sh'
)

# Build final command with all the tabs to launch
set finalCommand=""
for (( i = 0; i 

The Multiple Log Monitoring Example

Multiple Log Tails in Different Command Line Tabs Image

Another example situation in which I use this script is to launch tabs with all my debug logs open for quick access during my development. As a Back-End Engineer, I find this to be a must in my everyday work.

#!/bin/bash

# Array of commands to run in different tabs
commands=(
    'tail -f /var/log/apache2/access.log'
    'tail -f /var/log/apache2/error.log'
    'tail -f /usr/local/var/postgres/server.log'
)

# Build final command with all the tabs to launch
set finalCommand=""
for (( i = 0; i 

Here is the Gist link if you want to fork the script.

If you found this post helpful or have something to say, leave a comment bellow

The post Command Line Script to Run Multiple Commands in Different Tabs appeared first on João Ribeiro.



This post first appeared on João Ribeiro | Tech, please read the originial post: here

Share the post

Command Line Script to Run Multiple Commands in Different Tabs

×

Subscribe to João Ribeiro | Tech

Get updates delivered right to your inbox!

Thank you for your subscription

×