Zwei Netzwerkkarten - wget befehl

Einrichten des lokalen Netzes, Verbindung zu anderen Computern und Diensten.
Antworten
Spike1986
Beiträge: 153
Registriert: 25.01.2012 20:16:47

Zwei Netzwerkkarten - wget befehl

Beitrag von Spike1986 » 18.06.2013 16:24:18

Habe ein debian wheezy server installiert. Dort sind zwei Netzwerkkarten drin.
Beide gehen zu einem Router und ins Internet. Kann auch vom Server aus auf beide Netze zugreifen. Jetzt geht es mir um ein Befehl der mir die IP abfrägt.

eth0 192.168.178.0 > Router 1.FB 192.168.178.1
eth1 192.168.1.0 > Router 2.FB 192.168.1.1

Code: Alles auswählen

wget -q --bind-address=`ifconfig "eth0" | grep 'inet addr:' | cut -d: -f2 | awk '{print $1}'` -O - http://myip.dnsomatic.com
wget -q --bind-address=`ifconfig "eth1" | grep 'inet addr:' | cut -d: -f2 | awk '{print $1}'` -O - http://myip.dnsomatic.com
sollten ja verschiedene IP's angezeigt werden. Leider klappt das nicht.

NetworkManager abgeschalten

Code: Alles auswählen

update-rc.d network-manager disable
/etc/network/interfaces

Code: Alles auswählen

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
allow-hotplug eth0
iface eth0 inet static
        address 192.168.178.3
        netmask 255.255.255.0
        network 192.168.178.0
        broadcast 192.168.178.255
        gateway 192.168.178.1
        # dns-* options are implemented by the resolvconf package, if installed
        dns-nameservers 192.168.178.1
        dns-search fritz.box

allow-hotplug eth1
iface eth1 inet static
        address 192.168.1.3
        netmask 255.255.255.0
        network 192.168.1.0
        broadcast 192.168.1.255
        gateway 192.168.1.1
        # dns-* options are implemented by the resolvconf package, if installed
        dns-nameservers 192.168.1.1
        dns-search fritz.box
ifconfig

Code: Alles auswählen

eth0      Link encap:Ethernet  Hardware Adresse 4c:72:b9:32:32:df  
          inet Adresse:192.168.178.3  Bcast:192.168.178.255  Maske:255.255.255.0
          inet6-Adresse: fe80::4e72:b9ff:fe32:32df/64 Gültigkeitsbereich:Verbindung
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metrik:1
          RX packets:125481 errors:0 dropped:0 overruns:0 frame:0
          TX packets:81154 errors:0 dropped:0 overruns:0 carrier:0
          Kollisionen:0 Sendewarteschlangenlänge:1000 
          RX bytes:171905554 (163.9 MiB)  TX bytes:6924648 (6.6 MiB)
          Interrupt:20 Speicher:f7d00000-f7d20000 

eth1      Link encap:Ethernet  Hardware Adresse 4c:72:b9:32:32:e0  
          inet Adresse:192.168.1.3  Bcast:192.168.1.255  Maske:255.255.255.0
          inet6-Adresse: fe80::4e72:b9ff:fe32:32e0/64 Gültigkeitsbereich:Verbindung
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metrik:1
          RX packets:256 errors:0 dropped:0 overruns:0 frame:0
          TX packets:317 errors:0 dropped:0 overruns:0 carrier:0
          Kollisionen:0 Sendewarteschlangenlänge:1000 
          RX bytes:122673 (119.7 KiB)  TX bytes:47278 (46.1 KiB)
          Interrupt:18 Speicher:f7c00000-f7c20000 

lo        Link encap:Lokale Schleife  
          inet Adresse:127.0.0.1  Maske:255.0.0.0
          inet6-Adresse: ::1/128 Gültigkeitsbereich:Maschine
          UP LOOPBACK RUNNING  MTU:16436  Metrik:1
          RX packets:89 errors:0 dropped:0 overruns:0 frame:0
          TX packets:89 errors:0 dropped:0 overruns:0 carrier:0
          Kollisionen:0 Sendewarteschlangenlänge:0 
          RX bytes:6919 (6.7 KiB)  TX bytes:6919 (6.7 KiB)
ip route

Code: Alles auswählen

default via 192.168.178.1 dev eth0 
192.168.1.0/24 dev eth1  proto kernel  scope link  src 192.168.1.3 
192.168.178.0/24 dev eth0  proto kernel  scope link  src 192.168.178.3 
habe ich was falsch eingestellt?
Zuletzt geändert von Spike1986 am 30.07.2013 19:04:52, insgesamt 2-mal geändert.

dufty
Beiträge: 378
Registriert: 21.09.2012 21:09:05

Re: Zwei Netzwerkkarten - wget befehl

Beitrag von dufty » 18.06.2013 17:49:59

Klar, klappt das nicht, Du grepst nach grep 'inet addr:',
hast aber dt. Locale, sprich in der Ausgabe von ifconfig erscheint "inet Adresse:".

Spike1986
Beiträge: 153
Registriert: 25.01.2012 20:16:47

Re: Zwei Netzwerkkarten - wget befehl

Beitrag von Spike1986 » 18.06.2013 18:13:19

Wie sollte der dann sonst heißen?
Den habe ich vom Internet, sollte bei denen funktioniert haben.

Danke schonmal

Spike1986
Beiträge: 153
Registriert: 25.01.2012 20:16:47

Re: Zwei Netzwerkkarten - wget befehl

Beitrag von Spike1986 » 18.06.2013 18:34:58

wget -q --bind-address=192.168.1.3 -O - http://myip.dnsomatic.com

befehl startet um kommt kein Ergebnis

wget -q --bind-address=192.168.178.3 -O - http://myip.dnsomatic.com

befehl startet und IP Adresse wird angezeigt - richtig.

dufty
Beiträge: 378
Registriert: 21.09.2012 21:09:05

Re: Zwei Netzwerkkarten - wget befehl

Beitrag von dufty » 18.06.2013 18:52:29

Zum einen

Code: Alles auswählen

wget -q --bind-address=`ifconfig "eth0" | grep 'inet Adresse:' | cut -d: -f2 | awk '{print $1}'` -O - http://myip.dnsomatic.com
zum anderen liegt Dein Defaultgateway auf eth0 ;-)

Spike1986
Beiträge: 153
Registriert: 25.01.2012 20:16:47

Re: Zwei Netzwerkkarten - wget befehl

Beitrag von Spike1986 » 18.06.2013 19:37:25

dufty hat geschrieben: zum anderen liegt Dein Defaultgateway auf eth0 ;-)
das war das Schlüsselwort.

Code: Alles auswählen

/etc/iproute2/rt_tables
#
# reserved values
#
255	local
254	main
253	default
0	unspec
#
# local
#
#1	inr.ruhep
1 rt2    # NEU HINZUGEFÜGT
Neue Routingtable hinzugefügt

Code: Alles auswählen

ip route add 192.168.1.0/24 dev eth1 src 192.168.1.2 table rt2
ip route add default via 192.168.1.1 dev eth1 table rt2
Routingregeln

Code: Alles auswählen

ip rule add from 192.168.1.2/32 table rt2
ip rule add to 192.168.1.2/32 table rt2
Und jetzt klappt alles wie es soll.
Damit alles beim neustart wieder funktioniert

Code: Alles auswählen

/etc/network/interfaces

iface eth1 inet static
        address 192.168.1.2
        netmask 255.255.255.0
        gateway 192.168.1.1
        broadcast 192.168.1.255
        dns-namenserver 192.168.1.1
    post-up ip route add 192.168.1.0/24 dev eth1 src 192.168.1.2 table rt2
    post-up ip route add default via 192.168.1.1 dev eth1 table rt2
    post-up ip rule add from 192.168.1.2/32 table rt2
    post-up ip rule add to 192.168.1.2/32 table rt2

Spike1986
Beiträge: 153
Registriert: 25.01.2012 20:16:47

Re: Zwei Netzwerkkarten - wget befehl

Beitrag von Spike1986 » 30.07.2013 19:13:33

ich brauch nochmal eure Hilfe.

So die Abfrage klappt ja jetzt wunder bar. Bin auf ein DDNSupdater script gestoßen.

Nur funktioniert nicht ganz das IP Update.

Code: Alles auswählen

#!/bin/bash
#
# DynamicDNSupdater - supports: DynDNS.org, NO-IP.com, DYNServ.ca and IPActive.de
#
# Es koennen auch verschiedene Dienste genutzt werden um mehrere DNS-Hosts zu nutzen...
#
# Sonderzeichen im Password werden nun auch supported (danke IDDQD)
#
# credits: Didge2002, SnowHead, r00t, rj.2001, IDDQD
#
### CONFIG - START

# Zugangsdaten...
# es koennen mehrere accounts geupdated werden... (rest auskommentieren)
USERNAME["1"]="capotest"	# DDNS Benutzername1
PASSWORD["1"]="test1"	# DDNS Passwort1
DDNSHOST["1"]="capotest.zapto.org"	# DDNS Hostname1

USERNAME["2"]="capotest"	# DDNS Benutzername2
PASSWORD["2"]="test1"	# DDNS Passwort2
DDNSHOST["2"]="capotest.dynvpn.de"	# DDNS Hostname2

#USERNAME["3"]="benutzer3"	# DDNS Benutzername3
#PASSWORD["3"]="password3"	# DDNS Passwort3
#DDNSHOST["3"]="host3.dyndns.org"	# DDNS Hostname3
#

# Provider URL's - pro DDNSHOST muss wie oben ein dazu passendes URL["<zahl>"] angelegt werden!
# (beliebig erweiterbar)
#
# $USERNAME , $PASSWORD , $DDNSHOST werden innerhalb der URL mit %USER% , %PASS% , %HOST% angegeben!
#
URL["2"]="http://%USER%:%PASS%@update.two-dns.de/update?hostname=%HOST%"
URL["1"]="http://dynupdate.no-ip.com/dns?username=%USER%&password=%PASS%&hostname=%HOST%"
URL["3"]="http://%USER%:%PASS%@members.dyndns.org/nic/update?hostname=%HOST%"
#
# BEISPIEL URL's
#
# DynDNS.org:		"http://%USER%:%PASS%@members.dyndns.org/nic/update?hostname=%HOST%"
# No-IP.com:		"http://dynupdate.no-ip.com/dns?username=%USER%&password=%PASS%&hostname=%HOST%"
# DYNServ.ca:		"http://dynserv.ca/dyn/dynengine.cgi?name=%USER%&pass=%PASS%&func=set&domain=%HOST%"
# IPActive.de:	"http://logon.ipactive.de/cgi-bin/logon_off.pl?V=2.1&B=%USER%&P=%PASS%&IP=%HOST%&F=1"
# two-dns.de:   "http://%USER%:%PASS%@update.two-dns.de/update?hostname=%HOST%"

EVERY="60"		# Zeit in Sekunden zwischen den Abfragen
LOG="1"			# Erstelle Logfile vom update? [0=nein; 1=ja]

# Verschicke EMail bei Problemen? [no=nein; yes=ja]
# ( benoetigt: apt-get install sendEmail )
EMAIL="yes"
EMAILFROM="a***e"
EMAILTO='D***m'
EMAILSERVER='m***e'
EMAILUSER='a***e'
EMAILPASS='X***1'

ETH='eth1'

### CONFIG - END

# -------------------------------------------------------------- #
# >>> >> >  DO NOT MESS WiTH ANYTHiNG BELOW THiS LiNE!  < << <<< #
# -------------------------------------------------------------- #


# required system cmd's:
# basename cat cut date echo expr killall ping rm sed sleep wget  

Osrcn="DDNSupdater2.sh"
srcn=$(basename $0)
srcv="2.251"
srccfg="config.$Osrcn"
LOGFILE="/var/log/log.$Osrcn"
CHKFILE="/tmp/.$Osrcn"
PiDFILE="/tmp/.pid.$Osrcn"
OnlinePing="google.de"
ProfileSwitchSleep=2
IPCcfgdir="/var/emu/conf"
IPCfunctions="/var/emu/script/functions.sh"
IPCddnssrc="/var/emu/script/$Osrcn"
IPCddnslinkname="ddns"

C="\033[";Ca="${C}0;33m";Cb="${C}1;33m";Cn="${C}0m";ROT="${C}1;31m";GRUEN="${C}1;32m";BOLD="${C}1;37m"
Bo="${C}1m";Bc="${C}21m"; Ro="${C}3m";Rc="${C}23m"; Uo="${C}4m";Uc="${C}24m"
Blo="${C}5m";Blc="${C}25m"; Io="${C}7m";Ic="${C}27m"

## Return Codes
declare -A ReturnCodes
ReturnCodes["good"]="DNS hostname update successful."
ReturnCodes["nochg"]="IP address is current, no update performed."
ReturnCodes["nohost"]="Hostname supplied does not exist under specified account."
ReturnCodes["badauth"]="Invalid username password combination."
ReturnCodes["badagent"]="The user agent was not sent or HTTP method is not permitted (we recommend use of GET request method)."
ReturnCodes["!donator"]="An option available only to credited users (such as offline URL) was specified, but the user is not a credited user."
ReturnCodes["abuse"]="The hostname specified is blocked for update abuse."
ReturnCodes["911"]="A fatal error on our side such as a database outage. Retry the update no sooner 30 minutes."
ReturnCodes["notfqdn"]="The hostname specified is not a fully-qualified domain name (not in the form hostname.dyndns.org or domain.com)."
ReturnCodes["0"]="IP address is current, no update performed."
ReturnCodes["1"]="Update successful."
ReturnCodes["2"]="Hostname supplied does not exist under specified account."
ReturnCodes["3"]="Invalid password."
ReturnCodes["4"]="Invalid username."

function AddonInstalled () {
	[ -f "/var/emu/conf/addons.info" ] && echo "ok" > /tmp/.AddonInstalled_$(basename $0)
}

function remove_addon () {
	#onlinescript als addon entfernen
	if [ -f "/var/emu/conf/addons.info" ]; then
		Anum=$(sed -ne "/^$(basename $0).*/=" /var/emu/conf/addons.info)
		[ ! -z "$Anum" ] && sed -i -e "$Anum d" /var/emu/conf/addons.info
	fi
}

if [ -f "$IPCfunctions" -a ! -f "/sbin/$IPCddnslinkname" ]; then
	echo ".. $srcn v$srcv .."
	echo "Erstbenutzung dieses Scripts? IPC erkannt... kopiere Script $srcn..."
	cp -f $0 $IPCddnssrc ; chmod 755 $IPCddnssrc >/dev/null 2>&1
	echo -e "\nErstelle Symlink fuer ${Ro}$IPCddnslinkname${Rc} auf $IPCddnssrc"
	ln -sf $IPCddnssrc /sbin/$IPCddnslinkname
	echo -e "Nun muss noch der ${Ro}CONFIG${Rc} Abschnitt in dem Script $srcn angepasst werden!"
	sleep 3
	nano -R $IPCddnssrc
	#[ ! -f "$IPCcfgdir/$srccfg" ] && proc_Create_Script_CFG "$IPCcfgdir/$srccfg"
	echo -e "Fertig! Das Script kann kuenftig ueber den Befehl ${Ro}$IPCddnslinkname${Rc} ausgefuehrt werden"
	AddonInstalled
	$IPCddnssrc help
	exit
fi

# load script config?
[ -d "$IPCcfgdir" -a -f "$IPCcfgdir/$srccfg" ] && source $IPCcfgdir/$srccfg
[ ! -d "$IPCcfgdir" -a -f "$srccfg" ] && source $srccfg

# Verschicke EMail..
function send_EMail() {
	MESSAGE=$1
	SUBJECT="$Osrcn"
	if [ $EMAIL = "yes" -o $EMAIL = "1" ]; then
		echo "Verschicke EMail.."
		sendEmail -f $EMAILFROM -t $EMAILTO -u "$SUBJECT" -m "$MESSAGE" -s $EMAILSERVER -xu "$EMAILUSER" -xp "$EMAILPASS"
	fi
}

# Simple URL encoding
function proc_url_encode() {
	out=${1//%/%25}; out=${out//\{/%7B}; out=${out//\}/%7D}; out=${out//|/%7C};
	out=${out//\\/%5C}; out=${out//^/%5E}; out=${out//~/%7E}; out=${out//[/%5B};
	out=${out//]/%5D}; out=${out//\`/%60}; out=${out//#/%23}; out=${out//>/%3E};
	out=${out//\$/%24}; out=${out//&/%26}; out=${out//+/%2B}; out=${out//,/%2C};
	out=${out//\//%2F}; out=${out//:/%3A}; out=${out//;/%3B}; out=${out//=/%3B};
	out=${out//\?/%3F}; out=${out// /%20}; out=${out//</%3C};
	out=${out//\!/%21}; out=${out//\"/%22}; out=${out//\@/%40}; out=${out//\'/%27};
	out=${out//\(/%28}; out=${out//\)/%29}; out=${out//\*/%2A}; out=${out//\-/%2D};
	out=${out//\_/%5F}; out=${out//\./%2E}; out=${out//\€/%80};
	echo $out
}

function LOG_msg() {
	message=$1
	if [ $LOG = "1" ]; then
		_DT=$(date +"%d.%m.%Y %H:%M:%S")
		echo "$_DT: $message" >> $LOGFILE
	fi
}

function ReturnCode () {
	for index in ${!ReturnCodes[*]}; do
		[ "$index" == "$1" ] && echo "${ReturnCodes[$1]}" && break
	done
}

function abuse_check() {
	index=$1
	answer=$(cat ${CHKFILE}_answer_$index)
	MSG=""
	if [ "$answer" = "abuse" ]; then
		MSG="WARNING!! You abused the DNS update function! You must Unlock your hostname: ${DDNSHOST[$index]} !"
	fi
	[ "$answer" = "nohost" ] && MSG="ERROR: Unknown host ${DDNSHOST[$index]} !"
	[ "$answer" = "badauth" ] && MSG="ERROR: Bad auth! Check USERNAME and PASSWORD setting for ${DDNSHOST[$index]} !"
	if [ ! -z "$MSG" ]; then
		echo "$MSG"
		LOG_msg "$MSG"
		send_EMail "$MSG"
	fi
}

function get_IPs() {
	CURRENTIP=""
	# get current internet ip
	CURRENTIP=$(wget -q --bind-address=`ifconfig "$ETH" | grep 'inet Adresse:' | cut -d: -f2 | awk '{print $1}'` -O - http://myip.dnsomatic.com)
    if [ -z "$CURRENTIP" -o "$CURRENTIP" = " *" -o "$CURRENTIP" = "*1.0 *" ]; then
        CURRENTIP=$(wget -q --bind-address=`ifconfig "$ETH" | grep 'inet Adresse:' | cut -d: -f2 | awk '{print $1}'` -O - http://my.ip.fi)
    fi
    if [ -z "$CURRENTIP" -o "$CURRENTIP" = " *" -o "$CURRENTIP" = "*1.0 *" ]; then
        CURRENTIP=$(wget -q --bind-address=`ifconfig "$ETH" | grep 'inet Adresse:' | cut -d: -f2 | awk '{print $1}'` -O - http://www.myip.ch | grep "IP Address" | cut -d ' ' -f4 | sed -e 's/\$//g' -e 's/\\r//g')
    fi
    if [ -z "$CURRENTIP" -o "$CURRENTIP" = " *" -o "$CURRENTIP" = "*1.0 *" ]; then
        CURRENTIP=$(wget -q --bind-address=`ifconfig "$ETH" | grep 'inet Adresse:' | cut -d: -f2 | awk '{print $1}'` -O - http://www.ip-lookup.de | grep -Eo '\<[[:digit:]]{1,3}(\.[[:digit:]]{1,3}){3}\>')
    fi
    if [ -z "$CURRENTIP" -o "$CURRENTIP" = " *" -o "$CURRENTIP" = "*1.0 *" ]; then
        CURRENTIP=$(wget -q --bind-address=`ifconfig "$ETH" | grep 'inet Adresse:' | cut -d: -f2 | awk '{print $1}'` -O - http://checkip.dyndns.org | sed s/[^0-9.]//g)
    fi
    if [ -z "$CURRENTIP" -o "$CURRENTIP" = " *" -o "$CURRENTIP" = "*1.0 *" ]; then
        CURRENTIP=$(wget -q --bind-address=`ifconfig "$ETH" | grep 'inet Adresse:' | cut -d: -f2 | awk '{print $1}'` -O - http://checkip.two-dns.de | grep "IP Address" | cut -d ' ' -f4 | sed -e 's/\$//g' -e 's/\\r//g')
    fi
	if [ -z "$CURRENTIP" ]; then
		eRROR["0"]="Cant get current internet ip"
	else
		# get current dyndns ip
		for index in ${!DDNSHOST[*]}; do
			#DYNIP[$index]=$(nslookup ${DDNSHOST[$index]} | tail -n2 | grep A | sed s/[^0-9.]//g)
			DYNIP[$index]=$(ping -c1 "${DDNSHOST[$index]}" | sed -n 1p | sed -e 's/(//g' -e 's/)//g' | cut -d " " -f3 | sed -e 's/\://g')
			[ -z "${DYNIP[$index]}" ] && eRROR[$index]="Cant get IP of DDNSHOST: ${DDNSHOST[$index]}"
		done	
	fi
}

# answer return codes: 1=ip.updated ; 3=wrong.pwd ; 4=wrong.username
function do_update() {
	index=$1
	# Replace %USER% , %PASS% , %HOST%
	URL=${URL[$index]}
	URL=${URL//%USER%/`proc_url_encode "${USERNAME[$index]}"`}
	URL=${URL//%PASS%/`proc_url_encode "${PASSWORD[$index]}"`}
	URL=${URL//%HOST%/${DDNSHOST[$index]}}
	wget -q -O ${CHKFILE}_answer_$index $URL
	answer=$(cat ${CHKFILE}_answer_$index)
	echo "DDNSHOST: ${DDNSHOST[$index]} - DYNIP: ${DYNIP[$index]} - CURRENTIP: $CURRENTIP - answer: $answer"
	LOG_msg "DDNSHOST: ${DDNSHOST[$index]} - DYNIP: ${DYNIP[$index]} - CURRENTIP: $CURRENTIP - answer: $answer"
}

# fuer jedes "profil" (DDNSHOST) die jeweilige "action" abarbeiten (function-names)
function check_profils() {
	ACTION=$1
	eRROR=""
	get_IPs
	for index in ${!DDNSHOST[*]}; do
		if [ -z "$eRROR" ]; then
			# for each $ACTION...
			if [ ! -z "$ACTION" ]; then
				for actionfunction in $ACTION; do
					$actionfunction "$index"
				done
			fi
		fi
		sleep $ProfileSwitchSleep
	done
	[ ! -z "$eRROR" ] && for Eidx in ${!eRROR[*]}; do echo "${eRROR[$Eidx]}"; done
}

function update_interval() {
	PiDs="$$ $!"
	echo $PiDs > $PiDFILE
	echo "Running Script in Background with PID(s): $PiDs"
	while true; do
		[ ! -f "$PiDFILE" ] && echo "$srcn: Interval stopped" && break
		# check if online...
		ONLINE=0
		[ "$(ping -c1 "$OnlinePing" | grep -c "seq")" -eq 1 ] && ONLINE=1
		# if online, check each DDNSHOST (array)...
		if [ "$ONLINE" ]; then
			get_IPs
			for index in ${!DDNSHOST[*]}; do
				[ "${DYNIP[$index]}" != "$CURRENTIP" ] && do_update "$index" && abuse_check "$index"
			done
		fi
		if [ ! -z "$eRROR" ]; then
			Error=""
			for Eidx in ${!eRROR[*]}; do
				Error="$Error ${eRROR[$Eidx]}\n"
			done
			echo -e "$Error" && LOG_msg "$Error" && send_EMail "$Error"
			eRROR=""
		fi
		sleep $EVERY
	done
}

function show_status() {
	get_IPs
	for index in ${!DDNSHOST[*]}; do
		if [ "${DYNIP[$index]}" != "$CURRENTIP" ]; then
			echo "The IP of ${DDNSHOST[$index]} (${DYNIP[$index]}) does NOT match your current Internet-IP: $CURRENTIP"
			echo "You should update immediately! (with: $0 now)"
		else
			echo "Your host ${DDNSHOST[$index]} with IP ${DYNIP[$index]} is still up to date: $CURRENTIP"
			if [ -f "${CHKFILE}_answer_$index" ]; then
				answer=$(cat ${CHKFILE}_answer_$index)
				echo -e "Last Answer was: $answer \t $(ReturnCode "$(echo $answer|sed -e s/.*://)")"
			fi
		fi
		echo " "
	done
	[ -f "$PiDFILE" ] && echo "Script seems to run in background with PID(s): $(cat $PiDFILE)"
}

function kill_script() {
	counter="5"
	[ -f "$PiDFILE" ] && PID=$(cat $PiDFILE)
	#[ -z "$PID" ] && PID="$$ $!"
	if [ ! -z "$PID" ]; then
		echo "PID(s): $PID"
		echo -n "Stopping Script"
		if ( kill -TERM $PID 2> /dev/null ); then
			c=1
			while [ "$c" -le 300 ]; do
				if ( kill -0 $PID 2> /dev/null ); then
					echo -n "."
					sleep 1
				else
					break
				fi
				c=$((++c))
			done
		fi
		if ( kill -0 $PID 2> /dev/null ); then
			echo -e "\rScript is not shutting down cleanly - killing"
			kill -KILL $PID
		else
			echo " done"
		fi
		#for P in $PID; do
		#	kill -9 $P >/dev/null 2>&1
		#	echo "Killed PID $P"
		#done
		killall -9 $IPCddnslinkname $srcn >/dev/null 2>&1
	else
		echo "Nothing to $1!"
	fi
	rm -f $PiDFILE
}

function echo_PIDs() {
	[ -f "$PiDFILE" ] && PID=$(cat $PiDFILE)
	[ -z "$PID" ] && PID="$$ $!"
	if [ -z "$PID" ]; then
		echo "Seems script isnt running in background"
	else
		echo "Scripts currently ProcessIDs: $PID"
	fi
}


if [ -f "$IPCfunctions" -a -f "$IPCddnssrc" ]; then
	linkname=$IPCddnslinkname
else
	linkname=$0
fi

case "$1" in
	"")
		update_interval &
	;;
	[aA][uU][tT][oO]|[sS][tT][aA][rR][tT])
		bash $0 & >/dev/null 2>&1
	;;
	[kK][iI][lL][lL]|[sS][tT][oO][pP])
		kill_script $1
	;;
	[nN][oO][wW])
		check_profils "do_update abuse_check"
	;;
	[pP][iI][dD]*)
		echo_PIDs
	;;
	[sS][tT][aA][tT][uU][sS])
		show_status
	;;
	[hH][eE][lL][pP]|[hH][iI][lL][fF][eE]|?)
		echo "Usage: $linkname [now|auto|kill|status|pid|help]"
		echo "$linkname now -> Force to update DDNSHOST immediately (erzwinge sofortiges updaten von DDNSHOST)"
		echo "$linkname auto -> Checks/updates DDNSHOST every $EVERY seconds (Ueberprueft/updated DDNSHOST alle $EVERY Sekunden)"
		echo "$linkname kill -> Kills running script (Script wird beendet)"
		echo "$linkname status -> Show current DDNSHOSTs status (Zeigt den aktuellen Status, ob ein update noetig ist)"
		echo "$linkname pid -> Show Process IDs (Zeigt die verwendeten ProzessIDs dieses Scripts)"
		echo "$linkname deinstall -> Deinstalls Script (Deinstalliert das Script)"
		echo "$linkname help -> This help... (Zeigt diese Hilfe...)"
	;;
	[dD][eE][iI][nN][sS]*)
		kill_script $1
		rm -f $IPCddnssrc /sbin/$IPCddnslinkname
		remove_addon
		echo "Script deinstalled!"
	;;
	*)
		echo "Usage: $linkname [now|auto|kill|status|pid|help]"
	;;
esac

exit 0
ich startet das script "DDNSupdater2.sh now"

Code: Alles auswählen

DDNSHOST: capotest.zapto.org - DYNIP: 87.79.144.222 - CURRENTIP: 84.124.242.136 - answer: capotest.zapto.org:0
DDNSHOST: capotest.dynvpn.de - DYNIP: 87.79.144.222 - CURRENTIP: 84.124.242.136 - answer: good 87.79.144.222
eth0 ip = 87.79.144.222
eth1 ip = 84.124.242.136

die von eth1 will ich updaten. mit CURRENTIP fragt das Script schon mal die richtige IP an. Aber Updatet die nicht.

Antworten