Tag Archives: bash

Setup a backup job for your LAMP sites. | Setup a backup job for your LAMP sites.

I wrote a script which takes a backup of my webserver, taking a snapshot of all the website content, database, and configuration files.

Theory is if the webserver died, we would be about to result quickly using the data backed up.

On the server, put the following script and below is the cron entry which triggers every week. You will need up change the username and password for your mysql server.

This is the cron entry which fires up every friday.

Now this script will be on a linux machine somewhere else, it will connect and copy the backup archive file generated. You must first setup the ssh key so that its passwordless connection.

Simplicity it key! It works and will get you out of trouble. Well worth the 5minute investment.

 

 

Simple way to backup your MySQL database everyday! | backup your mysql database everyday with this bash script.

This is a simple script to backup your MySQL database everyday and compress it on the fly, you just need to add an entry into Cron. see below

Script

The script will also data the new backup which stops it overriding the previous backup.

Edit cron

Enter this

This will kick off everyday at 9:22pm

Get an email when your public IP changes | get notified when your public ip changes.

Alot of us have ISPs which change your IP address and you may not want to setup a client with a dynamic IP or want a backup in case the services fails.

So i developed a bash script which checks to see if your public IP has changed. If it has it will log it and email you the new IP.

See below.

 

 

Dump1090 to MySQL Script | send flight data from dump1090 to mysql

I wanted a script which would read all the live dump1090 aircraft data and log it to a mysql database.

This base script does it, it will dump all the data to Mysql every minute.

It will start the dump1090 server and kick off a process which reads/sorts and inserts.

 

Bash script to generate a sitemap.xml on a WordPress instance | bash script to generate a sitemap.xml for wordpress

There are free online tool to generate sitemap.xml, but the one I used would only index 500 pages. My site www.techinterchange.com.au has more, so I decide to write a bash script which ill index the site and generate an sitemap.xml.

Its simple, ill continue to add features and make it more reliable. This is only working with WordPress atm, Ill improve with the next revision.

 

 

Having your Linux system email you! | How to write a script which emails you

Quite often you need to write scripts which need to email you urgent information, there is a very simply way to do this.

First we need to install an email server to transmit the emails.

Then insert the following into your script.

In the above example it will email a copy of your local host file, change be change for any file you want transmitted.

See this script for a working example.

Visibility when your IP changes and is updated by no-ip | email notification when ip changes home adsl nbn bash script

My new internet connection with NBN changes the IP on a regular basis, but I wanted visibility as to how often.

So I’ve written a bash script which records your IP and date, once it changes it records your new IP and sends you an email to notify you of the new change.

This is completed by querying your no-ip dns record.

Usage

 

Cron Entry. (runs every hour)

 

 

Encrypting your home area for backup with Openssl | using openssl to encrypte and automate your backups to fileserver

Im currently running a Linux desktop, the other day the disk become corrupt and I lost my home area. Not a big problem as I dont store much data, but I lost all my ssh keys, configs etc. It took a few days to recover.

In an effort to stop that from happening again I want to backup all my data to the company file server, but I dont want them to have access to my keys and configs ect.

So I have scripted a backup which will encrypt on the fly. Through it into cron and you have a daily backup.

This is the command you run to create backup, notice the password is in the command. This is allow for automated backups using Cron.

And the following command is to run a restore, once executed you will be prompted for the password.

 

 

Killing stale SSH connections | linux centos bash stale ssh connections script ClientAliveInterval

I administer a large scale SSH server with upwards of 300+ concurrent sessions. This server presents some challenges.  When migrated to AWS it started experiencing a large number of stale SSH sessions.

Fixing this was achieved in two parts. First was a bash script which ran every hour which culled all the stale connections.

The second part was to specify keepalive packets at 5 second intervals in the /etc/ssh/sshd_config file.

 

Top 6 common uses for grep | top six uses for grep linux systems administration centos redhat

Grep is the number one tool used by linux systems administrators. I rely on this tool everyday, but its used in many different ways. I decided to list my top six uses.

 

Top use is grep with the recursive switch (grep -r). This is used for searching a particular filesystem path for a particular word. One common reason why I use this switch is when Im searching in a nagios configuration directory for mentions of a hostname. This allows me to find all the locations where a hostname has been mentioned and I can then alter it if needed.

 

This straightforward search allows you to look in a text file and find all the locations where the expression or search word can be found. The results will include the entire line where the expression has been matched.

 

The will do the opposite from he previous command, this will exclude all mentions of the search criteria. This will remove the entire line from the search results.

 

This will match the line but also include a certain number of subsequent lines, the number indicates how many lines after the match you would like included.

 

Again this the opposite of the previous command, this will include a certain number of lines before the match line.

 

This also proves to be very useful, this will remove case sensitivity from your search string.