Afficher un message
Vieux 30/05/2007, 07h56   #1
mowgli
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Script for uploading files - use select or case?

I tried to make the following script to upload my backed up files to a
list of servers. Firstly, if I use continue to redisplay the list, I
get an error which says continue can only be used in while and until
loops.

Sorry that me being a newbie, it's not very clear to me yet when to
use select and when to use case.

Also what needs to be done if my username on one server is different
than on others? And also the ssh port for one server is different?


Here's the script:

#!/bin/bash
# Purpose: To upload my already backed up files to servers
# of my choice.

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

# Change default PS3 prompt
PS3='Select the server to upload backups to: '

# Set path to the files to upload
FILESPATH=~/backup/*.bz2
SERVER1=myserver1.example.com
SERVER2=myserver2.example.com
SERVER3=myserver3.example.com
SERVER4=myserver4.example.com
SERVER5=myserver5.example.com

select SERVER in $SERVER1 $SERVER2 $SERVER3
do
echo Now uploading files up files to $SERVER
scp $FILESPATH user@$SERVER:~/mybackup &>> $LOGFILE
continue

done




This is the same script but using case statements:


#!/bin/bash
FILESPATH=~/backup/*.bz2
SERVER1=myserver1.example.com
SERVER2=myserver2.example.com
SERVER3=myserver3.example.com
SERVER4=myserver4.example.com
SERVER5=myserver5.example.com

tput clear
tput bold
tput cup 20
echo "Please Select a server to upload the files to:"
echo 1. Server 1
echo 2. Server 2
echo 3. Server 3
echo 4. Server 4
echo 5. Server 5
echo 6. Exit

tput bold
read SERVER
case $SERVER in

1)
echo "Now uploading backed up files to Server 1"
#scp -P 22 $FILESPATH user@$SERVER:~/mybackup
;;

2)
echo "Now uploading backed up filed to Server 2"
#scp -P 22 $FILESPATH user@$SERVER:~/mybackup
;;

3)
echo "Now uploading backed up filed to Server 3"
#scp -P 22 $FILESPATH user@$SERVER:~/mybackup
;;

4)
echo "Now uploading backed up filed to Server 4"
#scp -P 22 $FILESPATH user@$SERVER:~/mybackup
;;

5)
echo "Now uploading backed up filed to Server 5"
#scp -P 22 $FILESPATH user@$SERVER:~/mybackup
;;

6)
exit 0
;;

*)
echo "You selected an invalid server. Please try again"
continue
;;
esac


Regards,
mowgli

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