Find the answer to your Linux question:
Results 1 to 7 of 7
Hey all, I have made a neat little backup script and i would like to be able to run it remotly, eg from ANYWHERE! is there a way that i ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Linux Newbie
    Join Date
    Dec 2005
    Posts
    104

    Cool Running a Script when a email is recieved


    Hey all,
    I have made a neat little backup script and i would like to be able to run it remotly, eg from ANYWHERE! is there a way that i can make the script run when a email is recieved from for instance backp@domain.com.au with the content

    From: ***
    To: Backup@domain.com.au
    Subject: Backup
    --------------------------------------------------
    Run Backup


    And maby be able to tell my program to do it defferent ways, eg with arguments...

    Cheers,
    Nathan

  2. #2
    Linux Guru anomie's Avatar
    Join Date
    Mar 2005
    Location
    Texas
    Posts
    1,692
    Hmm, maybe. You could use some complex script that used mutt, grep and some other pieces to work as a cronjob to kick this backup off.

    But that seems unnecessarily complex to me. Also, anyone who knew about the script could send you a few hundred (spoofed sender) emails and potentially run a DOS attack on your machine.

    How about doing this a more standard way, like logging in to an ssh session and running it? Or letting a cronjob do it for you?

  3. #3
    Linux Newbie
    Join Date
    Dec 2005
    Posts
    104

    Thumbs up

    Quote Originally Posted by anomie
    Hmm, maybe. You could use some complex script that used mutt, grep and some other pieces to work as a cronjob to kick this backup off.

    But that seems unnecessarily complex to me. Also, anyone who knew about the script could send you a few hundred (spoofed sender) emails and potentially run a DOS attack on your machine.

    How about doing this a more standard way, like logging in to an ssh session and running it? Or letting a cronjob do it for you?
    The email address would:
    1) Not be advertised at all.
    2) In the body of the email have an option like -P "PASSWORD" and require that to kick off the job.
    3)SSH is not an option, i want to be able to do this from ANYWHERE, and some networks (like ours) have egress filtering and wont allow outgoing ports etc, also SSH requires a 3rd party software...

    Thanks Nathan

  4. #4
    Linux Guru
    Join Date
    Oct 2001
    Location
    Täby, Sweden
    Posts
    7,578
    I run a lot of scripts when I get mail. To do that, I use procmail. You'll have to check whether your distro has configured sendmail to call procmail to handle incoming mail, because some do and other don't, and I don't recall which ones do which. Procmail is a nice program design to deliver incoming mails to their final destination based on a set of filters. Normally, it delivers mail to different file mailboxes, but it can also e.g. forward mails to other address, filter them through scripts and send them to scripts.

    My ~/.procmailrc file looks like as follows. Pick and choose what you like. For more info, see the manpage on procmailrc.
    Code:
    LOGFILE=$HOME/Mail/.maillog
    
    # Spam handling
    :0
    *X-Spam-Flag: YES
    $HOME/Mail/spamdir/
    
    # Doldawebmail mailing lists
    
    :0
    *List-Id: <doldawebmail-[a-z]*.lists.sourceforge.net>
    $HOME/Mail/mboxes/mlist-doldawebmail
    
    # Mailing list multiplexing
    
    :0
    *List-Id: [^<]*<\/[^.>]*
    $HOME/Mail/mboxes/mlist-$MATCH
    :0
    *X-Mailing-List:[       ]*\/[^@]*
    $HOME/Mail/mboxes/mlist-$MATCH
    :0
    *Mailing-List: (.*; +)?list +\/[^ @]+
    $HOME/Mail/mboxes/mlist-$MATCH
    :0
    *Delivered-To: mailing list +\/[^ @]+
    $HOME/Mail/mboxes/mlist-$MATCH
    :0
    *Sender: owner-users@ipv6.org
    $HOME/Mail/mboxes/mlist-ipv6-users
    
    # Special root mail
    
    :0
    *Subject: LogWatch
    $HOME/Mail/mboxes/adm-logwatch
    :0
    *To: .*root@
    $HOME/Mail/mboxes/adm-toroot
    
    # Autonomous stuff
    
    :0
    *From: .*Cron Daemon
    $HOME/Mail/mboxes/cronjobs
    
    # Mail notification
    
    :0c:/home/fredrik/Mail/lock/mnotify.lock
    |$HOME/Mail/tools/mnotify
    
    :0
    *X-Mailer: autodlrep
    $HOME/Mail/mboxes/autodl
    My global /etc/procmailrc for the mail server looks like this:
    Code:
    DROPPRIVS=yes
    
    # Spamassassin learning
    
    :0
    *To: [a-z]*\+ls
    |/usr/local/libexec/learnspam >>/var/log/sal-log/$LOGNAME 2>&1
    :0
    *To: [a-z]*\+lh
    |/usr/local/libexec/learnham >>/var/log/sal-log/$LOGNAME 2>&1
    
    # Spamassassin scan
    
    :0fw:/tmp/spamc.lock
    |/usr/bin/spamassassin
    If you, for one reason or another, don't want to use procmail, I think there are some tricks you can play with ~/.forward, but it's much less flexible, and I don't remember its exact format (nor can I find docs on it).

  5. #5
    Linux Newbie
    Join Date
    Dec 2005
    Posts
    104
    Thanks,
    I probbably should have told you that im not using a linux mail server, so the email would have to be checked every 5 mins via a cron job, then scan the email every 5 to see if an email has come in from backup@domain.com.au and then act on that!
    Cheers,
    Nathan

  6. #6
    Linux Guru
    Join Date
    Oct 2001
    Location
    Täby, Sweden
    Posts
    7,578
    Well, if so, you had probably better check the fetchmail program. I don't recall its exact options or anything anymore, so I can only refer to the manpage. fetchmail handles POP3 and IMAP.

  7. #7
    Linux Newbie
    Join Date
    Dec 2005
    Posts
    104
    Ok, thanks.
    Ill have a look into it. Thanks for pointing me in the right direction!
    Nathan

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •