Secure Copy Script
# # Remote Secure Copy # # # This will upload files to a remote node through ssh (encrypted tunnel). It's preatty simple, # just type "./rscopy [filename]" and your good to go, just be sure to edit the few perameters below. # ## ##
## CONFIGURATION ##
# Username of the host you want to connect to.
USER=username
# Remote host address.
HOSTNAME=hostname.foobar.com
# location of the remote system where you want your files to goto.
REMOTELOCATION=/home/username/
## END ##
## ##
###########################
# B E G I N S C R I P T #
###########################
ErrorCheck()
{
ERR=$?
if [ $ERR -gt 0 ]; then
echo "Error Code: "$ERR
exit 1
fi
}
if [ $# -lt 1 ]; then
echo "Usage: "$0 "[Filename]"
exit 1
fi
# Some checks before we start.
echo "===> Checking if files exists"
for file in $( echo $* ); do
if [ -f $file ]; then
echo $file >> temp.out
echo -n ". ";
else
echo ">>> Invalid File:" $file
exit 1
fi
done
FILES=`cat temp.out`
echo ""
echo "===> Checking for Secure Copy Program"
if [ -f /usr/bin/scp ]; then
export SECURECOPY=/usr/bin/scp
echo ">>> Found"
elif [ -f /usr/local/bin/scp ]; then
export SECURECOPY=/usr/local/bin/scp
echo ">>> Found"
else
echo ">>> Missing"
echo -n "Please enter the full path for scp --> "
read scp
echo ">> Checking ..." ; sleep 1 ; test -f $scp ; STERR=$?
export SECURECOPY=$scp
while [ $STERR -gt 0 ]; do
echo -n "Incorrect, Please re-enter the full path for scp --> "
read scp
echo ">> Checking ..." ; sleep 1 ; test -f $scp ; STERR=$?
export SECURECOPY=$scp
done
echo ">>> Found"
fi
# Let's try to make a connection here and copy the files over the the remote host.
echo "===> Starting transfer"
sleep 1
scp $FILES $USER@$HOSTNAME:$REMOTELOCATION
ErrorCheck
echo "===> Cleaning up temp files"
if [ -f temp.out ]; then
rm -f temp.out
fi
# # - Amram Bentolila # - amram@bsdcenter.com # - July 9/2001 # --
Amram Bentolila
|