Sponsored Content
Top Forums Shell Programming and Scripting My Script For Process Checking is NOT Working Post 302628811 by rymnd_12345 on Tuesday 24th of April 2012 03:54:39 AM
Old 04-24-2012
My Script For Process Checking is NOT Working

Hello there ULF,

Good day! Just want to share my code and as well as my problem on why I'm not getting the output that I want. My original code was:

Code:
#!/usr/bin/sh

echo
echo -n "Please input an IP-Pool: "
read ip
echo
echo "Please wait....."
/home/nsadm/scripts/IP-PoolSession-Checker/ip_checker1.sh $ip > temp_output
sleep 15
/home/nsadm/scripts/IP-PoolSession-Checker/ip_checker2.sh $ip | grep -v NOTE >> temp_output
sleep 1
cp temp_output final_output
pd1=`cat temp_output | awk 'NR==10 {print $3}'`
bd1=`cat temp_output | awk 'NR==11 {print $3}'`
pu1=`cat temp_output | awk 'NR==12 {print $3}'`
bu1=`cat temp_output | awk 'NR==13 {print $3}'`
pd2=`cat temp_output | awk 'NR==18 {print $3}'`
bd2=`cat temp_output | awk 'NR==19 {print $3}'`
pu2=`cat temp_output | awk 'NR==20 {print $3}'`
bu2=`cat temp_output | awk 'NR==21 {print $3}'`
pd=$(expr $pd2 - $pd1)
bd=$(expr $bd2 - $bd1)
pu=$(expr $pu2 - $pu1)
bu=$(expr $bu2 - $bu1)
echo >> final_output
echo "Delta Summary:" >> final_output
echo "==============" >> final_output
echo "Delta Pkts-Dwn: $pd" >> final_output
echo "Delta Bytes-Dwn: $bd" >> final_output
echo "Delta Pkts-Up: $pu" >> final_output
echo "Delta Bytes-Up: $bu" >> final_output
cat final_output
rm temp_output
rm final_output
echo

Now since this script can be used by other users, there will be a possibility of having simultaneous running-process for this script which will lead to a wrongly data to be parsed, so in order for this one not to happen, I want to check if the process is running it will prompt the user that it's not yet safe to run the script otherwise begin using it. So I've decided to put something like this into my code:
Code:
#!/usr/bin/sh

psef=`ps -ef | grep IP-PoolSession-Summary.sh | grep -v grep | wc -l`
if [ $psef -eq 1 ]; 
then
echo
echo -e "\033[41;37mSorry! Another user is currently running the script. Please try again later.\033[0m"
echo
exit
else
echo -n "Please input an IP-Pool: "
read ip
echo
echo "Please wait....."
/home/nsadm/scripts/IP-PoolSession-Checker/ip_checker1.sh $ip > temp_output
sleep 15
/home/nsadm/scripts/IP-PoolSession-Checker/ip_checker2.sh $ip | grep -v NOTE >> temp_output
sleep 1
cp temp_output final_output
pd1=`cat temp_output | awk 'NR==10 {print $3}'`
bd1=`cat temp_output | awk 'NR==11 {print $3}'`
pu1=`cat temp_output | awk 'NR==12 {print $3}'`
bu1=`cat temp_output | awk 'NR==13 {print $3}'`
pd2=`cat temp_output | awk 'NR==18 {print $3}'`
bd2=`cat temp_output | awk 'NR==19 {print $3}'`
pu2=`cat temp_output | awk 'NR==20 {print $3}'`
bu2=`cat temp_output | awk 'NR==21 {print $3}'`
pd=$(expr $pd2 - $pd1)
bd=$(expr $bd2 - $bd1)
pu=$(expr $pu2 - $pu1)
bu=$(expr $bu2 - $bu1)
echo >> final_output
echo "Delta Summary:" >> final_output
echo "==============" >> final_output
echo "Delta Pkts-Dwn: $pd" >> final_output
echo "Delta Bytes-Dwn: $bd" >> final_output
echo "Delta Pkts-Up: $pu" >> final_output
echo "Delta Bytes-Up: $bu" >> final_output
cat final_output
rm temp_output
rm final_output
echo
fi

The problem with this code is that it's not prompting the user and still continues and proceed with the original code (which is after the else function) even if I already ran one before running it again.

Then I've modified the if/else by doing something like this:
Code:
#!/usr/bin/sh

psef=`ps -ef | grep IP-PoolSession-Summary.sh | grep -v grep | wc -l`
if [ $psef -eq 1 ]; then
echo
echo -e "\033[41;37mSorry! Another user is currently running the script. Please try again later.\033[0m"
echo
exit
elif [ $psef -eq 0 ]; then
echo
echo -n "Please input an IP-Pool: "
read ip
echo
echo "Please wait....."
/home/nsadm/scripts/IP-PoolSession-Checker/ip_checker1.sh $ip > temp_output
sleep 15
/home/nsadm/scripts/IP-PoolSession-Checker/ip_checker2.sh $ip | grep -v NOTE >> temp_output
sleep 1
cp temp_output final_output
pd1=`cat temp_output | awk 'NR==10 {print $3}'`
bd1=`cat temp_output | awk 'NR==11 {print $3}'`
pu1=`cat temp_output | awk 'NR==12 {print $3}'`
bu1=`cat temp_output | awk 'NR==13 {print $3}'`
pd2=`cat temp_output | awk 'NR==18 {print $3}'`
bd2=`cat temp_output | awk 'NR==19 {print $3}'`
pu2=`cat temp_output | awk 'NR==20 {print $3}'`
bu2=`cat temp_output | awk 'NR==21 {print $3}'`
pd=$(expr $pd2 - $pd1)
bd=$(expr $bd2 - $bd1)
pu=$(expr $pu2 - $pu1)
bu=$(expr $bu2 - $bu1)
echo >> final_output
echo "Delta Summary:" >> final_output
echo "==============" >> final_output
echo "Delta Pkts-Dwn: $pd" >> final_output
echo "Delta Bytes-Dwn: $bd" >> final_output
echo "Delta Pkts-Up: $pu" >> final_output
echo "Delta Bytes-Up: $bu" >> final_output
cat final_output
rm temp_output
rm final_output
echo
fi

As you can see, I've just changed the if/else to if/elif, but again the output is that after executing the script, it automatically exits. No prompt appeared even.

Can you please help me with this problem? I'm working on a SUSE Linux.


Thanks and Best Regards,
rymnd_12345

Last edited by rymnd_12345; 04-24-2012 at 04:56 AM.. Reason: typo error
 

10 More Discussions You Might Find Interesting

1. HP-UX

checking process existed

On HP-UX, in application, if the process id has been get with the getpid() and sotred in database, then other monitor process want to check it if the process is existed, are there any system function can do it? I do not want to use the shell script, because it should use popen function to excuted... (5 Replies)
Discussion started by: Frank2004
5 Replies

2. Shell Programming and Scripting

Checking the cron process in unix

Hi Experts, Is there any command by which i can chk that the cron process is running fine? Say i have scheduled the cron to run at 10 o clock every monday,Do i need to wait for the time it runs and then chk using ps -ef? Please shed some light. Thanks Ashok. (2 Replies)
Discussion started by: Ashok_oct22
2 Replies

3. Shell Programming and Scripting

Checking for multiple instances of a process

Hi I have a scenario where i need to check multiple instances of a running shell script (abc.sh) . How can I find from inside a running shell script whether any other instance of the same script is running or not? If any other instance of same shell script is running I need to exit from... (4 Replies)
Discussion started by: raghu.amilineni
4 Replies

4. Shell Programming and Scripting

The checking of folder existance is not working...

Hi all, I have the following code: if ; then echo 'folder not exist'; else echo 'folder exist'; fi The "testing" folder is not exist in /home/batch , but thhe result is 'folder exist'. It seems that the code cannot detect that the folder "testing" not exist. ANybody know the... (1 Reply)
Discussion started by: suigion
1 Replies

5. Shell Programming and Scripting

Process checking loop

Hi, I want to create a script who will check if the java process is running & if it finds the process is still there it continues to execute & when the process completes it exit from the script. I have written a code to check & notify the process existence but i am not getting how to write... (4 Replies)
Discussion started by: d8011
4 Replies

6. Shell Programming and Scripting

block process checking

How can i check block process in Linux? If found any what action is required? How to check the pid of process? How to kill the block process? How to find out bottleneck process? (3 Replies)
Discussion started by: learnbash
3 Replies

7. AIX

Script Checking LVM Mirror not Working

Hi, I need to know who can I create an script in order to check server mirror in AIX. I got this script !/usr/bin/ksh # # Check if a VG is mirrored. # # lsattr -El <lvname> -a strictness -a copies # If copies=2 and scrictness=y, then VG is mirrored # # LVs are retrieved via 'lsvg -l... (5 Replies)
Discussion started by: fede_mont
5 Replies

8. Solaris

Python script not working in batch process

Good morning, I have a python 2.3 script that runs stand alone as intended when tested, then it was put into a ksh script. when running the ksh script it runs as intended. The problem is that my script does not run when the ksh script is called by another user who runs a batch process (as of right... (1 Reply)
Discussion started by: mhahe
1 Replies

9. Shell Programming and Scripting

Problem with a script for checking the state of a process

Hello Everyone, I have a process that should be always running. Unfortunately, this process is getting down almost every 10 minutes. I want to make a script that verify the state of this process: If the process is up, the script shouldn't do nothing and if it's down he should run it. Can... (3 Replies)
Discussion started by: adilyos
3 Replies

10. Shell Programming and Scripting

Checking DataPump Process

Hi All, I am writing script for Env refresh for Oracle DB. I am using Datapump for that. If i start expdp or impdp, how can i know that export or import has completed. I have query for that. How will i integrate with script?. Or any command i can run from Linux side. Please share you... (1 Reply)
Discussion started by: pvmanikandan
1 Replies
All times are GMT -4. The time now is 12:56 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy