I've just written this on the fly right now, and haven't compiled it or
tested it. I'm sure there will be syntax errors/missing semi colons etc. But
if you're familiar with perl you can whip it into shape to do what you want.
If I get some time over the next few days, and if nobody else has got it to
work I might take another look at it.
It pulls down all the messages in a pop mail box, checks for a subject line
which contains the phrase "username" and then checks to see if this subject
line has a username & password which matches the hardcoded username and
password in the script. If so, it performs the action. You would schedule
this perl script to run every 10 minutes (or whatever) to check if there was
any new mail with commands.
The subject line of the email you send to is colon seperated and should look
like this:
username:blah:password:blah:command:blah
So you would send an email with a subject of
Subject:username:myusername:password:mypassword:command:restart
for instance.
As I said, unless I've written something which works the first time it's run
for the first time in my entire life, it's not going to work out of the box,
it's just an example. I'll leave it to people on the list who are familiar
with perl to get it working properly.
#!/usr/bin/perl
use Mail::POP3Client;
$action_required='NO';
#replace pop_username with the username needed
#to connect to the pop mail box
#replace pop_password with the password needed to
#connect to the pop mail box
#replace pop.whatever.domain.whatever.com
#with the address of your popserver
#
$pop = new Mail::POP3Client("pop_username", "pop_password",
"pop.whatever.domain.whatever.com");
$amount_to_do=$pop->Count;
OUTER_LOOP: for ($i = 1; $i <= $amount_to_do; $i++)
{
foreach( $pop->Head( $i ) )
{
if (/^Subject:\s+/i) #we have come to the subject field in the mail
header
{
$subject=$_;
#get rid of the word "Subject:" to leave the bit with just the
username/password/command
$subject=~s/^Subject:\s*//i;
#does it actually contain theword 'username'
if ($subject=~/username:/i)
{
$action_required='YES';
last OUTER_LOOP; #only do the first one we come across
}
}
}
}
$pop->Delete($i); # get rid of the mail message
$pop->Close($i); #close pop connection
if ( $action_required eq 'NO') { exit 0; }
#Next line might be hard to read,
#it's @subject_parts=split ( / : / ,$subject ) - but without the spaces
@subject_parts=split(/:/,$subject);
#format of subject line is colon seperated
#username:blah:password:blah:command:blah
$username=$subject_parts[1];
$password=$subject_parts[3];
$command=$subject_parts[5];
# get rid of any whitespace characters like <cr>, just in
#case.
$command=~s/\S*//;
#replace 'superdba' with whatever username you like.
#It doesn't have to be
#any real username.
#likewise for 'superdbas_password'. All case sensitive though.
if (($username eq 'superdba') && ($password eq 'superdbas_password'))
{
if ($command eq 'restart')
{system ('restart.bat')}
if ($command eq 'shutdown')
{system ('shutdown.bat')}
if ($command eq 'whatever')
{system ('whatever.bat')}
}
exit ;
You'll need to have Mail::Mail::POP3Client installed, which you can download
& install like this:
if using Activestate perl,
D:\>ppm
PPM interactive shell (2.2.0) - type 'help' for available commands.
PPM> install Mail::POP3Client
Install package 'Mail-POP3Client?' (y/N): y
Installing package 'Mail-POP3Client'...
Downloading
http://ppm.ActiveState.com/PPMPackages/5.6plus/MSWin32-x86-multi-thread/Mail
-POP3Client-2.15.tar.gz ...
Installing C:\usr\html\site\lib\Mail\POP3Client.html
Installing C:\usr\site\lib\Mail\POP3Client.pm
PPM>exit
D:\>
----- Original Message -----
From: "Jason Volpe "
<mssqldba-ezmlmshield-x44191306.[Email address protected]
To: "LazyDBA.com Discussion" <[Email address protected]
Sent: Friday, May 28, 2004 2:03 AM
Subject: Response
> I have a blackberry and would like to be able to stop/restart iis, sql
> server, or sql server services by sending an email to a dedicated dba
> exchange account. Is this a pipe dream or could you actually code
> something to understand what you want to do??
>
>
>
> ---------------------------------------------------------------------
> TO REPLY TO EVERBODY , PLEASE CLICK REPLY-ALL, NOT JUST REPLY
> Website : http://www.LazyDBA.com
> To unsubscribe: http://www.lazydba.com/unsubscribe.html
> For additional commands, e-mail: mssqldba-[Email address protected]
>
MS Sql Server LazyDBA home page