Server Uptime Competition Click Here to see current bragging rights.
Another one from the library of often used scripts. Rotate backups, log files or just about anything you this you might need a copy of.
In this example, I back up my .bash_history file from my home directory each night so I always have copes stretching back 30 days.
You can use this script for just about anything you need to keep a number of historical backups of.
You can write an entry in your crontab as follows:
crontab -e
5 5 * * * /home/jim/bin/backup-history
Here's the script:
#!/bin/bash
Another useful script for a busy linux/web admin. This one will recursively find all the text based files from a given folder on down and look for your search term. It will then list the files with said search term in them and include the applicable line numbers within each file.
Not perfect by any means, but handy at times...
#!/bin/bash
#################################################################
# A script to help you find X in all text files recursively
# Jim R 2010/06/30
# Known issues: does not yet work with / or other special chars
A mainstay in the Linux Admin Toolkit - the ability to quickly find the disk hogging folders on a server's file structure.
This one will give you a summary disk usage for sub-folders in the immediate, current directory.
-----------------------------------------------
#!/bin/bash
log=/tmp/diskusage.log
ls -d */ > /tmp/list
date > $log
pwd >> $log
for folder in `cat /tmp/list` ; do
cd $folder
pwd >> $log
du -hs >> $log
cd ..
done
cat $log | less
Whilst not strictly "scripting", setting up RAID1 on Linux can be a little tricky if you have never tried this before.
Here is a link to a HOWTO I wrote on how to do this on RedHat based distributions of Linux. This includes the excellent ClearOS
Click Here to download the HOWTO in PDF format.
Here's another script that I use almost every week.
We have a lot of MailScanner/Sendmail email filter servers and with some of processing close to 100K/day it can get a little futile trying to pop open the maillog in nano to find out what happened to a message. The following script takes the hassle out of getting the full transaction out of the log for you and if you need it to, will email you the data. Gotta love the bash ;)
#!/bin/bash
# Find Email transaction info from Maillog
# Jim R 2005
log=/tmp/search.results
cat /dev/null > $log
clear
A request from my older brother to convert his iTunes library from m4a to mp3 format.
We looked at some cheaper commercial software out there but whilst there was some that seemed to be able to convert and retain the tag info nicely, we could not find anything that would recursively work through a folder hierarchy and convert in a single pass.