LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Sending email after successful lftp mget or mirror (https://www.linuxquestions.org/questions/linux-software-2/sending-email-after-successful-lftp-mget-or-mirror-4175478793/)

chickenshit 09-27-2013 04:48 PM

Sending email after successful lftp mget or mirror
 
Hey everyone, I've spent the last week configuring a server to auto download files from an FTP server the moment they are put up there, then delete them once I've downloaded them. I have been trying to send an email to a facebook email address once the process is completed, and from there the facebook will post to a twitter account but haven't had any luck. I've tested my mail scripts and it works flawlsessly, the second I send the mail script, I get a twitter notification on my phone saying download completed. This is my first experience with linux, so I'm not entirely sure how to do everything (that's why it took a week to setup so far :P)

I have my mail server setup like this with msmtp.

I have a file named test.mail with the following contents

Code:


To: xyz@m.facebook.com
From: myemail@mail.com
Subject: @twuser your download has completed

I then call that file with this command run from the same director as the test.mail file

Code:

cat test.mail | msmtp -a default xyz@m.facebook.com
I run two separate FTP commands, mget and mirror, dependng on which folder I am retrieving from. Let's say for folder "A" I run this.
Code:

lftp -u user,pass sftp://domain.com:port -e 'mirror -c  --include-glob=*.ext "/path/to/destination/A/" "/path/to/local/dir/A/"'
For folder B I run this.
Code:

lftp -u user,pass sftp://domain.com:port -e 'mget -c -E /path/to/destination/B/*.ext -O "/path/to/local/dir/B/"'
Just to clarify, my email to twitter thing works perfectly, and my lftp downloading works perfectly, I just want to integrate the two.

I found this on superuser http://superuser.com/questions/64399...-ftp-transfer/ but I really have no idea how to implement it.

Please do not think I am lazy and just leeching for answers, I have tried but have no idea where to go from here.

Thank you.


EDIT: It turns out twitter filters duplicate messages, so for example if I downloaded 4 files in a day it may only send me one message. I want to append a random string to the end of the subject, but $RANDOM doesn't work in msmtp evidently.

corp769 10-03-2013 06:02 PM

Code:

./my_ftp_script.sh && echo "FTP was succesful" | sendmail you@yourdomain.com
Just use this as a base, and substitute everything you have done so far. Since you said you have two scripts, before I go giving ideas and such.... Would these two "commands" be run at the same time, or will they always be ran separately, and will "/path/to/local/dir/$b_var" always be static? Say for example they are static, and you have to run both commands at the same time, with two different arguments, one for directory A, and one for directory B. The following may work for you (this is a very rough draft, I technically need more information, and would of course need to be improved upon):
Code:


#!/bin/bash
# script that would perform both commands, and report with email/twitter about status (success or fail?)

(($(which lftp) -u $user1,$pass1 $domain:$port -e 'mirror -c --include-glob=*.ext "/path/to/destination/$A/" "/path/to/local/dir/$A/"' && mirrorvar="mirror success") || mirrorvar="mirror fail")

(($(which lftp) -u user,pass sftp://domain.com:port -e 'mget -c -E /path/to/destination/B/*.ext -O "/path/to/local/dir/B/"' && mgetvar="mirror success") || mgetvar="mirror fail")

status=$mirrorvar+" "+$mgetvar

message="To: $to_email\nFrom: $from_email\nSubject: $status"

echo $message | msmtp -a default $to_email

Once again, this is really rough, as I technically can't run this either(no FTP server, etc), and you will need to edit a few parts as well, including escaping a few characters. Hope this helps your understanding behind what technically needs to be done!

Cheers, and wish the best

Josh


Ninja edit - Wow, I didn't even notice a certain thing until of course after I have posted all of that. This will most likely get deleted... :/
(Reported username)


All times are GMT -5. The time now is 08:21 AM.