Tuesday, August 19, 2008

Writing Scripts & Cron

Scripts are a way to simplify a list of commands or allow something else to execute commands. Here is an excellent summary of how they are written. Scripts must start by telling shell how to interpret them. Therefore, they often begin with:
#!/bin/bash
On the next lines, simply enter the commands you wish to be executed. Once you have made a script, you then usually want to then change the permissions so everything can execute it. For example, to give full read/write/execute permissions (which may not be appropriate in all situations), run the following command:
sudo chmod 777 /path/to/script

To have the script you have created executed at a regular interval, you can move it to one of the cron folders. These include /etc/cron.hourly, /etc/cron.daily, /etc/cron.weekly, and /etc/cron.monthly. For example, to have a script executed hourly, move it to cron.hourly with the following command:
sudo mv /path/to/script /etc/cron.hourly

Sources: Writing Shell Scripts

No comments: