simple while loop script to check a connection


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting simple while loop script to check a connection
# 8  
Old 10-09-2012
Quote:
Originally Posted by zippyzip
Hi pamu

Thanks for your help so far. Essentially if program A is running i want to continually send serial keepalives to the serial port..(something is scooping this output up fine) if the program fails i want the output to stop.. if the program resumes i want it to continue

Thanks

Zippy
1)Is it possible to edit Program A..? If yes then you can just call your second script from program A.

2)Second way is use crontab for your script that check your Program A stastus after some specific time.

3)Third way you can use your program second in infinite loop.(not good way of programming, but if you wish.)

Code:
while true
do
Program second code
done

Hope this helps you..Smilie
# 9  
Old 10-10-2012
Hi Pamu,

Tried the following in /etc/cron.minutely

Code:
#!/bin/bash CONNECTED=$(ps -ef | grep -c APP1) while [ "$CONNECTED" -gt 1 ]; do   echo -n p >/dev/ttyS1;   echo $CONNECTED   CONNECTED=$(ps -ef | grep -c APP1) done

it seemed to work but killed the CPU.. ran top and 0% idle.. and lots defunct instances of ps ( see below)..
Code:
top - 18:00:58 up  1:32,  1 user,  load average: 114.69, 112.65, 100.98
Tasks: 741 total, 155 running, 554 sleeping,   0 stopped,  32 zombie
Cpu(s): 34.4%us, 64.3%sy,  0.0%ni,  0.0%id,  0.0%wa,  0.0%hi,  1.2%si,  0.0%st
Mem:   2075060k total,   442024k used,  1633036k free,    27356k buffers
Swap:  1052248k total,        0k used,  1052248k free,   205168k cached

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND                                           
 7549 root      18   0     0    0    0 Z  1.3  0.0   0:00.05 ps <defunct>                                      
 7556 root      18   0     0    0    0 Z  1.3  0.0   0:00.05 ps <defunct>                                      
 7563 root      18   0     0    0    0 Z  1.3  0.0   0:00.05 ps <defunct>                                      
 7566 root      18   0     0    0    0 Z  1.3  0.0   0:00.05 ps <defunct>                                      
 7582 root      18   0     0    0    0 Z  1.3  0.0   0:00.05 ps <defunct>                                      
 7585 root      18   0     0    0    0 Z  1.3  0.0   0:00.05 ps <defunct>                                      
 7597 root      18   0     0    0    0 Z  1.3  0.0   0:00.05 ps <defunct>                                      
 7604 root      18   0     0    0    0 Z  1.3  0.0   0:00.05 ps <defunct>                                      
 7611 root      18   0     0    0    0 Z  1.3  0.0   0:00.05 ps <defunct>                                      
 7614 root      18   0     0    0    0 Z  1.3  0.0   0:00.05 ps <defunct>                                      
 7617 root      18   0     0    0    0 Z  1.3  0.0   0:00.05 ps <defunct>                                      
 7624 root      18   0     0    0    0 Z  1.3  0.0   0:00.05 ps <defunct>                                      
 7627 root      18   0     0    0    0 Z  1.3  0.0   0:00.05 ps <defunct>                                      
 7634 root      18   0     0    0    0 Z  1.3  0.0   0:00.05 ps <defunct>                                      
 7649 root      18   0     0    0    0 Z  1.3  0.0   0:00.05 ps <defunct>                                      
 7652 root      18   0     0    0    0 Z  1.3  0.0   0:00.05 ps <defunct>                                      
 7655 root      18   0     0    0    0 Z  1.3  0.0   0:00.05 ps <defunct>                                      
 7661 root      18   0     0    0    0 Z  1.3  0.0   0:00.05 ps <defunct>                                      
 7665 root      18   0     0    0    0 Z  1.3  0.0   0:00.05 ps <defunct>

Not sure whats wrong. Do you have any ideas?

Thanks

zippyzip

Moderator's Comments:
Mod Comment Please use code tags for code and data

Last edited by Scrutinizer; 10-10-2012 at 07:37 AM.. Reason: code tags
# 10  
Old 10-10-2012
you don't need while loop now...

just try with if

Code:
if [[ $(ps -ef | grep -c APP1) -gt 1]]
then
echo -n p >/dev/ttyS1
fi

that's what you need.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need Script to check the FTP connection

Hi, I need a script which check the FTP connections, if its working fine then no issue. Incase not working fine then Trigger the mail. Please help on this. Thanks (4 Replies)
Discussion started by: Keshav Kalra
4 Replies

2. Shell Programming and Scripting

[Solved] Simple script not working- for loop

Hi all, Please guide me writing this script Follwing is the file which I have created, which contains the files to be copied. cat system1-dr.txt /etc/passwd /etc/shadow /etc/group /etc/vfstab /etc/profile /etc/default/init /etc/shells /etc/dfs/dfstab /etc/dfs/sharetab... (11 Replies)
Discussion started by: manalisharmabe
11 Replies

3. Shell Programming and Scripting

Simple check login script

Hello, I just started with shell and i am doin simple script to check if certain user is logged in. Script takes 3 args. name sleep time and quit value if there is q for quit then date and user name is printed to file, not to screen. so far i have got this... login() { while :... (3 Replies)
Discussion started by: shelllo
3 Replies

4. Shell Programming and Scripting

Check the connectivity of the DB through script, exit if no connection

check the connectivity of the DBs through script, script should exit if no connection and display the output as below. connectivity for DB1 is OK connectivity for DB2 is OK connectivity for DB3 is FAILED for DB in 1 2 3 do (sqlplus -s... (5 Replies)
Discussion started by: only4satish
5 Replies

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

6. UNIX for Dummies Questions & Answers

simple script with while loop getting problem

Hello forum memebers. can you correct the simple while program. #! /bin/ksh count=10 while do echo $count count='expr$count-1' done I think it will print 10 to 1 numbers but it running for indefinite times. (2 Replies)
Discussion started by: rajkumar_g
2 Replies

7. Shell Programming and Scripting

Simple LOOP script help

I am trying to create a simple ksh loop script. What I've pasted below is not working. Any help is appreciated. typeset -i count typeset -i tcount count=0 tcount=0 while $tcount >= 11 do print "\$count is $count" pwd ls -l sleep 30 $(( $tcount = $count + 1 )) ... (5 Replies)
Discussion started by: musikman65
5 Replies

8. Shell Programming and Scripting

how to check DB connection in unix shell script

In the following script I need to find whether DB is established successfully or not. I need to find and display it. If <DB is connected successfully> then echo "DB connection success" else echo "DB connection failure" fi In the same way I need to do it for DB terminate. I don't... (1 Reply)
Discussion started by: kmanivan82
1 Replies

9. UNIX for Dummies Questions & Answers

Bash Script to check Remote Host Connection

Hi all, Can anyone tell/guide me how to check remote host is up/running using bash script? Thanks. Zulfiqar (5 Replies)
Discussion started by: zulfikarmd
5 Replies

10. Shell Programming and Scripting

Simple script loop question

Hey all. Thanks in advance for any help you can give, hopefully this is an easy one. I want to create a loop to run a simple performance monitor like vmstat and record it to a file, but have very limited scripting skills (obviously). Starting with this... date >> /var/log/perfmon.log vmstat... (2 Replies)
Discussion started by: mattlock73
2 Replies
Login or Register to Ask a Question