Afficher un message
Vieux 02/06/2007, 01h59   #4
mowgli
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Script for uploading files - use select or case?

On May 31, 3:44 pm, Brian Mac <mcnamarabr...@gmail.com> wrote:
Thanks Brian for clarification.

> if you would like to back up a list of files to all servers in a set,
> i would recommend using a for loop. you would be able to have the
> same command run against all three machines. your statement would
> need to be more complex than might be required for a simple for loop
> to account for the differences in machine - you could set different
> variables based upon the machine that is current in the iteration.
> this is where the case statement might come in handy.


I changed the script to this and it's working except in case
connection to one of the server fails:

#!/bin/bash

# Set logfile
LOGFILE=~/backup/`date +%d-%b-%y_%I-%M`.log

# Bold and centered output on screen
#clear
tput bold
#tput cup 5

# Set path to backup files
FILESPATH=~/backup/*.bz2

# Define servers
SERVER1=myserver1.example.com
SERVER2=myserver2.example.com
SERVER3=myserver3.example.com
SERVER4=myserver4.example.com
#SERVER5=myserver5.example.com # Currently down

for SERVER in $SERVER1 $SERVER3 $SERVER4 $SERVER5
do

if [ $SERVER = $SERVER4 ]
then
echo "Now uploading files to $SERVER ..."
echo
scp $FILESPATH user123@$SERVER:~/backup 2>>$LOGFILE
elif
[ $SERVER = $SERVER5 ]
then
echo "Now uploading to $SERVER ..."
echo
scp -P 700 $FILESPATH user456@$SERVER:~/
backup 2>> $LOGFILE
else
echo "Now uploading files to $SERVER ..."
echo
scp $FILESPATH user@$SERVER:~/backup 2>>
$LOGFILE
fi
done

> if, however, you would like a menu-driven interface to select one
> machine to back up files to, you might want to use the select loop
> that uses a case statement as a body. here is a sample (works in korn
> shell so may need to be modified):


This is what I needed I think.

Regards,
mowgli


  Réponse avec citation
 
Page generated in 0,06134 seconds with 9 queries