0

I am working on project in which we execute shell script which invokes the Node process and further processing happens. I want to design a script which should log the start time, termination time of the process created by the shell script which invoke Node.

How to do that ?

1 Answer 1

0

If your using Bash, there is the command called date.

#!/bin/bash
date > /path/to/your/logfile;
node your_program && date >> /path/to/your/logfile

naturally you will have to add your node program and whatever arguments after node in the script, and you will have to designate the your logfile, but that should output the time (granted milliseconds before) your program starts, and the time your program ends. You can even format the date command to output the time in a way that's the most meaningful to you. Have fun benchmarking!

5
  • Hey @knotech, thanks for posting comment. I am thinking that when my shell file (script_import.sh) is been called. Can i get the time of node process creation and when it completes its execution, then time of termination ? is it possible in any case. Aug 26, 2014 at 7:19
  • Have updated my answer to reflect that. Thanks for clarifying. Aug 26, 2014 at 7:27
  • How about using cron tab to call one shell script file which in turn checks for the node process and as soon as it didnt found it, it logs the current time ? Aug 26, 2014 at 10:11
  • Cron runs at regular intervals so, you would only get precision within the interval designated by cron to run the check script, to check. The method above while not perfectly precise, (especially if you are really trying time a child process spawned by the script) will give you better precision. Aug 26, 2014 at 10:43
  • How about running a cron job at 2 ms interval and calling shell file to check for process exist state.? We dont need exact time, interval of some milliseconds will be tolerable. can i use ps with grep to find node process ID and time accordingly. Aug 26, 2014 at 12:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .