Script for ping on Background Process


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script for ping on Background Process
# 1  
Old 06-10-2008
Script for ping on Background Process

Hi All,
I'm doing one script on Juniper router where you have one FreeBSD Shell:
Is pinging from time to time one ethernet port of othere router and in case of fail is blocking one port entering in CLI and doing some command:
If I run this script all is working perfectly, but if I run in Backgroung using "&" is blocked on ping (ping -c1 $RemoteIPAddress) . Could you help me to solve this problem?

Many thanks
giancarlo


Code:
#!/bin/sh

# Name of Script that will be show in log file ##############################################################
ScriptName='CheckLinkScript_Ze2-NS2'
# Remote Interface IP Address ##############################################################
RemoteIPAddress="10.15.100.222"
# Local Port connected to Remote IP Address ##############################################################
LocalPort="fe-2/0/1.23"
# Variable used for show time on log file ##############################################################
RIGHT_NOW=$(date +"%x %r %Z")
# Time between ping to Remote IP Address ##############################################################
SleepingTime='3'
# When interface is down after RentryTime will be sut up and Attemp of ping will be performed ##############
RetryTime='1000'


subping ()
{
echo ---$RIGHT_NOW---$ScriptName---- PERFORMING LINK CHECK RemoteIP $RemoteIPAddress LocalPort $LocalPort -- >> /var/log/messages
ping -c1 $RemoteIPAddress
if [ $? -ne 0 ]

# when is down #################################################################################################### ##
then

echo ---$RIGHT_NOW---$ScriptName---- Remote IP address $RemoteIPAddress unreachable -- > /var/log/messages
echo ---$RIGHT_NOW---$ScriptName---- Shutting down port &LocalPort -- > /var/log/messages
cli <<END_SCRIPT
edit
set interfaces $LocalPort disable

# shut interface ####################################################################################################


commit
top
exit
exit
echo ---$RIGHT_NOW---$ScriptName---- Port &LocalPort Admin DOWN -- > /var/log/messages
END_SCRIPT

sleep $RetryTime

# after sleep try to put up interface and try again to ping ##########################################################

echo ---$RIGHT_NOW---$ScriptName---- Attempt to recover link on port &LocalPort -- > /var/log/messages
cli <<END_SCRIPT
edit
dele interfaces $LocalPort disable
commit
top
exit
exit
END_SCRIPT



# when is up #################################################################################################### #####
else
echo ---$RIGHT_NOW---$ScriptName---- LINK CHECK Performed RemoteIP $RemoteIPAddress : OK -- > /var/log/messages
fi
}


while [ true ]
do
subping

sleep $SleepingTime



done

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Make background process interact with fg process

Hi, I have written a menu driven shell script in which as per the choice, I run the another script on background. For eg: 1. get info 2)process info 3)modify info All the operations have different scripts which i schedule in background using &. However I wish to display the error... (0 Replies)
Discussion started by: ashima jain
0 Replies

2. Shell Programming and Scripting

Running Shell Script in the cron, background process

Hi, i was looking for an answer for some trouble im having runing a script in the cron, thing is, that when i run it manually it works just fine. But when cron runs it, it just doenst work. I saw a reply on a similar subject, suggesting that the . .profile worked for you, but im kind of... (9 Replies)
Discussion started by: blacksteel1988
9 Replies

3. Shell Programming and Scripting

How to put FTP process as a background process/job in perl?

Hi, I am using net::ftp for transferring files now i am trying in the same Linux server as a result ftp is very fast but if the server is other location (remote) then the file transferred will be time consuming. So i want try putting FTP part as a background process. I am unaware how to do... (5 Replies)
Discussion started by: vanitham
5 Replies

4. UNIX for Dummies Questions & Answers

Script to start background process and then kill process

What I need to learn is how to use a script that launches background processes, and then kills those processes as needed. The script successfully launches the script. But how do I check to see if the job exists before I kill it? I know my problem is mostly failure to understand parameter... (4 Replies)
Discussion started by: holocene
4 Replies

5. Shell Programming and Scripting

Background Process.

How to create a backgrond processes ? (5 Replies)
Discussion started by: anupdas
5 Replies

6. Shell Programming and Scripting

Background and Foreground of a process within a script

I'm not sure if it is even possible but I figured if it was someone here would know how to do it... I am running a script which starts a bunch of processes in the background but there is one process I would like to bring back to the foreground when complete. Unfortunately the process that I... (2 Replies)
Discussion started by: ctruhn
2 Replies

7. UNIX for Dummies Questions & Answers

PING to one host in one background process

Hi All, I'm doing one script on Juniper router where you have one FreeBSD Shell: Is pinging from time to time one ethernet port of othere router and in case of fail is blocking one port entering in CLI and doing some command: If I run this script all is working perfectly, but if I run in... (1 Reply)
Discussion started by: teigipo
1 Replies

8. Shell Programming and Scripting

facing problem in starting a process in background using shell script.

hey all, i am working on sun solaris machine and i want to start a process in background using shell script (actually i wanna start tomcat server using shell script). please dont tell me that append a & at last because this is not working in the shell script. i have also used nohup and... (8 Replies)
Discussion started by: dtomar
8 Replies

9. Shell Programming and Scripting

How to include RETURN KEY with Background process "&" in Shell Script

Hello All, I am a newbie in Shell script programming, and maybe you can help me with my query. I need to write a shell script (mntServer.ksh) that will start a background process and also to be able to run another script. The mntServer.ksh script contains: #!/bin/ksh... (1 Reply)
Discussion started by: racbern
1 Replies

10. Shell Programming and Scripting

capture the process id when starting a background process

Hello all, How do I start a background process and save the process id to a file on my system. For example %wait 5 & will execute and print the process id. I can't figure out how to get it to a file. I've tried: > filename 0>filename 1>filename. Any assistance is most appreciated. Thanks, Jim... (10 Replies)
Discussion started by: jleavitt
10 Replies
Login or Register to Ask a Question