HOW TO Check for process ending?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting HOW TO Check for process ending?
# 1  
Old 07-20-2016
HOW TO Check for process ending?

Hello,
I'm new of this forum and have very very old and rusty memories of shell scripting (my latest script dates back to about 20 years ago !).

My need is following:
I'm testing a software that make a backup, but at now is not implemented the email report (the sw is in beta).
I'm trying to write a script the extract job result and send me an email.
My problem is to check when the job is finished, in order to grep job result and email it. In other words, until the job is running do nothing; when job is ended,
proceed with the script.

Thanks to those who want to help me.
Davide

This is the script:
------------------------------------------------------------------------
Code:
#!/bin/bash
#
# Script to run Veeam backup and email job status (BackupJob3)
#This is the backup command
veeamconfig job start --id {ba6434ea-55cc-4529-a9d3-69ec868769e9}
JOBNAME=BackupJob3
export JOBNAME
TODAY=$(date +"%Y-%m-%d")
export TODAY
# this to check id job is running or not
JOBRUNNING=`pgrep veeamjobman`
export JOBRUNNING
#Here I need to check and wait for job ending, but the while cycle is not working
while [ -z "$JOBRUNNING" ]
do
        echo "job is running" >> /tmp/test/out.txt
done
# this is to check if the job is failed or not
FAILED=`veeamconfig session list | grep -e Failed | grep $JOBNAME | grep $TODAY`
export FAILED
if [ -z "$FAILED" ]
then
        echo "Job $JOBNAME Successfull" | mailx -s "VAL session $JOBNAME Successfull" my@email.it
else
        echo "Job $JOBNAME Failed" | mailx -s "VAL session $JOBNAME Failed" my@email.it
fi

------------------------------------------------------------------------


Moderator's Comments:
Mod Comment Use code tags, thanks.

Last edited by dadep; 07-20-2016 at 06:24 AM..
# 2  
Old 07-20-2016
Not everybody (including me) is familiar with that backup tool. Please explain its behaviour: Does it do the backups itself, or does it send some job(s) into background? Does it start independent processes? Does it come back immediately after doing so?

The info "the while cycle is not working" is not necessarily something to work upon. Please supply way more detail: What doesn't work? How does it deviate from the expexted behaviour? Error messages?


Two comments to your above script:
- the -z checks for zero-length-strings; this might be the opposite of what you want?
- the while loop won't ever react on changing conditions unless you modify the conditions (i.e. the pgrep) INSIDE the loop.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script to check line end not ending with comma

I have several line in a text file. for example I like apple; I like apple I like orange; Output: I like apple I try to useif grep -q "!\;$"; then (Not work) Please use CODE tags when displaying sample input, sample output, and code segments (as required by forum rules). (1 Reply)
Discussion started by: cmdcmd
1 Replies

2. UNIX for Dummies Questions & Answers

How a process can check if a particular process is running on different machine?

I have process1 running on one machine and generating some log file. Now another process which can be launched on any machine wants to know if process1 is running or not and also in case it is running it wants to stream the logs file generated by process1 on terminal from which process2 is... (2 Replies)
Discussion started by: saurabhnsit2001
2 Replies

3. Shell Programming and Scripting

if statement to check files with different ending but same starting name

I am trying to check if files staring with filename but ending with diffent dates e.g. filename.2011-10-25. The code I am using is below if It works find only if one file is present but returns binary operator expected when there are mulptiple files. Please help me correcting it. I... (5 Replies)
Discussion started by: ningy
5 Replies

4. Programming

Perl regular expression to check string ending

Hi, I am trying to write a regular expression in perl to check if the string end's with "numbers-numbers" or "-numbers". I experimented something like m/\d*-\d*$/ , but this is not solving my problem. Can anyone help me in writing this expression? Well spelled titles and proper use of code... (2 Replies)
Discussion started by: successlin
2 Replies

5. Shell Programming and Scripting

Check process

Hi.. I have this code which tells me that if a process is running or not. Actually someone on this forum help me to do it. :) But now If i want to check if the process is not running for more than 10 minutes. Does anyone know the code or syntax that checks if a process is not running for some... (1 Reply)
Discussion started by: kanexxx
1 Replies

6. Shell Programming and Scripting

To execute next UNIX command after ending SFTP process.

Hi, I am trying to run a simple UNIX command after i successfully executed SFTP command as shown below. ----------------------------------------- echo 'Step-1' sftp -vvv -b path exit echo 'Step-2' ------------------------------------------ In above script it executes from the 1st... (3 Replies)
Discussion started by: gautamc
3 Replies

7. UNIX for Dummies Questions & Answers

Check the process

Except the command "top" , is there other function / tool is used to check the process status in the system like 1. what process are running ? 2. how the CPU are allocating ? 3. how many swap is using ? 4. " Thx. (1 Reply)
Discussion started by: ust
1 Replies

8. Shell Programming and Scripting

check the process

how to kill the process that are idle over 30 minutes ? thx (2 Replies)
Discussion started by: ust
2 Replies

9. UNIX for Advanced & Expert Users

Check the process

I want to find the pid ( by ps ) that has already run over 30 seconds , I know ps only show the minute/hour . eg. the start time of the below process are 15:19 / 15:20 , but I don't know the exact time ( in term of "second" ) it start to run ( I only know the hour and minute ) , if I want to... (2 Replies)
Discussion started by: ust
2 Replies

10. UNIX for Dummies Questions & Answers

process check

does anyone know an easy way that at the beginning of your script you check to see if that process is already running? I think it would have something to do with ps but I may be making it more complicated than it has to be. If you have a script run say, every half hour, you would want to check and... (13 Replies)
Discussion started by: k@ssidy
13 Replies
Login or Register to Ask a Question