A tiny script to remote control your PC

30Mar12

Quite often do I leave for work, leaving my precious laptop at home, running some tasks or just downloading  stuff.  As a casual day goes by, do I worry about it, thinking how’s my buddy doing out there, all alone, in an empty flat? In fact, it’s not that safe to leave your electrical appliances working heavily, processing tons of data, heating up. So, I thought, is there a way to monitor and control you PC remotely? Of course there are many ways and a variety of tools. But what if I don’t need all that bloated software? What if I need one script, that could do simple stuff like checking, running simple tasks and reporting back?

As a result, I wrote a script for that purpose. How it actually works? Very simple, it probes your gmail account every 15 min. for arrived emails, which, in fact, are commands to perform. Let’s get into more details.

The script uses cron and curl  to probe gmail account for newly arrived letters, it extracts the email’s subject, which should be a command to perform. Then it reports back the command output.

On first boot, the script asks for your gmail login name (the account you will send your commands to), password for that account and a second email address to send reports to. After that it creates a cron job to be executed every 15 min and starts checking the indicated account for new emails.

For the script to work properly, you have to do two things though. Create a new gmail account and configure your ssmtp service. Piece of cake, I must say!

First — create a separate gmail account, exclusively for the purpose of receiving your email-commands. It is very important not only for normal work of the script, but mainly for security reasons. You don’t want your PC to receive a “mv *.* ~/.config” command as an innocent joke from a good old friend. Create a new gmail account, make filters, so that it accepts email only from several reliable sources. This is how it’s done:

1. Upon making and logging into a new gmail account open up settings and click filters tab.

2. Choose “Create a new filter”

3. In the newly opened window click on “from:” field and put down the addresses you are going to receive email-commands from like this:

“!mail@gmail.com !12345@mms.mygsm.com”

4. Click “continue”, check “delete it” box and click “Create filter”.

Now after you have set up your gmail filters, you will receive email-commands only from the above mentioned “certified” accounts. Remember, your security is always your responsibility, and even the strongest passwords will not excuse your negligence.

Second — we need to install ssmtp package and configure ssmtp service, so that the script would know how and where to send reports. It’s pretty straightforward, install ssmtp from your repository. Then under root open /etc/ssmtp/ssmtp.conf file and edit it like this:

root=yourmail@gmail.com   #the one you’ll use for receiving script reports

mailhub=smtp.gmail.com:587   #the mail server to send emails to

rewriteDomain=gmail.com   #the address, where the email appears to come from

hostname=local   #your PC hostname

UseTLS=Yes

UseSTARTTLS=Yes

AuthUser=mygmail   #your gmail account login name

AuthPass=mypass   #your gmail account password

FromLineOverride=yes

Finally, put the script to “/usr/local/bin” and run it (don’t forget to “chmod +x” it;). In a few seconds you’ll be able to send emails to your PC and it will answer you back:)

Oh, did I forget to tell you how to send an email-command? Very simple, go to your gmail account (remember, the one which was set not to be filtered), and compose a letter to your new gmail account for remote control with the subject field containing a shell command like “ls -l” (you can leave the letter empty).

Take notice, there are some dependencies. You need to have “zenity” ,”curl” and “ssmtp” as was mentioned above.

Download link for the script: http://evalm-script.googlecode.com/files/evalm

Advertisements


No Responses Yet to “A tiny script to remote control your PC”

  1. Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: