LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   help aout error script? (http://www.linuxquestions.org/questions/programming-9/help-aout-error-script-351108/)

ice99 08-08-2005 07:31 AM

help aout error script?
 
ok here is the problem...
with script that i have created i can copy folders fro one server to another, and the script is working ok...

but when i try to copy a folder who is not on that server the script is exiting and report error...how can i make the script to tell me that there is no folder with such name on server when i try to copy nonexisting name...just to report an error not to exit...

here is some example:


#!/bin/bash
echo -n "Enter the name from which server you are copying :"
read SOURCE
#if [ "$SOURCE" != "" ]
#then
#echo "There is no folder with name $SOURCE!"
#else
echo -n "Enter the name from which server do you like to paste the copy :"
fi
read DESTINATION

rsync -Waq /vservers/$SOURCE/ /vservers/$DESTINATION/

echo "The copying between servers was successful completed !"
thanks in advance!!!

keefaz 08-08-2005 07:38 AM

Try :
Code:

if [ -z "$SOURCE" ]; then
    echo 'operation cancelled: the user has pressed enter key'
    echo 'without giving a source directory'
    exit 1
fi
if [ ! -d  "/vservers/$SOURCE" ]; then
    echo "operation cancelled : the directory /vservers/$SOURCE does not exist"
    exit 1
fi


ice99 08-08-2005 07:42 AM

Quote:

Originally posted by keefaz
Try :
Code:

if [ -z "$SOURCE" ]; then
    echo 'operation cancelled: the user has pressed enter key'
    echo 'without giving a source directory'
    exit 1
fi
if [ ! -d  "$SOURCE" ]; then
    echo "operation cancelled : the directory $SOURCE does not exist"
    exit 1
fi


ok byt now with this code i can't copy also those directories who is on the server....

keefaz 08-08-2005 07:44 AM

My bad
 
I forget to use the full path to $SOURCE directory, see the edited post

ice99 08-08-2005 07:48 AM

Re: My bad
 
Quote:

Originally posted by keefaz
I forget to use the full path to $SOURCE directory, see the edited post

THANKS MAN YOU ARE THE BEST! :)


All times are GMT -5. The time now is 06:35 AM.