LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Script to send notification when process finishes (https://www.linuxquestions.org/questions/linux-newbie-8/script-to-send-notification-when-process-finishes-4175576393/)

loadedmind 04-01-2016 08:21 AM

Script to send notification when process finishes
 
Hey all. So, the goal here is to know when tape backup jobs are idle (nothing being backed up). The process name I'm interested in is called nvjobmgr. They only exist (as far as I can tell, anyway) when jobs are active. Then they disappear when idle. I'm trying to determine how long Netvault is idle before the next set of jobs kick off. This metric, hopefully, should help determine whether we need to purchase additional drives, how much more/less data it's backing up, etc.

The initial thought was to somehow "daemonize" the script to constantly monitor PID names for process name "nvjobmjr", write a statement with date/time stamp when jobs start into a file (perhaps /var/log/netvault/nvactive.txt), then create a different file (/var/log/netvault/nvidle.txt) when jobs finish.

If anyone has done something similar, might you be willing to share your code please?

TenTenths 04-01-2016 08:37 AM

If your process creates a PID file or lock file then you could use incrond/incrontab to monitor the folder and write a timestamp when the file is create and when the file is deleted.

Alternatively a cron job that runs every minute and detects the process name from ps and write a timestamp and sets a flag when there's no process and writes a timestamp and sets a flag if it sees a process.

What schedules the runs of your backup? Could you write a wrapper around them to write your timestamps when they start/finish rather than using an external detection process?

Alternatively, do your backup jobs have log files that give the start/finish times, you could write a script to pull the start/finish information from each job log file in to a central log file and analyse that?

loadedmind 04-01-2016 08:46 AM

Unfortunately, the way Netvault handles log files is what I'd consider atypical. Their code creates binaries that are read by the nvgui Log program in /usr/netvault/logs/. But I think you might be on to something because, looking at those binaries, if I can cross-reference date/time with actual PID start/stop times, then they'd be accurate enough to use as a basis for metrics.


All times are GMT -5. The time now is 11:32 AM.