April 25, 2021 • 2 min read
In iOS 14, Apple added the Shortcuts app which allows you to automate tasks on your iPhone. To create a Shortcut you put together Actions. One of the actions available is the Scripting action which has a feature for running shell scripts. We will use this feature to connect to a remote server and run a simple script.
The first thing we need to do is select the correct Action to run.
You can connect to your remote server using a username and password, but it is more secure if you use an SSH Key. The good thing is that an SSH Key is easy to set up on an iPhone.
If you want to connect with your username and password:
Now that we can connect, you can add your script in the script section. For example, to create a new directory called "testiphone" in your home directory on the server, add the following and press run.
Pretty much any command or script that you can run on your server from a command line, can be done from your iPhone with this feature.
Press "Next", add a name for your shortcut and save it so yo can run it whenever you want.
For one my websites, I was having consistent issues that caused the site to go down frequently. I started looking for solutions but I was having a hard time finding any. The temporary solution for me to was to hop on my computer, connect to the server, and shut it down. Of course this required me to always be near my personal laptop, which is not always the case. Being able to do it from my iPhone makes it a lot easier since most of the time my phone is nearby. This issue does not happen anymore, but if it does and I need to turn off my server I can use a shortcut to do it from my phone.
Another real world example is being able to run a script to check the status of website from your phone and letting you know if it is up or not.
Hope this was helpful and let me know if you come up with any interesting shortcuts.