Quote:
Originally Posted by psudo
Ive got a bash script put together and its not quite working. It is as follows:
#!/bin/sh
HOST="ftp.com"
USER="testuser"
PASSWD="secure_password"
FILE=/test.txt
ftp -n $HOST <<END_SCRIPT
quote USER $USER
quote PASS $PASSWD
cd target_directory
put $FILE
bye
END_SCRIPT
exit 0
To which I get the following output:
./ftp_upload.sh
Trying 99.99.99.99...
/test.txt: Error on output file.
When I test this script manually (Entering each command in turn) it works.
In new to scripting. I basically pulled this of the net and im not sure what is failing. Any thoughts?
|
as im still semi new to scripting, what are the quote USER for?
also here is a lftp script i have from a while back that works great. now it does not use a secure p/w because well its FTP
Code:
#!/bin/bash
startdate="`date +%Y-%m-%d-%a-%H.%M.%S`"
dow=`date +%A`
tarfilename=foo-${dow}
HOMEDIR="$HOME"
logname=${HOMEDIR}/logs/${startdate}-FTPBackup.log
enddate1="`date +%Y-%b-%d-%a-%H.%M.%S`"
url1=ftp.foo.com
# Change the NAS device's directory to where you want the files sent
############################################################
backdir1=disk1/some/place
LDIR=`pwd`
username=user
password=password
cd ${HOMEDIR}
lftp1()
{
if [ "${NO_KILL}" != "true" ]
then
lftp -e "set ftp:passive-mode on && cd ${backdir1} && put ${NEWTAR} && bye" -u ${username},${password} ${url1}
else
lftp -e "set ftp:passive-mode on && cd ${backdir1} && put /tmp/${tarfilename}.tar.bz2 && bye" -u ${username},${password} ${url1}
fi
}
TAR()
{
tar cvjf /tmp/${tarfilename}.tar.bz2 -X ${HOMEDIR}/excludes.conf ${HOMEDIR} >> ${logname}
}
checkTar ()
{
tar tfj /tmp/${tarfilename}.tar.bz2 &> /tmp/tar2; bzerr="$?"; echo $bzerr > /tmp/bz-check.list
echo "Verifying compressed data." | tee -a ${logname}
VERSTAT=`cat /tmp/bz-check.list`
if [ ${VERSTAT} -eq 0 ]
then
echo "Verification of compressed data was successfull." | tee -a ${logname}
else
echo "Compressed data appears to be corrupt. Error ${VERSTAT}." | tee -a ${logname}
exit 1
fi
echo "Encrypting ${tarfilename}.tar.bz2" | tee -a ${logname}
openssl des3 -a -salt -in /tmp/${tarfilename}.tar.bz2 -out /tmp/${tarfilename}.tar.bz2.enc -pass pass:somepasswordhere
echo "${tarfilename}.tar.bz2.enc Encrypted" | tee -a ${logname}
NEWTAR=/tmp/${tarfilename}.tar.bz2.enc
# to decrypt: openssl des3 -a -d -salt -in 2011-12-20.tar.bz2.enc -out 2011-12-20.tar.bz2 -pass pass:somepasswordhere
}
#Start the Ftp backup log
echo "AutoFTP backup script started ${startdate}" > $logname
### Checking for exclueds file, the adding file types to ignore
### make sure excludes.conf exists or tar command will blow up
### checks for and adds entries to excludes.conf
EXCLUDES=(
*.tar
*.tgz
*.bz2
*.bz
*.google*
*.mozilla*
*.openoffice*
*.DCOP*
*.adobe*
*.gconf*
*.gnome2*
*.mcop*
*.thumbnail
*.kde*
*Desktop*
)
EXCLUDENUM=${#EXCLUDES[@]}
echo $EXCLUDENUM
[ -f $HOME/excludes.conf ] || touch $HOME/excludes.conf
for ((i=0; i<$EXCLUDENUM; i++))
do
grep -w ${EXCLUDES[i]} excludes.conf
EXERR=$?
if [ $EXERR -eq 0 ]
then
echo "${EXCLUDES[i]} already in excludes.conf"
else
echo "adding ${EXCLUDES[i]} to excludes.conf" >>${logname}
echo "${EXCLUDES[i]}" >>excludes.conf
fi
done
### Code to clean up /tmp of old failed backups
#####################################
### The sed command will add a '- ' to the front of each of the
### lines in created in excludes.conf and put them in
### excludes.txt for the rsync command to use below.
if [ ! -f ${HOMEDIR}/excludes.txt ]
then
sed 's/^/- /' excludes.conf > excludes.txt
echo "Creating excludes.txt to be used by rsync." >> ${logname}
fi
### Cleaning up /tmp to prevent running out of storage space
#####################################
find /tmp/*.bz2 -mtime +2 -exec rm {} \;
### Call to create tarball
#######################################
echo "Compressing contents into backup file ${tarfilename}.tar.bz2" >> ${logname}
TAR
tarend="`date +%Y-%m-%d-%a-%H.%M.%S`"
echo "Backup tar file created ${tarend}" >> ${logname}
### Check and verify tarball then encrypt
#######################################
if [ "${NO_KILL}" != "true" ]
then
checkTar
fi
### Start the FTP transmission
#######################################
echo "Starting FTP1 transmission ${startdate}" >> ${logname}
lftp1
if [ $? -ne 0 ]
then
echo "FTP1 transmission failed" >> ${logname}
else
echo "FTP1 transmission complete to remote computer at ${url1}" >> $logname
fi
### Cleaning up tarballs
rm -rf /tmp/${tarfilename}.tar.bz2
rm -rf ${NEWTAR}
### Notes for e-mail
### yum install postfix
### cd /var/spool/postfix
### mkfifo pickup
### service postfix restart
### chkconfig postfix on ###this will set postfix to start on bootup###
### uncomment the following line to send e-mail everytime the script runs
# mailx -s "rsync backup log" <e-mail_addres@here.com> < $log
mailx -s "ftp logs ${license}" <e-mail_address@here.com> < ${logname}
echo "mailx -s "ftp logs ${license}" <e-mail_address@here.com < ${logname}" << ${logname}
exit;
that should help