#!/bin/bash
# A Nginx Shell Script To Block Spamhaus Lasso Drop Spam IP Address
# Run this script once a day and drop all spam network IPs (netblock) with http 403 client error.
# The script will get executed every day via /etc/cron.daily (make sure crond
# is running).
# -------------------------------------------------------------------------
# Copyright (c) 2008 nixCraft project <http://cyberciti.biz/fb/>
# This script is licensed under GNU GPL version 2.0 or above
# -------------------------------------------------------------------------
# This script is part of nixCraft shell script collection (NSSC)
# Visit http://bash.cyberciti.biz/ for more information.
# -------------------------------------------------------------------------
# Last updated on Jan/11/2010
# -------------------------------------------------------------------------
# tmp file
FILE="/tmp/drop.lasso.txt.$$"
 
# nginx config file - path to nginx drop conf file
OUT=/usr/local/nginx/conf/drop.lasso.conf
 
URL="http://www.spamhaus.org/drop/drop.lasso"
# reload command
NGINX="/usr/local/nginx/sbin/nginx -s reload"
 
# remove old file
[[ -f $FILE ]] && /bin/rm -f $FILE
 
# emply nginx deny file
>$OUT
 
# get database
/usr/bin/wget --output-document=$FILE "$URL"
 
# format in nginx deny netblock; format
/bin/egrep -v '^;' $FILE  | awk '{ print "deny " $1";"}' >>$OUT
 
# reload nginx
/bin/sync && ${NGINX}

How Do I Use This Script?

Download and save this script to /etc/cron.daily/, enter:

cd /etc/cron.daily/
wget http://bash.cyberciti.biz/dl/500.sh.zip
unzip 500.sh.zip
mv 500.sh nginx.drop.lasso
chmod +x nginx.drop.lasso
rm 500.sh.zip

Edit nginx.conf (/usr/local/nginx/conf/nginx.conf) and add the following line:

## Block lasso spammers ##
  include drop.lasso.conf;
## Block lasso spammers ##

Save and close the file. Run the script:

/etc/cron.daily/nginx.drop.lasso
#!/bin/bash
# A shell script to add mysql database, username and password. 
# It can also grant remote access on fly while creating the database.
# -------------------------------------------------------------------------
# Copyright (c) 2007 nixCraft project <http://cyberciti.biz/fb/>
# This script is licensed under GNU GPL version 2.0 or above
# -------------------------------------------------------------------------
# This script is part of nixCraft shell script collection (NSSC)
# Visit http://bash.cyberciti.biz/ for more information.
# -------------------------------------------------------------------------
# Last updated on Jan/09/2010
# -------------------------------------------------------------------------
_db="$1"
_user="$2"
_pass="$3"
_dbremotehost="$4"
_dbrights="$5"
 
## Path to mysql bins ##
mysql="/usr/bin/mysql"
## Mysql root settings ##
_madminuser='root'
_madminpwd='MySQL-PassWord'
_mhost='localhost'
 
# make sure we get at least 3 args, else die
[[ $# -le 2 ]] && { echo "Usage: $0 'DB_Name' 'DB_USER' 'DB_PASSORD' ['remote1|remote2|remoteN'] ['DB_RIGHTS']"; exit 1; }
 
# fallback to ALL rights 
[[ -z "${_dbrights}" ]] && _dbrights="ALL"
 
# build mysql queries 
_uamq="${mysql} -u "${_madminuser}" -h "${_mhost}" -p'${_madminpwd}' -e 'CREATE DATABASE ${_db};'"
_upermq1="${mysql} -u "${_madminuser}" -h "${_mhost}" -p'${_madminpwd}' -e \"GRANT ${_dbrights} ON ${_db}.* TO ${_user}@localhost IDENTIFIED BY '${_pass}';\""
 
 
# run mysql queries
$_uamq
$_upermq1
 
 
# read remote host ip in a bash loop
# build queires to grant permission to all remote webserver or hosts via ip using the same username
IFS='|'
for  i in ${_dbremotehost}
do
	_upermq2="${mysql} -u "${_madminuser}" -h "${_mhost}" -p'${_madminpwd}' -e \"GRANT ${_dbrights} ON ${_db}.* TO ${_user}@${i} IDENTIFIED BY '${_pass}';\""
	$_upermq2
done

How Do I Use This Script?

Add a database called bar with username tom and password jerry, enter:
./script.sh bar tom jerry
Add a database called bar with username tom, password jerry and allow remote access from 192.168.1.5 and 192.168.1.11, enter:
./script.sh bar tom jerry '192.168.1.5|192.168.1.11'
Add a database called bar with username tom, password jerry, allow remote access from 192.168.1.5 & 192.168.1.11, and only grant SELECT,INSERT,UPDATE,DELETE, enter:
./script.sh bar tom jerry '192.168.1.5|192.168.1.11' 'SELECT,INSERT,UPDATE,DELETE'

#!/bin/bash
# A simply shell script to update all remote Redhat Enterprise Linux 5 / CentOS Linux 5 servers
# You must have ssh public and private key installed. This will save a lot of time if you
# have 5-7 servers. The last example shows how to login as a normal user and run sudo 
# to update the same.
# -------------------------------------------------------------------------
# Copyright (c) 2008 nixCraft project <http://cyberciti.biz/fb/>
# This script is licensed under GNU GPL version 2.0 or above
# -------------------------------------------------------------------------
# This script is part of nixCraft shell script collection (NSSC)
# Visit http://bash.cyberciti.biz/ for more information.
# -------------------------------------------------------------------------
 
# an array to store all ssh commands
hosts=(
	"ssh root@server1.nixcraft.in -p222 yum update -y"
	"ssh root@server2.nixcraft.in -p333 yum update -y"
	"ssh root@server3.nixcraft.in yum update -y"
	"ssh user1@192.168.1.254 -t sudo  '/usr/bin/yum update -y' "
      )
# simply run array item
for c in "${hosts[@]}"
do
	$c
done

See how to install ssh-keys .

#!/bin/bash
# A Sample Shell Script To Generate Mediawiki Wiki Software Google Sitemap Using PHP
# on server itself via cron.
# Warning: You need to customize this script before using it!
# -------------------------------------------------------------------------
# Copyright (c) 2008 nixCraft project <https://www.cyberciti.biz/>
# This script is licensed under GNU GPL version 2.0 or above
# -------------------------------------------------------------------------
# This script is part of nixCraft shell script collection (NSSC)
# Visit http://bash.cyberciti.biz/ for more information.
# -------------------------------------------------------------------------
 
# Path to wiki dir
BASE="/home/httpd/example.com/wiki"
 
# Wiki domain name
SERVER="http://www.example.com/"
 
# Path to actual sitemap file - change this 
OUT="${BASE}/sitemap-index-cbzwikibashportal.xml"
cd $BASE/wiki/maintenance
php generateSitemap.php --fspath="$BASE" --server="${SERVER}"
 
# patch it up replace example.com with actual domain name 
sed -i -e 's/sitemap-cbzwikibashportal-NS_[0-9]*-[0-9]*\.xml\.gz/http:\/\/www\.example\.com\/&/g' $OUT

Here is an updated version without need of using sed command:

#!/bin/bash
# Purpose: Shell Script To Generate Mediawiki Wiki Software Google Sitemap Using PHP
# -------------------------------------------------------------------------
# Copyright (c) 2017 nixCraft project <https://www.cyberciti.biz/>
# This script is licensed under GNU GPL version 2.0 or above
# -------------------------------------------------------------------------
# This script is part of nixCraft shell script collection (NSSC)
# Visit https://bash.cyberciti.biz/ for more information.
# -------------------------------------------------------------------------
 
## ATTENTION: Set me ##
# PHP cli path
_php=/usr/bin/php
# Path to script
_s=/var/www/html/wiki/maintenance/generateSitemap.php
# Memory limit 
_mem=50M
# Output folder
_fs=/var/www/html
# Given ID
_id=cbzwikibashportal
# Folder in which mediawiki installed
_url=https://bash.cyberciti.biz/wiki
# Wiki https url
_server=https://bash.cyberciti.biz
# Run it 
${_php} ${_s} --memory-limit=${_mem} --fspath=${_fs} --identifier=${_id} --urlpath=${_url} --server=${_server} --compress=yes
#!/bin/bash
# A simple shell script to clean (delete)  ~/.known_hosts file hostname entry.
# This is useful when remote server reinstalled or ssh keys are changed!
# -------------------------------------------------------------------------
# Copyright (c) 2007 nixCraft project <http://cyberciti.biz/fb/>
# This script is licensed under GNU GPL version 2.0 or above
# -------------------------------------------------------------------------
# This script is part of nixCraft shell script collection (NSSC)
# Visit http://bash.cyberciti.biz/ for more information.
# -------------------------------------------------------------------------
 
host="$1"
 
[[ $# -eq 0 ]] && { echo "Usage: $0 host.name.com"; exit 1;}
 
ips=$(host "$host" | awk -F'address' '{ print $2}' | sed -e 's/^ //g')
ssh-keygen -R "$host"
for i in $ips
do
	ssh-keygen -R "$i"
done

How Do I Use This Script?

Simply run it as follows:
./script.sh www-03.nixcraft.net.in

#!/bin/bash
# A simple shell script to backup dirs to tape drive.
# -------------------------------------------------------------------------
# Copyright (c) 2005 nixCraft project <http://cyberciti.biz/fb/>
# This script is licensed under GNU GPL version 2.0 or above
# -------------------------------------------------------------------------
# This script is part of nixCraft shell script collection (NSSC)
# Visit http://bash.cyberciti.biz/ for more information.
# -------------------------------------------------------------------------
MT=/bin/mt
TAR=/bin/tar
LOGGER=/usr/bin/logger
 
# What to backup. 
SOURCE_DIRS="/data /home /etc /root /www"
 
# Where to backup to.
TAPE="/dev/st0"
 
# log message
$LOGGER "Backing $SOURCE_DIRS to $TAPE @ $(date)"
 
# Rewind the tape
$MT -f $TAPE rewind
 
# Backup the files
$TAR czf $TAPE $SOURCE_DIRS
 
# Rewind and eject the tape
$MT -f $TAPE rewoffl
 
# log message 
$LOGGER "Backup finished @ $(date)"
#!/bin/bash
# A Shell Script To Convert All .flac Files To .MP3 Format
# Note: I found this script somewhere on usenet and I've modified it for my needs
METAFLAC=/usr/bin/metaflac
FLAC=/usr/bin/flac
ID3=/usr/bin/id3
LAME=/usr/bin/lame
FIND=/usr/bin/find
 
t=$(${FIND} . -type f  -iname "*.flac")
if [ "$t" == "" ]
then
	echo "There are no *.flac file in $(pwd) directory"
	exit 1
fi
 
for f in *.flac
do
	OUTF=$(echo "$f" | sed s/\.flac$/.mp3/g) 
	ARTIST=$(${METAFLAC} "$f" --show-tag=ARTIST | sed s/.*=//g)
	TITLE=$(${METAFLAC} "$f" --show-tag=TITLE | sed s/.*=//g)
	ALBUM=$(${METAFLAC} "$f" --show-tag=ALBUM | sed s/.*=//g)
	GENRE=$(${METAFLAC} "$f" --show-tag=GENRE | sed s/.*=//g)
	TRACKNUMBER=$(${METAFLAC} "$f" --show-tag=TRACKNUMBER | sed s/.*=//g)
	DATE=$(${METAFLAC} "$f" --show-tag=DATE | sed s/.*=//g)
	$FLAC -c -d "$f" | $LAME -m j -q 0 --vbr-new -V 0 -s 44.1 - "$OUTF" 
	$ID3 -t "$TITLE" -T "${TRACKNUMBER:-0}" -a "$ARTIST" -A "$ALBUM" -y "$DATE" -g "${GENRE:-12}" "$OUTF" 
done
#!/bin/sh
# A FreeBSD shell script to dump Filesystem with full and incremental backups to tape device connected to server.
# Tested on FreeBSD 6.x and 7.x - 32 bit and 64 bit systems.
# May work on OpenBSD / NetBSD.
# -------------------------------------------------------------------------
# Copyright (c) 2007 nixCraft project <http://www.cyberciti.biz/fb/>
# This script is licensed under GNU GPL version 2.0 or above
# -------------------------------------------------------------------------
# This script is part of nixCraft shell script collection (NSSC)
# Visit http://bash.cyberciti.biz/ for more information.
# ----------------------------------------------------------------------
LOGGER=/usr/bin/logger
DUMP=/sbin/dump
# FSL="/dev/aacd0s1a /dev/aacd0s1g"
FSL="/usr /var"
NOW=$(date +"%a")
LOGFILE="/var/log/dumps/$NOW.dump.log"
TAPE="/dev/sa0"
 
mk_auto_dump(){
	local fs=$1
	local level=$2
	local tape="$TAPE"
	local opts=""
 
	opts="-${level}uanL -f ${tape}"
        # run backup
	$DUMP ${opts} $fs
	if [ "$?" != "0" ];then
       		$LOGGER "$DUMP $fs FAILED!"
       		echo "*** DUMP COMMAND FAILED - $DUMP ${opts} $fs. ***"
	else
  		$LOGGER "$DUMP $fs DONE!"
	fi
}
 
dump_all_fs(){
	local level=$1
	for f in $FSL
	do
		mk_auto_dump $f $level
	done
}
 
init_backup(){
	local d=$(dirname $LOGFILE)
	[ ! -d ${d} ] && mkdir -p ${d}
}
 
init_backup
 
case $NOW in
	Mon)	dump_all_fs 0;;
	Tue)	dump_all_fs 1;;
	Wed)	dump_all_fs 2;;
	Thu)	dump_all_fs 3;;
	Fri) 	dump_all_fs 4;;
	Sat) 	dump_all_fs 5;;
	Sun) 	dump_all_fs 6;;
	*) ;;
esac > $LOGFILE 2>&1

How do I run this script?

Download this script and unzip in /root. Open script and customize tape device ($TAPE variable) and file systems ($FSL). Operator can run this script from a shell prompt:
# /root/tapebackup.sh
Or via a cron job:
@midnight /root/tapebackup.sh

#!/bin/bash
# Linux 64 bit kernel shell script to collect hardware errors via /var/log/mcelog
# and send email alert.
# -------------------------------------------------------------------------
# Copyright (c) 2008 nixCraft project <http://cyberciti.biz/fb/>
# This script is licensed under GNU GPL version 2.0 or above
# -------------------------------------------------------------------------
# This script is part of nixCraft shell script collection (NSSC)
# Visit http://bash.cyberciti.biz/ for more information.
# -------------------------------------------------------------------------
# Tested under RHEL and Debian Linux 64 bit version.
# mcelog must be installed. 
# See: http://www.cyberciti.biz/tips/linux-server-predicting-hardware-failure.html
LOGGER=/usr/bin/logger
FILE=/var/log/mcelog
AEMAIL="vivek@nixcraft.net.in"
ASUB="H/W Error - $(hostname)"
AMESS="Warning - Hardware errors found on $(hostname) @ $(date). See log file for the details /var/log/mcelog."
OK_MESS="$0 - OK: NO Hardware Error Found."
WARN_MESS="$0 - ERROR: Hardware Error Found."
 
die(){
	echo "$@"
	exit 999
}
 
warn(){
	echo $AMESS | email -s "${ASUB}" ${AEMAIL}
	$LOGGER "$WARN_MESS"
}
 
[ ! -f "$FILE" ] && die "Error - No $FILE exists or mcelog is not configured"
[ $(grep -c -i "hardware error" $FILE) -gt 0 ] && warn || $LOGGER $OK_MESS