How to Run Commands on Raspberry Pi by Email
This problem is faced by nearly every Raspberry Pi user. You accept a Raspberry Pi running at home, and want to execute a command on it. The consequence is, you are outside your dwelling house, on your mobile network, and have no way to access your Pi. You lot can go a static IP address, or use one of the dynamic DNS services to enable access to your home network. However, that is merely also inconvenient for nearly people and takes likewise much effort for little gain. In add-on, it opens your Raspberry Pi to brute-forcefulness attacks, since the SSH port is at present exposed to the earth.
The good news is, at that place is a more convenient, and more secure method – simply e-mail the commands you wish to run on your Raspberry Pi. This mode, all yous need is an electronic mail client and a working internet connection on your Pi. No logins, and no static IP'due south. What'south more, this method not only works with the Raspberry Pi, just with whatever Linux distro with the Fustigate shell and cURL installed. Sounds absurd? Here is what y'all need to set up information technology upwards:
Requirements
- A Raspberry Pi with a working net connectedness.
- An business relationship on IFTTT.com.
- A Dropbox account.
Getting Started
Set up Up IFTTT Recipe
We will utilise IFTTT to distribute commands delivered by email to Dropbox. After setting up an IFTTT account, y'all will accept to use the "Run bash commands on Raspberry Pi past e-mail" recipe. Merely, go to this IFTTT recipe, and click on Add.
Fix Up Dropbox Uploader
We need Dropbox Uploader –
one. On your Raspberry Pi, get the prerequisite software gyre and wget. You lot probably already have these installed, but we will install them just in instance:
[sourcecode]sudo apt install wget gyre[/sourcecode]
2. Create a folder where nosotros will set it up. Hither, I've created a directory called raspi_email
in my home binder:
[sourcecode]mkdir ~/raspi_email
cd ~/raspi_email[/sourcecode]
3. Get the Dropbox Uploader script from GitHub, and mark information technology executable:
[sourcecode]wget https://raw.githubusercontent.com/andreafabrizi/Dropbox-Uploader/chief/dropbox_uploader.sh
chmod +ten ./dropbox_uploader.sh[/sourcecode]
four. Run the dropbox_uploader.sh
script. You will see an output like this:
5. Now y'all need to create a Dropbox app. Log in to Dropbox, become to this URL, where you lot will encounter a screen that looks like this:
6. As in the paradigm above, showtime choose the Dropbox API, and then select Full Dropbox in the blazon of access needed. Finally, Proper name your app whatever you like.
vii. Subsequently your new app is successfully created, scroll downwards to the OAuth2 section, and click on the Generate button to generate an access token. You volition at present see a generated access token where the Generate button was. Re-create this token, paste it in your last, and press Enter:
8. To verify that your account is working, execute the control ./dropbox_uploader.sh list
– you should meet a listing of the files in your Dropbox account.
Set Up Raspi Runner
On your Raspberry Pi, download the Raspi Runner script in the raspi_email
binder we created previously:
[sourcecode] cd ~/raspi_email
wget https://raw.github.com/enkydu/Raspi_Runner/master/raspi_runner.sh[/sourcecode]
Make the script executable, and run it:
[sourcecode]chmod +ten ./raspi_runner.sh
./raspi_runner.sh[/sourcecode]
You lot will now see a prompt like the image below. When the script asks for the total path to your Dropbox Uploader, enter the path to your Habitation directory (probably /home/pi/
), followed past the name of the binder in which yous downloaded the dropbox_uploader.sh
script. If you lot followed this guide word past word, you will enter /dwelling/pi/raspi_email
hither.
Set Up Crontab
One time the nuts are in place, information technology is necessary to schedule the running of Raspi Runner. For instance, you lot can set it to cheque for emails every five minutes.Nosotros volition use crontab for this. On your Raspberry Pi, run:
[sourcecode]crontab -e[/sourcecode]
On the lesser of the file, add the following line:
[sourcecode]*/5 * * * * /domicile/pi/raspi_email/raspi_runner.sh > /dev/zero 2>&1[/sourcecode]
Of course, in the higher up example, replace pi with your username, and raspi_email with the folder y'all placed the raspi_runner.sh
script in. Now save your crontab.
Usage
Simply send an email with the commands you lot wish to execute on your Pi to trigger@recipe.ifttt.com from the email address you lot used to set up your IFTTT business relationship. The body of the email will contain the command. You lot can add together whatsoever field of study you similar to the email, but it is recommended that you exercise add ane. In the following example, I am commanding my Raspberry Pi to shut down:
Afterward the corporeality of filibuster you set in your crontab, the raspi_runner.sh volition run and execute the control independent in your electronic mail.
SEE Too: How to Ready and Get Started with Raspberry Pi 3 (Starter Guide)
Run Commands Remotely On Your Raspberry Pi Using IFTTT
So this is how you tin utilise IFTTT, Dropbox, and some command line magic to run commands remotely on your Raspberry Pi. Of form, as mentioned in the beginning, this method will too piece of work with whatsoever Linux or Unix-like system with the Bash shell installed.
Stay tuned for more Raspberry Pi tips and tricks in the futurity. If you have trouble setting it up, or want to share some of your own cool IFTTT tricks with us, make certain to drop us a line in the comments section below.
Source: https://beebom.com/how-to-run-commands-on-raspberry-pi-by-email/
Posted by: gordonnothad86.blogspot.com
0 Response to "How to Run Commands on Raspberry Pi by Email"
Post a Comment