Sed - letztes Vorkommen eines Strings

Also das funktioniert super. Habe ein weiteres Script geschrieben, dass dieses Script auf Server kopiert, ausführt und anschließend wieder löscht.
Dieses Script wird in der Bourne-Shell (sh) ausgeführt.
Das OS ist ein Solaris x86 Serversystem. Die Anzahl der Server sind ca. 60 und es hat alles super funktioniert. Mein Code den ich hereingestellt habe ist ja auch nur ein Teil des Scriptes.

Hier mal das komplette Script:

{noformat}

#!/bin/sh
#
###############
# Autor : Sebastian Kachel
# Mail : sebastian.kachel@xxxx.com
# Datum : 24.02.2010
# Skriptname : edit_resolv.conf
# Version : 1.0
###############

# Abfrage ob Datei vorhanden ist und die Bearbeitung der resolv.conf
#
# Variablen:
#NS_SERVER="111.11.11.1"
NS2_SERVER="222.22.22.2"
NS3_SERVER="333.33.33.3"
NS3_SERVER_ALL="nameserver 333.33.33.3"
RESOLV_CONF="/etc/resolv.conf"
DATE="`date +"%Y%m%d"`"
IFNS3="`grep -c "333.33.33.3" /etc/resolv.conf`"
AUSGABE_TAIL="`cat "${RESOLV_CONF}" | grep "nameserver" | tail -1`"

if [ -f ${RESOLV_CONF} ] ; then
cp ${RESOLV_CONF} ${RESOLV_CONF}.$DATE
sed s/${NS2_SERVER}/${NS3_SERVER}/g ${RESOLV_CONF}.$DATE > ${RESOLV_CONF}
cat ${RESOLV_CONF}
echo "..................................................................."

if [ "${IFNS3}" -gt "0" ] ; then
echo "${RESOLV_CONF} already done..............................."

else
cat /etc/resolv.conf | sed "/${AUSGABE_TAIL}/G" | sed "s/^$/nameserver 333.33.33.3/" > ${RESOLV_CONF}
cat ${RESOLV_CONF}
echo "${RESOLV_CONF} already done..............................."
fi



fi
{noformat}


Und das Script das Anhand einer Serverliste sich auf die Server über ssh einloggt und dann das Script (OBEN) kopiert, ausführt und wieder löscht.

{noformat}

#!/bin/ksh
#
###############
# Autor : Sebastian Kachel
# Mail : sebastian.kachel@xxx.com
# Datum : 10.02.2010
# Skriptname : verteiler.sh
# Version : 1.0
###############
#
#Script, dass ein Script, auf der Auswahl einer Serverliste
#auf Server kopiert, ausführt und wieder löscht.
#
#Variablen:
SERVER=$SERVER" "`cat ~/Serverlists/SOLARIS`

[ $# -eq 1 ] && SERVER=$1

for server in $SERVER ; do
ping "$server" 1 > /dev/null
ping "$server" 1 > /dev/null
ping "$server" 1 > /dev/null

if [ "$?" = "0" ]; then
echo "$server"
scp /xxx/xx/xxxxxxx/edit_resolv_conf.sh root@${server}:/var/tmp/edit_resolv_conf.sh
ssh root@${server} "sh /var/tmp/edit_resolv_conf.sh"
ssh root@${server} "rm /var/tmp/edit_resolv_conf.sh"
else
echo "...$server is dead."
fi
done


{noformat}


Aus Sicherheitsgründen sind IP und Phade durch xxx ersetzt ;-)


Nochmls einen großen Dank an euch . Echt klasse !

Liebe Grüße
OnePixel
 
Also das funktioniert super.
Das scheint dann aber eine etwas unübliche Verhaltensweise der SunOS Bourne Shell zu sein.
http://snap.nlc.dcccd.edu/learn/madden/intro/common/redirect.html hat gesagt.:
Standard Output

There are two output redirection operators in UNIX.

1. date > myfile

redirects the output of a process (date) to the file specified after the metacharacter, in this case, myfile. Two significant things happen when this type of redirection is used: First, UNIX looks to see if the file specified already exists. If it does, then the next byte pointer (NBP) in the file is set to byte zero. That means the contents of the file are instantly, absolutely, totally, and irrevocably lost.

For example, this code shows the fastest cat possible:

cat myfile > myfile

When the shell starts to execute this command, it first does file handling, and sees the redirection. Since the first thing it does when a file is the target of a redirection is to set the next byte pointer to byte zero, the file "myfile" suddenly becomes very, very empty. Cating an empty file is pretty quick!
Und bitte fasse deine Codeschnipsel in [code]...[/code] Tags ein!

Gruß
 
Zurück