Tag Archives: script

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.

 

 

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.

 

 

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.

 

Executing SFTP transfers in BASH scripts | linux centos ssh rcp sftp ftp bash script batch file automation

I need to write a script which fetched files off a ftp server and put it into a specify folder for processing.

I was used to using SSH for these job and now I was forced to connect to an SFTP server, this was my first time and everything is a little different.

I have attached the commands I used in my bash script to get the project over the line.

 

This command allows you get a listing of what is currently on the server.

This will fetch all the CSV files on the SFTP server and copy them locally.

This was partially tricky, don’t know why. They may be an easier way which I overlooked but this worked for me. For some reason to send file you need to specify the instructions in a batch file which is execute once connected.

 

Using nmap to generate Nagios config.

I need to add hosts quickly to Nagios, I do this by scanning the hosts using nmap and generating a config with the output. Then I setup a Nagios client on the host and monitor the vitals.

This process takes time, so i wrote a script which will generate the configuration for me using the nmap results. see below.

 

Mythtv and HDhomerun

I use a combination of a HDhomerun tuner by Silicon Dust and a PC with mythtv backend setup, the tuner is network based.

Problem is the hdhomerun only works with DHCP, no static IP setup. So what happens is when I have a power outage the unit resets and comes back with a different IP.

I know I should setup my own DHCP server instead of using my routers, but cbf

So, what was happening was when the IP changed my mythtv would still record…. But nothing was recorded.

So I wrote the following script which would log on to the database check the recorded files and compared them to the files in the directory. If it existed in the database and not in the directory it will remove the entry from the database.

It just works and keeps your mythtv db nice and clean.

 

Nagios master / slave configuration files

I run a large Nagios setup, currently running one master server and around 10 slaves in a distributed monitoring setup.

The problem is when you setup your check on the slave for active monitoring you need to do the some on the master for passive monitoring, it takes ages.

So I wrote a single live stripper which changes the field to a passive format which change then be cut-n-pasted into the master. The one thing I put in as an extra is the parent relationships.