Hey Guys,
I wonder if someone could help shed some light on the problems I'm having with my script.
I'm pretty new to BASH and have been learning loads lately, so I'm actually quite happy with how far I've come on my own, however I have a question..
I'll put my script below. So my question on most of it, is have I done it the 'right' way and could I have made it simpler? Or is there a nicer way of doing anything?
My second question is specifically with the GPG bit, although the password is stored in the file /root/.gpgpass - it still pops up and asks for the password if it's not run within a couple of hours.. almost like it's only caching the password and when it expires it requires human interaction. Is there another way of doing this without putting the password in plain text within the script and without any human interaction?
Code:
#!/bin/bash
#Declare the variables... change these as needed if the script is run on another server or the locations change.
HOST=ftp-server
USER=ftpxfer
PASS=pass
FILE=test.csv.gpg
FTPLOG=/tmp/ftplogfile
OUTPUT=/scripts/test.csv
ftp -inv $HOST <<! > $FTPLOG
quote USER $USER
quote PASS $PASS
get $FILE
bye
!
if fgrep "226 Transfer complete" $FTPLOG ; then
echo "FTP TRANSFER SUCCESS"
else
echo "FTP TRANSFER ERROR - Send email could go here."
fi
gpg --passphrase-file /root/.gpgpass --output $OUTPUT --decrypt $FILE
cp $OUTPUT /storage
exit 0