I would like to process a directory listing from a ftp server. At the end of the day I would like to delete old files on the ftp server, but I'm not there yet. I have problems to interpret the lines from the directory listing. I'm a newbie in shell scripts, so please be patient. It´s probably a very basic mistake I've made....
You find the piece of code below and the printout when I run this script.
#!/bin/bash
# LOCAL/FTP/SCP/MAIL PARAMETERS
SERVER="xxx.yyy.zzz" # IP of NAS, used for ftp
USERNAME="joe" # FTP username of Network disk used for ftp
PASSWORD="joe1234" # FTP password of Network disk used for ftp
DESTDIR="/opt/backup" # used for temorarily storage
DESTDIRNAS="/sdb1/domoticz_backup/A/" # Path to your NAS backup folder
DOMO_IP="192.168.0.243" # Domoticz IP
DOMO_PORT="8085" # Domoticz port # get directory listing from remote source
putdir=$DESTDIRNAS
ftp -n $SERVER > /tmp/dirlist <<END_SCRIPT
quote USER $USERNAME
quote PASS $PASSWORD
cd $putdir
ls -l
quit
END_SCRIPT
cat /tmp/dirlist | while read LINE; do
echo $LINE
awk '{print $9}' $(LINE)
done;
The output is as follows:
pi@raspberrypi:~ $ ./test.sh
-rwxrwxrwx 1 0 0 229632 Oct 09 07:27 domoticz_20171009092723.db.gz
./test.sh: line 23: LINE: command not found
domoticz_20171009105333.db.gz
domoticz_20171009111940.db.gz
domoticz_20171009113716.db.gz
domoticz_scripts_20171009105333.tar.gz
domoticz_scripts_20171009111940.tar.gz
domoticz_scripts_20171009113716.tar.gz
pi@raspberrypi:~ $
The file /tmp/dirlist holds 7 lines similar to the first printed when I run the script. However, the script can't parse the first line, but throws an error. Subsequent lines works fine but they are not printed by the echo command. I can't figure out why this doesn't work....