[bglug] [Era Un Aiutino] Script per automatizzare ftp/telnet
tHEbREV
bglug@lists.linux.it
Thu, 20 Mar 2003 01:41:01 -0800 (PST)
--0-830196219-1048153261=:5128
Content-Type: text/plain; charset=us-ascii
Content-Id:
Content-Disposition: inline
Gli script sono questi.
Ovviamente la cosa può essere molto affinata, ma per
quello che dovevo fare per ora è andato tutto bene su
un centinaio di macchine, che ovviamente so a priori
essere funzionanti ed attive.
Se date un occhio alla gestione errori fa veramente
schifo. I comandi telnet impartiti tramite la funzione
cmd escono sempre con un exit status=1 che ovviamente
per il sistema è un codice di errore, anche se le
operazioni sono state eseguite in modo corretto.
Per il file .netrc da includere nella home vi rimando
alla pagina man dell'ftp.
Se avete suggerimenti sono più che bene accetti.
Saluti.
__________________________________________________
Do you Yahoo!?
Yahoo! Platinum - Watch CBS' NCAA March Madness, live on your desktop!
http://platinum.yahoo.com
--0-830196219-1048153261=:5128
Content-Type: text/plain; name="connect.sh"
Content-Description: connect.sh
Content-Disposition: inline; filename="connect.sh"
#!/bin/bash
# connect.sh
#######################################################################
# ShellScript: connect.sh - connect,create user,copy file,extract file
# Author : Claudio Ciseria (claudio.ciseria@dalmineenergie.it
# Date : 19-03-2003
# Category : File Transfer
# Version : 1.0
#######################################################################
#######################################################################
# Changes:
# - ip included from a source file ip-data
#
#######################################################################
# Source of ip list
. ip-data
# Define exit status 65 for error during connection
WRONG_EXIT="65"
# 'cmd' function: print command during telnet session and define the
# sleep time to wait for next command.
function cmd {
echo "$1"
sleep $2
}
# Begin for loop for every ip in $ip.
for ip in $IP
do
# 1st telnet session: create the default user 'devel'.
echo "Tentativo di connessione Telnet a 172.31.100.$ip"
(
sleep 5
cmd 'cubeuser' 1
cmd 'cubeuser' 3
cmd 'su -' 3
cmd '' 3
cmd 'adduser prova' 1
cmd 'prova' 2
cmd 'prova' 2
)|telnet 172.31.100.$ip
# If the exit code equal 1 we're done.
if [ $? -eq 1 ]
then
echo
echo "Default user succesfully created..."
echo
else
echo
echo "Default user creation failed..."
echo
exit $WRONG_EXIT
fi
# Ftp session: execute command passed by ftp.cmd file.
# See 'man ftp' for more.
echo "Tentativo di connessione ftp a 172.31.100.$ip"
if ftp -i 172.31.100.$ip<ftp.cmd
then
echo
echo "Ftp command on $ip done succesfully..."
echo
else
echo
echo "Ftp command on $ip failed..."
echo
exit $WRONG_EXIT
fi
# 2nd telnet session: extract the configuration file.
echo "Tentativo di connessione telnet a 172.31.100.$ip"
(
sleep 5
cmd 'prova' 1
cmd 'prova' 3
cmd 'su' 3
cmd '' 3
cmd 'ls' 3
) | telnet 172.31.100.$ip
# If the exit code equal 1 we're done.
if [ $? -eq 1 ]
then
echo
echo "Telnet session on $ip done succesfully..."
echo
else
echo
echo "Telnet command on $ip failed..."
echo
exit $WRONG_EXIT
fi
# End of for loop.
done
# All done. Exit with code 0.
exit 0
--0-830196219-1048153261=:5128
Content-Type: application/octet-stream; name="ftp.cmd"
Content-Transfer-Encoding: base64
Content-Description: ftp.cmd
Content-Disposition: attachment; filename="ftp.cmd"
YmluDQpwdXQgbWdldHR5LnRneg0K
--0-830196219-1048153261=:5128
Content-Type: text/plain; name=ip-data
Content-Description: ip-data
Content-Disposition: inline; filename=ip-data
IP="1
2
3
4
5"
--0-830196219-1048153261=:5128--