ich habe mir zwei Scripte für die bash geschrieben, die mir in diversen .htaccess-Dateien die IP-Adressen von den zutrittsberechtigten Usern ändern. Nun möchte ich die zwei Scripte zu einem Script verschmelzen/verbinden, jedoch komme ich nicht weiter und bräuchte ein wenig Hilfe.
Zum besseren Verständnis Packe ich die zwei Scripte mal hier rein.
ipupdaterv4.sh
Code: Alles auswählen
#!/bin/bash
WORKER_DIR="/tmp/ipupdater"
LASTIPFILE=$WORKER_DIR/lastip
LOGFILE=/var/log/ip.log
LASTIP=`/bin/cat $LASTIPFILE`
NEWIP=`/bin/cat /home/ipupdater/lastip`
TIME_START=`date +%s`
if [ ! -e $WORKER_DIR ]; then
mkdir $WORKER_DIR; fi
if [ ! -e $LASTIPFILE ]; then
echo "NoIpSavedYet" > $LASTIPFILE; fi
if [ $NEWIP != $LASTIP ]; then
cp /var/www/vhost1/.htaccess $WORKER_DIR/tmp1
sed "s/$LASTIP/$NEWIP/g" $WORKER_DIR/tmp1 > $WORKER_DIR/tmp2
mv $WORKER_DIR/tmp2 /var/www/vhost1/.htaccess
chown www-data:www-data /var/www/vhost1/.htaccess
rm -f $WORKER_DIR/tmp1
rm -f $WORKER_DIR/tmp2
sleep 1
cp /var/www/vhost2/.htaccess $WORKER_DIR/tmp1
sed "s/$LASTIP/$NEWIP/g" $WORKER_DIR/tmp1 > $WORKER_DIR/tmp2
mv $WORKER_DIR/tmp2 /var/www/vhost2/.htaccess
chown www-data:www-data /var/www/vhost2/.htaccess
rm -f $WORKER_DIR/tmp1
rm -f $WORKER_DIR/tmp2
echo `/bin/date +"%d.%m.%Y - %H:%M:%S"` IP: $NEWIP >> $LOGFILE
echo $NEWIP > $LASTIPFILE
fi
#echo "NEWIP: $NEWIP"
#echo "LASTIP: $LASTIP"
TIME_END=`date +%s`
logger -p local1.info -t ipupdaterv4.sh "ipupdaterv4.sh executed in $((TIME_END - $TIME_START)) seconds."
exit 0
Code: Alles auswählen
#!/bin/bash
WORKER_DIR="/tmp/ipupdater"
LASTIPFILEv6=$WORKER_DIR/lastipv6
LOGFILEv6=/var/log/ipv6.log
LASTIPv6=`/bin/cat $LASTIPFILEv6`
NEWIPv6=`/bin/cat /home/ipupdater/lastipv6`
TIME_START=`date +%s`
if [ ! -e $WORKER_DIR ]; then
mkdir $WORKER_DIR; fi
if [ ! -e $LASTIPFILE ]; then
echo "NoIpSavedYet" > $LASTIPFILEv6; fi
if [ $NEWIPv6 != $LASTIPv6 ]; then
cp /var/www/vhost1/.htaccess $WORKER_DIR/tmp1
sed "s/$LASTIPv6/$NEWIPv6/g" $WORKER_DIR/tmp1 > $WORKER_DIR/tmp2
mv $WORKER_DIR/tmp2 /var/www/vhost1/.htaccess
chown www-data:www-data /var/www/vhost1/.htaccess
rm -f $WORKER_DIR/tmp1
rm -f $WORKER_DIR/tmp2
sleep 1
cp /var/www/vhost2/.htaccess $WORKER_DIR/tmp1
sed "s/$LASTIPv6/$NEWIPv6/g" $WORKER_DIR/tmp1 > $WORKER_DIR/tmp2
mv $WORKER_DIR/tmp2 /var/www/vhost2/.htaccess
chown www-data:www-data /var/www/vhost2/.htaccess
rm -f $WORKER_DIR/tmp1
rm -f $WORKER_DIR/tmp2
echo `/bin/date +"%d.%m.%Y - %H:%M:%S"` IP: $NEWIPv6 >> $LOGFILEv6
echo $NEWIPv6 > $LASTIPFILEv6
fi
#echo "NEWIPv6: $NEWIPv6"
#echo "LASTIPv6: $LASTIPv6"
TIME_END=`date +%s`
logger -p local1.info -t ipupdaterv6.sh "ipupdaterv6.sh executed in $((TIME_END - $TIME_START)) seconds."
exit 0
Code: Alles auswählen
if [ $NEWIP != $LASTIP ] || [ $NEWIPv6 != $LASTIPv6 ]; then
Ich sage schon einmal Danke für alle Anregungen oder Vorschläge und bitte gleichzeitig um Nachsicht, da ich Anfänger bin.
LG Sven