Sponsored Content
Top Forums Shell Programming and Scripting How to add conditional check of whether a process is running before doing rest of script? Post 302854087 by nbsparks on Monday 16th of September 2013 05:38:09 PM
Old 09-16-2013
OK... So I've never done anything like that before...

Here's the script I have that I want to modify.
Code:
#!/bin/bash

echo Overviewer Starting... >>/home/mcmaps/scripts/overviewer.log
date >>/home/mcmaps/scripts/overviewer.log
echo ------------------------- >>/home/mcmaps/scripts/overviewer.log
overviewer.py --verbose --quiet --processes 1 --config=/home/mcmaps/servers/bukkitpvt/overviewer.conf >>/home/mcmaps/scripts/overviewer.log
echo ------------------------- >>/home/mcmaps/scripts/overviewer.log
echo Overviewer Complete >>/home/mcmaps/scripts/overviewer.log
echo ============================================ >>/home/mcmaps/scripts/overviewer.log

An example of the log it creates:
Code:
============================================
Overviewer Starting...
Mon Sep 16 13:57:52 PDT 2013
-------------------------
overviewer.py:290  12313 2013-09-16 13:57:52 INFO     Welcome to Minecraft Overviewer!
observer.py:105    12313 2013-09-16 13:59:37 INFO     Rendered 0 of 0.  100% complete
observer.py:97     12313 2013-09-16 13:59:37 INFO     Rendered 0 of 0.  100% complete
-------------------------
Overviewer Complete
============================================
Overviewer Starting...
Mon Sep 16 14:10:45 PDT 2013
-------------------------
overviewer.py:290  13681 2013-09-16 14:10:45 INFO     Welcome to Minecraft Overviewer!
observer.py:105    13681 2013-09-16 14:12:31 INFO     Rendered 0 of 1808.  0% complete
observer.py:105    13681 2013-09-16 14:12:33 INFO     Rendered 11 of 1808.  0% complete
observer.py:105    13681 2013-09-16 14:12:35 INFO     Rendered 22 of 1808.  1% complete
observer.py:105    13681 2013-09-16 14:12:36 INFO     Rendered 33 of 1808.  1% complete
observer.py:105    13681 2013-09-16 14:12:37 INFO     Rendered 44 of 1808.  2% complete
observer.py:105    13681 2013-09-16 14:12:38 INFO     Rendered 55 of 1808.  3% complete
observer.py:105    13681 2013-09-16 14:12:39 INFO     Rendered 66 of 1808.  3% complete
observer.py:105    13681 2013-09-16 14:12:40 INFO     Rendered 77 of 1808.  4% complete
observer.py:105    13681 2013-09-16 14:12:42 INFO     Rendered 88 of 1808.  4% complete
observer.py:105    13681 2013-09-16 14:12:43 INFO     Rendered 99 of 1808.  5% complete
observer.py:105    13681 2013-09-16 14:12:48 INFO     Rendered 150 of 1808.  8% complete
observer.py:105    13681 2013-09-16 14:12:57 INFO     Rendered 201 of 1808.  11% complete
observer.py:105    13681 2013-09-16 14:13:08 INFO     Rendered 252 of 1808.  13% complete
observer.py:105    13681 2013-09-16 14:13:17 INFO     Rendered 303 of 1808.  16% complete
observer.py:105    13681 2013-09-16 14:13:27 INFO     Rendered 354 of 1808.  19% complete
observer.py:105    13681 2013-09-16 14:13:40 INFO     Rendered 405 of 1808.  22% complete
observer.py:105    13681 2013-09-16 14:13:49 INFO     Rendered 456 of 1808.  25% complete
observer.py:105    13681 2013-09-16 14:14:07 INFO     Rendered 557 of 1808.  30% complete
observer.py:105    13681 2013-09-16 14:14:26 INFO     Rendered 658 of 1808.  36% complete
observer.py:105    13681 2013-09-16 14:14:45 INFO     Rendered 759 of 1808.  41% complete
observer.py:105    13681 2013-09-16 14:15:07 INFO     Rendered 860 of 1808.  47% complete
observer.py:105    13681 2013-09-16 14:15:24 INFO     Rendered 961 of 1808.  53% complete
observer.py:105    13681 2013-09-16 14:15:43 INFO     Rendered 1062 of 1808.  58% complete
observer.py:105    13681 2013-09-16 14:16:05 INFO     Rendered 1163 of 1808.  64% complete
observer.py:105    13681 2013-09-16 14:16:24 INFO     Rendered 1264 of 1808.  69% complete
observer.py:105    13681 2013-09-16 14:16:43 INFO     Rendered 1365 of 1808.  75% complete
observer.py:105    13681 2013-09-16 14:17:04 INFO     Rendered 1466 of 1808.  81% complete
observer.py:105    13681 2013-09-16 14:17:33 INFO     Rendered 1567 of 1808.  86% complete
observer.py:105    13681 2013-09-16 14:17:59 INFO     Rendered 1668 of 1808.  92% complete
observer.py:105    13681 2013-09-16 14:18:21 INFO     Rendered 1769 of 1808.  97% complete
observer.py:97     13681 2013-09-16 14:18:28 INFO     Rendered 1808 of 1808.  100% complete
-------------------------
Overviewer Complete
============================================

What I see if I run it again and then view "top" in another terminal session.
Code:
  PID USER      PR  NI  VIRT  RES  SHR S  %CPU %MEM    TIME+  COMMAND
15228 mcmaps    20   0  115m  33m 5080 R 100.1  0.9   0:06.94 overviewer.py

But the PID changes each time I run the script. So how would I know what to store (PID wise) in "/var/run/processname.pid" and how would I know what to look for?

Totally lost. Sorry. :-(
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

script to check for a particular process and alert if its not running

Hai Friends, I have to develop a script that checks for a particular process say x.exe once every day and report if its not running say through a blat mail. I need this to run in a given list of pc from a single point. Any suggestion of how to go abt this Thnx for any help (1 Reply)
Discussion started by: goks
1 Replies

2. UNIX for Advanced & Expert Users

how to check if a process is running in a server from shell script.

I want to write a unix shell script that will check if a process (say debu) is running in the server or not. If no , then send a mail to the corresponding person to start the process??? (2 Replies)
Discussion started by: debu
2 Replies

3. Shell Programming and Scripting

script to check if process is running

How do I make a shell script to see if a certain process is running. The process shows up on ps aux as /usr/sbin/daemon eg: if /usr/sbin/daemon else #nothin basically i want to run the process if it isnt running/ has been stopped. Thanks. (2 Replies)
Discussion started by: daydreamer
2 Replies

4. Shell Programming and Scripting

How to write an expect script to check if a process is running?

I'm new to expecting and i want to create a script to ssh to a device,check is a process is running and display that the process is running or not.This is what i have so far After executing this script i get an error. #!/usr/bin/expect set timeout -1 set ip "machine ip goes here" set... (5 Replies)
Discussion started by: icchi
5 Replies

5. Programming

How do I check if a process is running in C

How to I check if a process is running in C? I'm trying to use ps aux |grep "process name" but failing in doing that. How do I do that? Thanks, (1 Reply)
Discussion started by: cprogdude
1 Replies

6. Shell Programming and Scripting

Script to check running of process

Hi, Can anyone please tell me how to write a shell script to check whether a process if running or not.... if its still running then wait for sometime and if not then run the next query. Also, Under my one main script main.sh I have to run 2 scripts simutaneously which take some time to... (2 Replies)
Discussion started by: lovepujain
2 Replies

7. Shell Programming and Scripting

Simple Script to Check running Process

#!/bin/sh CHECK='ps aux | grep start.jar | grep -v grep | wc -l' if then /usr/local/jre-1.7.0/bin/java - jar start.jar & else fi Could anybody advise whats up with this code im trying to put this in as a cron job to check that solr search engine is running every 10secs and if... (10 Replies)
Discussion started by: will_123
10 Replies

8. 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

9. Shell Programming and Scripting

ksh script to check if certain process is running

I have to kill the process "test" for a maintenance I do but want the script to check when it comes back up. I can get what I want when I run this while loop: while true;do ps -ef | grep test | grep -v grep | sed -e 's/^*//';sleep 60;done but I want the script to do it for me and as soon as... (6 Replies)
Discussion started by: seekryts15
6 Replies

10. Web Development

Javascript to check field is empty then execute rest of script

I have found this bit of code that nearly does what I want. Basically 3 input fields, I want to copy t2 to t3 as it's typed but only if t1 contains data AND t3 is empty: <input type="text" id="t1" /> <input type="text" id="t2" /> <input type="text" id="t3" /> <script> var t2 =... (4 Replies)
Discussion started by: barrydocks
4 Replies
All times are GMT -4. The time now is 05:17 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy