survival – Connection to ftp server using a script and block of commands automatically
It results a bit helpful to send certain information using FTP authenticated, but automatically for scripts, as you can see highlighted.
#!/bin/bash
#
umask 002FTP_Server=”webserver.queiroz.info”
FTP_USER=cqueiroz
FTP_PASSWD=blablablaREMOTE_FTP_DIR=/home/cqueiroz/log_bkp
LOCAL_FTP_DIR=/var/log/app/
cd $LOCAL_FTP_DIR
ftp -inv $FTP_SERVER<<EOF
user $FTP_USER $FTP_PASSWD
binary
cd $REMOTE_FTP_DIR
prompt off
pwd
put *log
bye
EOF
You could even define a policy that says: I wanna keep the last three days logs instead upload all log files into the local folder
file2update=`find . -name “*log” -mtime -1 -type f | sort -u | xargs `
for i in file2update
do
(function ftp connect and upload) blablabla
done
Now you have to remove the file which has 4 days since last time modified.
file2remove=`find . -name “*log” -mtime 4 -type f | sort -u | sed ‘s/$/.Z/g’ |xargs `
for i in file2remove
do
(function to connect and delete files)
done
That’s all