Results 1 to 6 of 6
I need a program that will run certain scripts/programs depending on contents of the email.
Example:
I send an email to statusbot@mydomain.com with the body saying space . The email ...
- 01-13-2008 #1Just Joined!
- Join Date
- Mar 2006
- Posts
- 65
Smart email bot?
I need a program that will run certain scripts/programs depending on contents of the email.
Example:
I send an email to statusbot@mydomain.com with the body saying space. The email bot then runs this bash script:
Code:#!/bin/bash #Percent of space used pct_used=$(df -h | grep hda1 | grep -o [0-9][0-9]'%'| tr -d '%') #Gigabytes free gb_free=$(df -h | grep hda1 | egrep -o '([0-9].?[0-9]?G)( {2})[0-9][0-9]?[0-9]?%' | sed -n 's/[0-9][0-9]%//p' | tr -d G | tr -d " ") echo "Disk '/dev/hda1' is $pct_used% full with "$gb_free"GB's of unused space." > _spacemail.txt mail -s "Hard Drive Space Alert" statusbot@mydomain.com mycell@cellprovider.com < _spacemail.txt rm -f _spacemail.txt
So I need the bot to interpret the contents of the email, and run the needed script. This system is going to be used by my cellphone, allowing me to keep track of my server while away from an internet source. I would rather the email bot be able to run a script, then reply with the output, which would allow me to use a cellphone other than my own, but the above scheme would be much easier to implement. So if anyone can think of how to auto-reply with a scripts output, that would work too.
Is this possible?
- 01-24-2008 #2Just Joined!
- Join Date
- Mar 2006
- Posts
- 65
Anyone? I've been searching on my own and I still can't find anything.
- 01-24-2008 #3Linux Newbie
- Join Date
- Jan 2008
- Location
- UK
- Posts
- 211
Hi,
Threre is a web site at bots.htm: (¯`·.¸(¯`·.¸ Searching Bots ¸.·´¯)¸.·´¯) - which shows you the code for bots to read pages and extract information, which you can use. Perhaps you can modify one to suit your needs. Many of them use Perl which is ideal for then running a script.
- 01-24-2008 #4Just Joined!
- Join Date
- Mar 2006
- Posts
- 65
- 01-28-2008 #5Linux Newbie
- Join Date
- Jan 2008
- Location
- UK
- Posts
- 211
I have been looking into MUTT - text based e-mail reader editor etc.
MUTT supports regular expressions pattern matching, and many other things. It interfaces with Mozilla as well. Here is a link:
The Mutt E-Mail Client
- 02-02-2008 #6Just Joined!
- Join Date
- Mar 2006
- Posts
- 65
Well here's what I did:
created a new user named statusbot
created a file name .forward in statusbot's hom dir with this in it:
mailmon.sh contains this:Code:/home/statusbot/mailmon/mail.txt,"|/home/statusbot/mailmon/mailmon.sh"
Than I can just keeps adding cases to suit my needs. Works perfect for me.Code:#!/bin/bash dPATH=/home/statusbot/mailmon for line in `cat $dPATH/mail.txt` do from=$(cat $dPATH/mail.txt | grep From: | grep -v Message-ID | grep -v Return-Path:| egrep "[a-zA-Z0-9_.-]+@([a-zA-Z0-9-]+\.){1,}([a-z]){2,4}" -o|grep -v statusbot) case $line in uptime|Uptime ) UP=$(uptime | egrep "([0-9][0-9]:?){3}.up.[0-9]{1,4}.days?" -o) echo $UP > $dPATH/out.txt ;; speed|Speed ) curl http://router:rangers@192.168.2.1:8000/speed.cgi -s -o $dPATH/rawpage.tmp up=$(cat $dPATH/rawpage.tmp |grep \<h3\> | sed -n 's/<h3>//p' | sed -n 's/<\/h3>//p' | grep Up) down=$(cat $dPATH/rawpage.tmp |grep \<h3\> | sed -n 's/<h3>//p' | sed -n 's/<\/h3>//p' | grep Down) rm $dPATH/rawpage.tmp -f echo -e "$down\n$up" > $dPATH/out.txt ;; "hi" ) echo "Why hello to you too" > $dPATH/out.txt ;; esac done mail statusbot@kylesplace.org $from < $dPATH/out.txt rm -f $dPATH/out.txt rm -f $dPATH/mail.txt echo done exit 0


Reply With Quote
