Visualizzazione post con etichetta Unix. Mostra tutti i post
Visualizzazione post con etichetta Unix. Mostra tutti i post

lunedì 1 dicembre 2014

Unix Tip: executing processes in serial/parallel mode

I am working for a customer that has set up tons of processes that are executed periodically by a scheduler.
We are currently applying modifications to these scripts and we need to execute them frequently to check results. The scheduler is a very old fashioned one and the quickest way to simulate an execution is to create a Unix script that execute processes in the same way, which means simulating serial and parallel executions.

Let's think about the following situation:

We want to execute first the script A.sh and then in parallel the scripts B.sh and C.sh and finally the script D.sh.
The following script does the job:

serial_parallel_scripting.sh

./A.sh &
wait
./B.sh &
./C.sh &
wait
./D.sh

The ampersand symbol (&) executes the job in background and the wait command will wait for the script to terminate. The script will first execute the A.sh script and wait for it to end. Later it will execute B.sh and C.sh scripts in parallel. Finally, when both of them terminate, it will execute the D.sh script.

martedì 27 maggio 2014

Unix Tip: How to format LS output

Issue
I want to use Unix ls command output and write it to a well-formatted file
Solution:
I just used the following command:

ls -ltra | awk -v OFS=";" '$1=$1'

in a bash script.
OFS parameter is used for specifying the separator for the file.


You can redirect the output to a file and then process it as it was a semicolon delimited file.