SUSE Conversations


Remotely Dispatching Jobs from your Cell Phone



By: mlfarrell

May 22, 2008 2:35 pm

Reads:107

Comments:0

Rating:0

by Michael L Farrell

Okay so perhaps you’ve shelled out the extra bucks for an iphone and you can run just about any app you want on it to connect to your computer. However, if you’re like the rest of us, the only “fancy” thing you can do with your cell phone, besides talk on it, is send emails. This article will teach you how to configure your linux server to respond to emails from your cell phone and execute specific pre-programmed jobs as a result.

Getting Started

The first thing you need to do is configure your server to accept incoming emails. Do this by starting to the “Mail transfer agent” module under yast2 and configuring the Incoming Mail section as follows where here I use “kain” as my local user name.

Note the choice of “procmail” for delivery mode. This will be important. Also take care when choosing the user account to forward to, as this is the account the remote jobs will be ran under. If you have a firewall, you’ll need to disable it for the smtp port number.

Next, you should verify that your mail host is correct to your global dns server name for your box. Do this by editing the /etc/postfix/main.cf as root and changing the following line to your correct host name

myhostname = localhost # change this to your globally-accessible dns server name (ie www.mybox.com)

After this, verify the change and restart the postfix service (still under root)

slickbox:/etc/postfix # grep "myhostname = " main.cf
myhostname = xxxxx.ath.cx
slickbox:/etc/postfix #
slickbox:/etc/postfix # rcpostfix restart
Shutting down mail service (Postfix)                                 done
Starting mail service (Postfix)                                      done
slickbox:/etc/postfix #

Now send a test email to your test user from your cell phone and verify its receipt under that user’s account. There may be a delay due to the slow nature of email delivery from some cell phone providers

kain@slickbox:~>
You have new mail in /var/spool/mail/kain
kain@slickbox:~> mail
mailx version nail 11.25 7/29/05.  Type ? for help.
"/var/spool/mail/kain": 1 message 1 new
>N  1 <mycell#>@VTEXT.COM  Wed May 14 23:26   21/825   Test
?

Okay it works! On to the procmail stuff.

Configuring the remote jobs

Now we’ll want to set up a pre-programmed list of jobs that can be executed remotely only from our cell phone’s email and only containing special keywords that should be hard to guess for security reasons (for additional security concerns, read “security implications” below).

Create a shell script file in your ~/bin directory for each remote job you want to have available to your cell phone. In this example, I’m configuring a job for remote hibernation for my laptop for energy saving reasons. So I’m creating ~/bin/cellphone_hibernate.sh

Containing the text:

#!/bin/bash

powersave -U

Next, I make sure the script is executable

kain@slickbox:~/bin> chmod +x cellphone_hibernate.sh

Now, create a file in your home directory, ~/.procmailrc (the leading dot is important) containing the following

PATH=$HOME/bin:/usr/bin:/usr/ucb:/bin:/usr/local/bin:.
MAILDIR=$HOME/Mail      # You'd better make sure it exists
DEFAULT=$MAILDIR/mbox

:0                             # Cell phone directive #1
* ^From.<mycell#>@VTEXT.COM
* !^execjob1_127850
|cellphone_hibernate.sh

The execjob1_127850 is the “command” that I text from my cell phone. I made sure to follow it by some random magic for some limited amount of security. It acts like a weak password for the command. I also make sure that this command is only valid if sent from my phone’s email address. This is somewhat provider-dependant as my provider (verizon) ends all their emails in vtext.com. If you have too much trouble with this, you can comment the From line with a ‘#’ and make the email work from anywhere if you don’t care about the security implications. The line beginning with a | is the command we execute locally upon receiving the email, which happens to be the script I edited earlier in my ~/bin directory.

Seconds after saving this file, I sent a test email from my cell phone to kain@slickbox with the magic directive and within 1 second my laptop started to suspend! Pretty awesome huh?

You can add as many jobs here as you want and if you’re good with procmail, you can even dispatch jobs that collect data and send reports back to your phone – all autonomously!!

Security Implications

Disclaimer: Please be sure to understand the security implications of enabling remote email delivery and procmail processing on your linux server. You should fully understand what you are doing before following the instructions on this article. I accept no responsibility for any damages or losses resulting from the directions in this article. Use them at your own risk.

VN:F [1.9.22_1171]
Rating: 0.0/5 (0 votes cast)

Tags: ,
Categories: SUSE Linux Enterprise Server, Technical Solutions

Disclaimer: As with everything else at SUSE Conversations, this content is definitely not supported by SUSE (so don't even think of calling Support if you try something and it blows up).  It was contributed by a community member and is published "as is." It seems to have worked for at least one person, and might work for you. But please be sure to test, test, test before you do anything drastic with it.

Comment

RSS