Sponsored Content
Top Forums Shell Programming and Scripting How to restart shell script when cpu is 0.0%? Post 303032011 by baris35 on Saturday 9th of March 2019 09:19:17 AM
Old 03-09-2019
Thank You Don and Rudic,
So far, here is what I did:
Program name is cvlc as I am running under command line.
Code:
watch -n5 "ps aux -y | grep 'zoltan' | grep 'cvlc' | awk '{print \$4}'"

At the moment, there are two processes and the code gives:
Code:
0.2
0.2
0.0

Normally 0.0 at the bottom line is the program itself. I am working on how to take/read all output lines excluding the bottom one or assigning pid value to search in the result.


Quote:
A guess: You seem to want to terminate a process that doesn't do any work any more but doesn't quit. None of your commands in your code addresses that.
Yes, that's what I wish to do but you both say it's no good.

PS: At first, I could not have found any info regarding abbreviations, then coincidentally learnt the meaning of gt and lt Smilie
I am working on it..



Update:
Code:
ps aux | grep 'zoltan' | grep 'cvlc' | awk '{print $4}'
                if [ $? -eq 0.0 ]; then
echo "vlc is not running"
./restart.sh
else
echo "vlc is okay"
fi
exit 0

Output:
Code:
0.2
0.2
./check.sh: line 2: [: 0.0: integer expression expected
vlc is okay

Latest:
Code:
                ps aux | grep 'zoltan' | grep 'cvlc' | awk '{print $4}'
                if [ $? -eq 0 ]; then
                id=$(ps aux | grep 'zoltan' | grep 'cvlc' | awk '{print $2}')
echo "vlc is not running"
kill $id
./restart.sh
else
echo "vlc is okay"
fi
exit 0

Not-working process has been killed and restarted..


Sorted now:
Code:
                ps aux | grep 'zoltan' | grep 'cvlc' | awk '{print $4}'
                if [ $? -eq 0 ]; then
                id=$(ps aux | grep 'zoltan' | grep 'cvlc' | awk '{print $2}')
echo "vlc is not running"
ps -f -u zoltan | awk '{ for(i=8; i<=NF; ++i) printf $i""FS; print "" }' > rerun
kill $id
sleep 2
sed -i '1d' rerun
chmod 755 rerun
sed -i "s|/usr/bin/vlc|sudo -u zoltan /usr/bin/vlc|g" rerun
sed -i "s|$| >> output.log 2>&1 < /dev/null \&|g" rerun
./rerun
else
echo "vlc is okay"
fi
exit 0

When cpu 0.0%, it restarts related process.. I am sure you can make it with shorter commands but works though.

Boris

Last edited by baris35; 03-09-2019 at 11:52 AM.. Reason: updated
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

suspend/restart a process in shell script

Hi, I have a task that Im stuck on. I have an elementary script named 'myscript' that prints "the script is running" once a second. It runs for 27 seconds. I need to write a 2nd script that starts 'myscript' and takes a parameter '$1' for a number. my 2nd script then needs to pause myscript... (1 Reply)
Discussion started by: daneensign
1 Replies

2. Shell Programming and Scripting

need help: shell script to restart apache when no. of processes keeps growing

I need a shell script to kill apache and restart it, in case the number of processes keeps growing. The logic is like the below, but I don't know how to get the number and neither the syntax. Could somebody kindly help? if no_of_processes (ps ax ¦ grep httpd) > 200 then killall httpd... (14 Replies)
Discussion started by: _joshua_
14 Replies

3. HP-UX

how could I use shell script to determine which CPU structure

how could I use shell script to determine which CPU structure because I found that I compile my program under Itanium base that cannot run on the PA-RISC base but PA-RISC program can run on Itanium base i would like to use shell script to know which CPU structure it is,how could i do thanks (1 Reply)
Discussion started by: alert0919
1 Replies

4. Shell Programming and Scripting

Help on shell script conditional execution when CPU Idle > 60%

I need a shell script that will monitor a few conditions and not execute until the these conditions are met. The problem I'm having is that I can not perform a database snapshot (backup) of a sybaseIQ database unless the CPU Status Idle % is above 60% or the snapshot (backup) fails. If... (2 Replies)
Discussion started by: pancona99
2 Replies

5. Shell Programming and Scripting

Restart Logic for a Korn Shell Master Script

Hello All, I was wondering if someone can help me to develop restart logic for a Korn Shell program (a master script) that I am developing. The program is design to invoke a series of child processes (Korn Shell Scripts) whose function is to create a series of load files on a specified mount... (0 Replies)
Discussion started by: jonesdk5
0 Replies

6. UNIX for Advanced & Expert Users

Shell script to monitor cpu and VMstat, iostat

Hi , I am new to scripting. please help me out how to write a script to monitor cpu , vmstat, iostat in Redhat linux. we are doing the load test. Thanks in advance !!!! (1 Reply)
Discussion started by: saanvi
1 Replies

7. Shell Programming and Scripting

Restart debian server if one specific process has more than 10 seconds have high cpu load

Hi, could someone give me an example for a debian server script? I need to check a process if the process has a high cpu load (top). If yes the whole server needs to reboot. Thats it, nothing more. ;) Hope someone could help me. Regards woisch (2 Replies)
Discussion started by: woisch
2 Replies

8. Shell Programming and Scripting

Shell script to monitor process with high CPU

Hi, Linux redhat 5.5 I need to write a kshell script that shows all the process that consume 100% CPU (or more. strange but there are time that top shows higger value that 100) and they are active more than 5 minute. The top command shows all the relevat information: The PID of the cpu ,... (0 Replies)
Discussion started by: yoavbe
0 Replies

9. Shell Programming and Scripting

Shell script to calculate the max cpu usage from the main script

Hi All, I have a script which does report the cpu usuage, there are few output parameter/fields displayed from the script. My problem is I have monitor the output and decide which cpu number (column 2) has maximum value (column 6). Since the output is displayed/updated every seconds, it's very... (1 Reply)
Discussion started by: Optimus81
1 Replies

10. Shell Programming and Scripting

Help with Shell script that monitors CPU Usage

I'm a newbie to shell scripting, I was given this script to modify. This script that monitors when CPU Usage is too high based off the top command. The comparison is not working as it should. Its comparing a decimal to a regualar interger. When it send me an email, it send an email and ignores the... (21 Replies)
Discussion started by: mhannor
21 Replies
All times are GMT -4. The time now is 12:34 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy