Avatar of enthuguy
enthuguyFlag for Australia

asked on 

Check if script is still running in bash

Hi Friends,

Have a script which invoke same shell script with different argument in background (usually runs couple of hours)

In above scenarios,
1. would like to check if all the above script execution has finished or not
2. In a loop with sleep/interval?
3. Once all finished, call a function and exit

I dont want to use sleep which increases the overall time for some reason in the script. Instead would like to use grep and check in a loop. pls help what is the best way to achieve this

e.g
ps -ef | grep  backgroundDummyProc | grep -v grep
if [ $? -eq 1 ]
then
    echo "Not running"
else
      echo "running"
fi

Thanks in advance
JavaShell ScriptingLinuxUnix OS

Avatar of undefined
Last Comment
enthuguy
Avatar of arnold
arnold
Flag of United States of America image

Do you want those scripts to run in the background? Run them sequentially and the calling script will wait until the other completes before proceeding.

Without sleep, use a counter I.e. A for loop counting till 10000 between the ps check.

While
Ps
Check status, break out of loop if condition met
For counter
Done
Avatar of enthuguy
enthuguy
Flag of Australia image

ASKER

thx arnold

Run this in background as well
sample script pls

Just wondering what if it goes beyond 10000
ASKER CERTIFIED SOLUTION
Avatar of arnold
arnold
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of arnold
arnold
Flag of United States of America image

What are you after?
You have tasks that a script of yours trigger by cron scheduling or Anacron scheduling, etc.
And you want the same or aseparate script to report on when the scripts it triggers complete?
Avatar of enthuguy
enthuguy
Flag of Australia image

ASKER

Thanks very much
Java
Java

Java is a platform-independent, object-oriented programming language and run-time environment, designed to have as few implementation dependencies as possible such that developers can write one set of code across all platforms using libraries. Most devices will not run Java natively, and require a run-time component to be installed in order to execute a Java program.

102K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo