LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 09-27-2013, 04:48 PM   #1
chickenshit
LQ Newbie
 
Registered: Sep 2013
Posts: 1

Rep: Reputation: Disabled
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.

Last edited by chickenshit; 09-27-2013 at 05:16 PM.
 
Old 10-03-2013, 06:02 PM   #2
corp769
LQ Guru
 
Registered: Apr 2005
Location: /dev/null
Posts: 5,818

Rep: Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007
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)

Last edited by corp769; 10-03-2013 at 06:09 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how to lftp mirror in a bash zimbot Linux - Server 1 01-22-2013 01:09 PM
lftp mirror problem ycxbiao Linux - Software 1 09-27-2009 09:42 PM
lftp mirror problem crusher88 Linux - Software 2 08-14-2009 01:03 AM
filezilla setting and lftp:mirror help samengr Linux - General 0 01-25-2008 05:51 AM
LFTP , mget question sopiaz57 Linux - General 1 09-03-2004 12:09 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 12:58 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration