Linux Shell Scripts

Handy Bash Scripts to get started

Linux is very customizable especially if you take advantage of the terminal mode and enter commands at the command line. You can automate these commands by writing them in a small text file with the extension ‘.sh’, this is called a bash shell script. You can execute the script by typing ‘sh scriptname.sh’.

You can write or edit bash shell scripts to automate and personalize many tasks, such as backups, daily downloads (use the wget command), mirror your files to another server (rsync), basically anything you can imagine.

The scripts provided here are some examples to get you started quickly, you will have to provide some paths and details specific to your system so read through the script and modify them where required.

Backup shell script

The backup shell script will allow you to create automatic backups of your htdocs and mysql directories (webserver and database) on a daily basis (1, 7 or 14 days history), automatically rotates the backups, mirrors to another server, FTP’s to another server,restore the files from any given day to return your system to a previous state, exclude option for certain databases or htdocs directories, and send out an optional email confirmation upon success or failure of the backup process.

backup.sh_.zip

MySQL Repair and Optimize shell script

This shell script will optimize or repair a MySQL database, it can handle a large amount of tables and will go through the tables one by one.

mysqltool.sh_.zip

Create SSL certificate shell script

You can use this script to create your own self-signed SSL certificate.

ssl_certificate.sh_.zip

Screensaver shell script

If you have the Cmatrix screensaver installed on your system, you can show a Matrix style screensaver on your terminal. With this shell script, you can run the screensaver as a process which will be killed the moment the load on the server gets too high. You can use this script as an example to run your shell scripts as a background process.

screensaver.sh_.zip

Sorting shell script

This shell scripts helps you arrange your movies into genres. It should be located in the same directory as the movie files you want to sort. The genre of the movie file will be determined by the OMDB search engine, it will create the genre directory if it does not exists and move the file there. The movie file will be tagged with the year of release and the IMDB score, example: 2017 (6) The Movie.mp4. Get your API key from http://www.omdbapi.com/apikey.aspx

file2genre.sh_.zip