Simple Automation Scripts

Making a script to automate a few commands is actually pretty easy, but seemed really daunting on the first few attempts.

Here is a breakdown to create a simple script, make it executable and run it.  Once you get the hang of this you can create your own customized scripts.

nano automation.sh

Create a new file with the .sh extension.  While the extension is not necessary for the script to run, it helps you know it’s a script when looking at the file in the directory listing using ls.

#!/bin/sh

This is the first line of the script that tells bash “hey, this is a script!”

# Start Automation Script

Adding comments like this helps to keep track of what the script is doing.

echo “This is an automation script!”

Here’s an example of a command that can be run, really any command run in the terminal can be put into this kind of script.

Your script file should look like this when editing in nano.

#!/bin/sh

# Start Automation Script

echo “This is an automation script!”

Exit and save the file with Ctrl x, confirm you want to save with y and press enter.

chmod +x automation.sh

Modify the permissions to make the script executable.

./automation.sh

Run the script.  This command will run the script but make sure you’re in the same directory as the script.

 

Advertisements

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 )

Google photo

You are commenting using your Google 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 )

Connecting to %s