Skip to content
Advertisement

Time multiple commands running in parallel in shell and save it in file

I have a bash script for which i want to know the time it took to run for individual commands and save them in a log file. Also I need some of these commands to run as a different process. The problem I am facing is I am not able to tell which output belongs to which command for example my script has:

JavaScript

desired output(note here I can see which output belongs to which command ):

JavaScript

but i get something like:

JavaScript

(not sure if they are in order cant tell which one is which), Here I am not sure which output belongs to which command as they complete independently

JavaScript

I tried many things like coupling the commands and then timing , creating a function for two commands and then time them and many other things but every time something caused an issue or didn’t give me the desired results. I am guessing this should be an easy task for someone who has some experience in bash scripting.Thanks for your time

Update: where my_command is something like:

JavaScript

Advertisement

Answer

With some help I was able to find a way around this issue what worked for me is this

JavaScript

the output i got was like this were the time is above the tag mentioned:

JavaScript

Moreover I couldn’t test Jacek Zaleski’s answer properly though as it gave me some errors with syntax when I tried it in my case.Thanks anyway to everyone for the time and effort. Hope this helps someone.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement