Linux / UNIX Tech Support Forum
This is a discussion on Shell script to reconnect when PPP / DSL interface goes down within the Shell scripting forums, part of the Development/Scripting category; Hello,, I need script which prompt me when net is dc on my server. regards...
|
|||||||
| Shell scripting You can discuss the shell scripting, request shell scripts and scripting techniques |
![]() |
|
|
LinkBack | Thread Tools | Display Modes |
| Sponsored Links | ||
|
|
|
||||
|
What is dc?
How do you connect to Internet?
__________________
Vivek Gite Linux Evangelist |
|
||||
|
You can ping to remote site and if ping failed you can reconnect. For example:
Code:
#!/bin/bash
# add ip / hostname separated by while space
HOSTS="yourwebsite.com"
# no ping request
COUNT=1
# email report when
for myHost in $HOSTS
do
count=$(ping -c $COUNT $myHost | grep 'received' | awk -F',' '{ print $2 }' | awk '{ print $1 }')
if [ $count -eq 0 ]; then
# 100% failed
# Call script or command below to reconnect
# add your command below
fi
done
__________________
Vivek Gite Linux Evangelist |
|
||||
|
Hi,
This is part of script i use: Code:
#!/bin/bash
#set -x
dnsbroken=`ping -c1nqW5 -s8 www.yahoo.ca 2>&1 | grep -e "unknown" -e "denied" -e "permited"`
if [ -n "$dnsbroken" ]
then
# reconnect the connection
poff -a
pon dsl-provider
sleep 3
fi
# get current ip on ppp0
x=`/sbin/ifconfig ppp0`
y=${x#*inet addr:}
y=${y%% *}
# log current ip
echo $y > /home/ali/scripts/adsl_ip
exit 0
You can run this every 3 - 5 minutes via cron (as root). You can report the date, time and new ip address of machine as you like. change the hostname (Yahoo! Canada), log path (/home/ali/scripts/adsl_ip) and your connection name (dsl-provider), then run. |
![]() |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) |
|
| Thread Tools | |
| Display Modes | |
|
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| [Solved] Shell script for ftp the file | vishal_titre | Shell scripting | 4 | 21-08-2009 03:50 PM |
| Run mv command from ftp shell script | subin | Shell scripting | 6 | 02-05-2008 09:44 AM |
| writing a shell script to find out my shell name | jaymob123 | Shell scripting | 1 | 08-10-2007 12:36 AM |
| require shell script | puppen | Shell scripting | 4 | 12-04-2006 09:42 PM |
| Shell Script dought | Mahesh | Shell scripting | 3 | 16-02-2005 12:13 PM |