[prev in list] [next in list] [prev in thread] [next in thread]
List: suse-blinux-d
Subject: Re: [suse-blinux-d] wvdial on demand script
From: Christian Schoepplein <schoeppi () suse ! de>
Date: 2002-08-20 14:23:33
[Download RAW message or body]
Hi Dietmar!
On Die, Aug 20, 2002 at 05:48:00 +0100, Dietmar Segbert wrote:
>
> hier das Script aus der Suse-Supportdatenbank:
Jau, kommt schon wider zurück und hängt als Attachment an der Mail, sollte
jetzt hoffentlich gehen. Der Fehler lag nicht in der case-Anweisung am
Ende sondern schon in der Funktion davor:
MESSAGE="starting pppd $PPPPDPARAMS connect "
/usr/bin/wvdial --chat $WVPARAMS
Das stand alles in einer Zeile und konnte deshalb nicht gut gehen. Auch
das "..." danach (ich glaube so was war's, konnte so nicht gehen.
Probier's aus und berichte obs jetzt dann geht, leider kann ich selbst
mangels wvdial das Ganze hier nicht testen.
> Was bedeutet der Befehl "log" im script?
"log" ist eine eigene Funktion im Skript:
function log() {
# logs the messages to system log
HEAD=$0[$$]
echo $MESSAGE
logger -t $HEAD "$MESSAGE"
}
Diese funktion logt über syslog, der durch das externe Programm logger
aufgerufen wird, das momentan aktive Programm / Skript dessen Name in $0
gespeichert ist und dessen aktueller Prozess-ID die in $$ aufgehoben
ist und einen angehängten String der in $message geschrieben ist in die
Datei /var/log/messages. Davor wird noch der String, der in $message
steht, ganz normal am Bildschirm ausgegeben. Du kannst so über irgendeine
Zuweisung an $message an jeder Stele im Skript einen String in $message
schreiben und diesen dann loggen lassen. Ist eigentlich ganz praktisch
;-).
Ciao,
Schöppi
--
SuSE-Blinux Support
Christian Schöpplein <schoeppi@suse.de>
Tel.: Di. und Do. 15.00 - 20.00 Uhr 0421/526-2480
www: http://www.blinux.suse.de
["wvdialskript.sh" (application/x-sh)]
#!/bin/bash
#
# Copyright (c) 1999 SuSE GmbH Nuernberg, Germany. All rights reserved.
#
#
# parameters
# start section section section
# restart section section section
# start or restart the daemon with parameters found in /etc/wvdial.conf
# section is the name of a section in the /etc/wvdial.conf file
# (see man wvdial)
# stop
# stop the pppd
# hangup # hang up the telephone line
# additional Parameters in /etc/wvdial.conf could be
# Idle: sets the idle-time for waiting before hang up (deafult 180s)
# Remote IP: remote IP-address (default 192.168.99.99)
# Local IP: local IP-address (default 192.168.99.1)
# Defaultroute: no: pppd will not set the default route to the remote ip
# (default yes)
function log() {
# logs the messages to system log
HEAD=$0[$$]
echo $MESSAGE
logger -t $HEAD "$MESSAGE"
}
function setpppdparam() {
# time to sleep for pppd to come up
WAITFORPPPD=2
CONFFILE="/etc/wvdial.conf"
TMPFILE="/tmp/wvdial.dod.tmp"
# extract subsection
cat /etc/wvdial.conf | sed -n "/Dialer.*$SECTION/{:x;p;n;/Dialer/q;bx}" > $TMPFILE
VALUE=`cat $TMPFILE | grep "Modem" | cut -f2 -d"="`
if [ ! -z "$VALUE" ]; then Modem=$VALUE; fi
VALUE=`cat $TMPFILE | grep "Baud" | cut -f2 -d"="`
if [ ! -z "$VALUE" ]; then Baud=$VALUE; fi
VALUE=`cat $TMPFILE | grep "Username" | cut -f2 -d"="`
if [ ! -z "$VALUE" ]; then Username=$VALUE; fi
VALUE=`cat $TMPFILE | grep "Remote IP" | cut -f2 -d"="`
if [ ! -z "$VALUE" ]; then Remote_IP=$VALUE; fi
VALUE=`cat $TMPFILE | grep "Local IP" | cut -f2 -d"="`
if [ ! -z "$VALUE" ]; then Local_IP=$VALUE; fi
VALUE=`cat $TMPFILE | grep "Idle" | cut -f2 -d"="`
if [ ! -z "$VALUE" ]; then Idle=$VALUE; fi
VALUE=`cat $TMPFILE | grep "Defaultroute" | cut -f2 -d"="`
if [ X$VALUE = XNo -o X$VALUE = XNO -o X$VALUE = Xno ]; \
then DEFAULTROUTE="nodefaultroute";
fi
rm -f $TMPFILE
}
function killpppd() {
if [ -e $PIDFILE ]; then
MESSAGE="killing pppd process "
PID=`cat $PIDFILE`
MESSAGE=$MESSAGE"PID=$PID"
log
kill -15 $PID 2>/dev/null
#kill -9 $PID 2>/dev/null
rm $PIDFILE
fi
}
function startpppd() {
# set defaults, no defaults for Username, Modem, Baud
Local_IP="192.168.99.1"
Remote_IP="192.168.99.99"
Idle=360
DEFAULTROUTE="defaultroute"
# get params from section "Dialer Default"
SECTION=Defaults
setpppdparam
# parse given section ([Dailer xxx]) parameters
while [ ! -z $1 ]; do
SECTION=$1
setpppdparam
shift
done
# start pppd in demand mode
PPPPDPARAMS="$Local_IP:$Remote_IP $Modem $Baud modem crtscts $DEFAULTROUTE
-detach user $Username ipcp-accept-local ipcp-accept-remote call wvdial
demand idle $Idle"
MESSAGE="starting pppd $PPPPDPARAMS connect "
/usr/bin/wvdial --chat $WVPARAMS
pppd $PPPPDPARAMS connect "/usr/bin/wvdial --chat $WVPARAMS" &>/dev/null &
PPPDPID=$!
echo $PPPDPID > $PIDFILE
MESSAGE=$MESSAGE"PID=$PPPDPID"
log
# setting dynamic - parameter for ppp - device
# waiting pppd to come up
sleep $WAITFORPPPD
ls /var/run/ppp?.pid | while read PIDFILE ; do
if [ X$PPPDPID = X`cat $PIDFILE` ]; then
DEVICE=`echo $PIDFILE | cut -c 10-13`
MESSAGE="setting $DEVICE dynamic"
ifconfig $DEVICE dynamic
ifconfig $DEVICE | grep "DYNAMIC" -q
RES=$?
if [ $RES -gt 0 ] ; then
MESSAGE=$MESSAGE"failed"
exit 1
fi
MESSAGE=$MESSAGE"done"
log
fi
done
exit 0
}
LINKNAME=dod
PIDFILE=/var/run/pppd.$LINKNAME.pid
ACTION=$1
shift
WVPARAMS=$@
case "$ACTION" in
start)
# make sure to start even when uncleanly stopped
killpppd
netstat --inet -p
startpppd $@
netstat --inet -p
;;
stop)
# handle stop
killpppd
exit 0
;;
reload|restart)
killpppd
startpppd $@
;;
hangup)
if [ -e $PIDFILE ] ; then
MESSAGE="hangup pppd connection"
PID=`cat $PIDFILE`
MESSAGE=$MESSAGE"PID=$PID"
log
kill -SIGHUP $PID #2>/dev/null
exit 0
fi
MESSAGE="no pppd connection"
log
exit 1
;;
*)
echo "Usage: /sbin/init.d/wvdial.dod {start [section [section [..]]] | hangup | stop | restart}"
exit 1
;;
esac
--
Um sich von der Liste abzumelden schreiben Sie bitte eine Mail an die
Adresse, die im Kopf hinter dem List-Unsubscribe-Eintrag zu finden ist.
Um eine Liste aller verf=FCgbaren Kommandos zu bekommen, schicken
Sie eine Mail an:
suse-blinux-d-help@suse.com
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic