The bash scripts

Part 1: Pulse via Openconnect in Debian Buster
Part 2: Use LFTP to batch download files and then delete them on server.
Part 3: mSMTP with Office365
Part 4: The bash scripts

First we have the script that connects to the vpn and downloads everything via lftp

echo "Starting VPN to yourvpn"
sudo systemctl start yourvpn.service
sleep 5
echo "Downloading files"
lftp -u username,password hostname -e "mirror --exclude .profile --exclude .sh_history --Remove-source-files --verbose /remote/path /local/path/; bye"
sleep 2
echo "Stopping VPN"
sudo systemctl stop yourvpn.service
sleep 5
echo ""
echo "Mailing-Log"
/home/xml/ ##see schript
echo "DONE"

Second script for checking lftp log for a string in this case the date from the filenames that we download and then email the result to us.

#Function to get Yesterdays date
getdate=$(/usr/bin/date -d "$date -1 days" +"%Y%m%d")

#grep for Date in logfile
output=$(/usr/bin/grep "$getdate" "/path/to/log/lftp.log")

if  [[ -n $output ]]; then
        echo -e "Subject: New XML-files in LFTP Log\r\n\r\n$output" |msmtp --from email@domain -t email@domain
        #echo "$output"
        echo -e "Subject: No New XML-Files in LFTP Log\r\n\r\nNothing matching the date $getdate" |msmtp --from email@domain -t email@domain
        #echo "Nothing New"

Now simply add the first script to a crontab. We wanted it to be run everyday @ 00.01

1 0 * * * /path/to/ >/dev/null 2>&1

Leave a comment

Your email address will not be published. Required fields are marked *