Showing posts with label Shell Script. Show all posts
Showing posts with label Shell Script. Show all posts

Thursday, July 13, 2017

Bash Script to Run Multiple Commands in Different Tabs

Running Multiple Commands in Different Command Line Tabs


This small tutorial is directed at people that still have to do a lot of initial setup every time they reboot your Linux machine and are looking for some automation, with a simple bash script.
Creating a bash 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 I wanted some of those commands to run in different tabs so I can easily access the outputs for debugging purposes (like Docker containers, log monitoring, etc…).
I also didn’t want to go to the trouble of installing and configuring tools like tmux or tmuxifier (if you want something more advanced, definitely check them out!) for such a simple task like launching a few command line tabs. So, I decided to do some research and I found that the solution is rather simple if your Linux machine has gnome-terminal installed.


Tuesday, October 20, 2015

Shell script to run multiple programs in Linux

"Recently, I had a situation where I needed to execute multiple programs in Linux at the same time while redirecting their outputs to separated log files and wait for them to finish.
If you ever need to do something like that, I leave year the script that I used to accomplish that task:"

#!/bin/bash
 
# Add the full path processes to run to the array
PROCESSES_TO_RUN=("/home/joao/Code/test/prog_1/prog1" \
                  "/home/joao/Code/test/prog_2/prog2")
# You can keep adding processes to the array...
 
for i in ${PROCESSES_TO_RUN[@]}; do
    ${i%/*}/./${i##*/} > ${i}.log 2>&1 &
    # ${i%/*} -> Get folder name until the /
    # ${i##*/} -> Get the filename after the /
done
 
# Wait for the processes to finish
wait
 
Post source:  http://joaoperibeiro.com/execute-multiple-programs-and-redirect-their-outputs-linux/