Posts Tagged ‘script’
The following is a simple (and very row) init script for Symantec Backup Exec Agent for Linux.
I wrote it because I really hate to execute script not registered with chkconfig on a production systems.
I’ve added the “status” function by checking if an executable called “beremote” is listening on 10000/tcp on IPv4 on the localhost.
If you are planning to run ralus on a different TCP port, please fix the script.
The following is the script :
#!/bin/sh
#
# RALUS Control Script
# chkconfig: 2345 99 01
# Description: Here is a little startup/shutdown script for RedHat/CentOS systems
#
# Author : Riccardo Riva
#
# description: Symantec Backup Exec Linux Agent Init Script
#
# Source function library.
. /etc/rc.d/init.d/functions
RETVAL=0
# See how we were called.
if [ ! -d /opt/VRTSralus ]
then
echo "Symantec Backup Exec Remote Agent missing /opt/VRTSralus [FAILED]"
exit 1
fi
if [ ! -d /etc/VRTSralus ]
then
echo "Symantec Backup Exec Remote Agent missing /etc/VRTSralus [FAILED]"
exit 1
fi
if [ ! -d /var/VRTSralus ]
then
echo "Symantec Backup Exec Remote Agent missing /var/VRTSralus [FAILED]"
exit 1
fi
CMD="$1"
case "$CMD" in
'start')
if [ -x /opt/VRTSralus/bin/beremote ]
then
echo -n "Starting Symantec Backup Exec Remote Agent "
rm -f /var/VRTSralus/ralus.pid
rm -f /var/VRTSralus/ralus.errpid
/opt/VRTSralus/bin/beremote >/var/VRTSralus/beremote.service.log 2>/var/VRTSralus/beremote.service.log &
PIDWAIT=30
while [ "$PIDWAIT" != "0" ]
do
if [ -f /var/VRTSralus/ralus.pid ]
then
PIDWAIT=0
else
PIDWAIT=$(($PIDWAIT-1))
echo -n "."
sleep 1;
fi
if [ -f /var/VRTSralus/ralus.errpid ]
then
PIDWAIT=0
fi
done
if [ -f /var/VRTSralus/ralus.pid ]
then
RETVAL=0
else
RETVAL=1
fi
echo
else
RETVAL=1
fi
if [ "$RETVAL" = "0" ]
then
echo "Starting Symantec Backup Exec Remote Agent: [ OK ]"
else
echo "Starting Symantec Backup Exec Remote Agent: [FAILED]"
fi
;;
'stop')
if [ -f /bin/grep ]
then
PID=`/bin/ps -e | /bin/grep beremote | /bin/sed -e 's/^ *//' -e 's/ .*//'`
else
PID=`/usr/bin/ps -e | /usr/bin/grep beremote | /usr/bin/sed -e 's/^ *//' -e 's/ .*//'`
fi
if [ "${PID}" != "" ]
then
echo -n "Stopping Symantec Backup Exec Remote Agent "
if [ -f /bin/pkill ]
then
/bin/pkill -15 beremote
else
/usr/bin/pkill -15 beremote
fi
RETVAL=$?
PIDWAIT=15
while [ "$PIDWAIT" != "0" ]
do
if [ -f /var/VRTSralus/ralus.pid ]
then
PIDWAIT=0
RETVAL=0
else
PIDWAIT=$(($PIDWAIT-1))
echo -n "."
sleep 1;
fi
done
echo
rm -f /var/VRTSralus/ralus.pid
rm -f /var/VRTSralus/ralus.errpid
else
RETVAL=1
fi
if [ "$RETVAL" = "0" ]
then
echo "Stopping Symantec Backup Exec Remote Agent: [ OK ]"
else
echo "Stopping Symantec Backup Exec Remote Agent: [FAILED]"
fi
;;
'restart')
$0 stop
$0 start
RETVAL=1
;;
'status')
if [ $(netstat -tulpan | grep beremote |grep 0.0.0.0:10000 | wc -l) -eq 1 ];
then
echo "Symantec Backup Exec Remote Agent running and listening on tcp port 10000"
else
echo "Symantec Backup Exec Remote Agent not running"
fi
;;
*)
echo "Symantec Backup Exec Remote Agent for Linux/Unix Servers"
echo "Usage: VRTSralus.init { start | stop | restart | status}"
RETVAL=1
;;
esac
exit $RETVAL
#
# -- End of file
You should download the file here : http://www.riccardoriva.com/shared-files/ralus_init_script.sh
Hope this help
Bye
Riccardo
Print This Post
If you use Postgrey (and you should do it) on your mail servers and you want to have some statistics on the amount of greylisted messages and other information, you should find useful the following script.
The scripts assume that you have installed Postgrey (http://postgrey.schweikert.ch/) on RHEL (http://www.redhat.com) or CentOS (http://www.centos.org).
If you are using other distros you may fix some path problems.
Create a file called “greylisting_statistics.sh” in your “/usr/local/bin” folder with the following content :
#!/bin/sh
LOGFILE=/tmp/greylist-statistics
YOURMAIL=you@yourdomain.com
echo -n "Total amount of GreyListed messages" > $LOGFILE
cat /var/log/maillog | /usr/sbin/postgreyreport --delay=300 >> $LOGFILE
echo -ne "\n" >> $LOGFILE
echo -ne "-------------------------------------\n" >> $LOGFILE
echo -ne "-------------------------------------\n" >> $LOGFILE
echo -n "Get only the top 20 sources getting greylisted out" >> $LOGFILE
cat /var/log/maillog | postgreyreport | awk '{print $1}' | sort | uniq -c | sort -nr | head -n20 >> $LOGFILE
echo -ne "\n" >> $LOGFILE
echo -ne "-------------------------------------\n" >> $LOGFILE
echo -ne "-------------------------------------\n" >> $LOGFILE
echo -n "Get a list of the top 20 email address that the greylisted sources are sending email to" >> $LOGFILE
cat /var/log/maillog | postgreyreport | awk '{print $4}' | sort | uniq -c | sort -nr | head -n20
echo -ne "\n" >> $LOGFILE
echo -ne "-------------------------------------\n" >> $LOGFILE
echo -ne "-------------------------------------\n" >> $LOGFILE
cat $LOGFILE | mail -s "Greylisting Statistics of `hostname` for `date +%Y-%m-%d`" $YOURMAIL
#--- End of file ---
Assign to it the correct ownership and permission by running :
chmod 700 /usr/local/bin/greylisting_statistics.sh chown root:root /usr/local/bin/greylisting_statistics.sh
Schedule the execution using “crontab -e” and adding the following line to have a daily based statistics :
59 23 * * * /usr/local/bin/greylisting_statistics.sh
Hope this help
Bye
Riccardo
Print This Post
This simple How-To will explain a raw and dirt method to daemonize to http manager for ARECA Raid Controller.
If you have this controller on your system you should find in the bundled CD-ROM the following folder :
root PACKAGES -> Linux -> CLI -> version -> i386 -> cli32 PACKAGES -> Linux -> CLI -> version -> x86-64 -> cli32 PACKAGES -> Linux -> HTTP -> version.x.y.x -> i386 -> archttp32 PACKAGES -> Linux -> HTTP -> version.x.y.x -> x86-64 -> archttp32
Create a folder in your /usr/local folder called “areca” e and create into it two folders called “http” and “cli”
Copy the “cli32″ and “archttp32″ executable file that match your architecture (i386 or x86-64) in the specified folder, so you should have something similar :
[root@relay ~]# ls -lahR /usr/local/areca/ /usr/local/areca/: total 20K drwxr-xr-x 4 root root 4.0K Feb 12 10:28 . drwxr-xr-x 13 root root 4.0K Feb 12 10:26 .. dr-xr-xr-x 2 root root 4.0K Feb 12 10:27 cli dr-xr-xr-x 2 root root 4.0K Feb 12 10:42 http /usr/local/areca/cli: total 1.6M dr-xr-xr-x 2 root root 4.0K Feb 12 10:27 . drwxr-xr-x 4 root root 4.0K Feb 12 10:28 .. -r-xr-xr-x 1 root root 1.6M Dec 26 2008 cli32 /usr/local/areca/http: total 1.6M dr-xr-xr-x 2 root root 4.0K Feb 12 10:42 . drwxr-xr-x 4 root root 4.0K Feb 12 10:28 .. -r-xr-xr-x 1 root root 1.6M Dec 26 2008 archttp32 -rw-r--r-- 1 root root 91 Feb 12 10:42 archttpsrv.conf
Create a new file called “areca” in your /etc/init.d folder with the following content :
#!/bin/sh
#
# Startup script for the ARECA RAID CONTROLLER HTTP Monitor
#
# chkconfig: 2345 62 38
# description: HTTP Tools to monitor and manage ARECA RAID Controller
#
# processname: archttp32
# config: none
# lockfile: /var/lock/subsys/archttp32
#
# Author: Riccardo Riva
# WebSite: http://www.riccardoriva.com
#
# This script is realeased under the terms of the GPL.
#====================================================================
# Source function library
. /etc/init.d/functions
RETVAL=0
start() {
echo -n $"Starting ARECA HTTP Manager: "
daemon /usr/local/areca/http/archttp32 2>&1>/dev/null &
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/archttp32
return $RETVAL
}
stop() {
echo -n $"Stopping ARECA HTTP Manager: "
killproc archttp32
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/archttp32
return $RETVAL
}
restart() {
stop
start
}
reload() {
echo -n $"Reloading ARECA HTTP Manager: "
killproc archttp32 -ALRM
RETVAL=$?
echo
return $RETVAL
}
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status archttp32
;;
restart)
restart
;;
condrestart)
[ -f /var/lock/subsys/archttp32 ] && restart || :
;;
reload)
reload
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart|reload}"
exit 1
esac
exit $?
#---End of file---
Assing to it the right permission and ownership
chmod 755 /etc/init.d/areca chown root:root /etc/init.d/areca
You should also place in the executable file folder the configuration file, called “archttp32srv.conf” with the following content :
[GENERAL] BindingIp=0.0.0.0 HTTPPort=81 SMTPPort=25 ScanPci=YES ScanRs232=NO ScanInband=NO ConnInfo=NO [MAIL] Server=MAIL.SERVER.IP.ADDRESS # Please Change ME Sender=SENDERNAME # Please Change ME SenderMail=SENDERMAIL # Please Change ME Account= Password= MailToName1=RECEIVERNAME # Please Change ME MailToName2= MailToName3= MailToName4= MailAddr1=RECEIVERMAIL # Please Change ME MailAddr2= MailAddr3= MailAddr4= EvtLevel=3 NotifyForNoEvent=NO [SNMP] TrapIp1=SNMP.SERVER.IP.ADDRESS # Please Change ME TrapIp2=0.0.0.0 TrapIp3=0.0.0.0 TrapPort1=162 TrapPort2=162 TrapPort3=162 Community=public EvtLevel=3
And configure it for startup at boot time.
chkconfig areca on
I know it very dirt, but I had no time left to search a better way, maybe in the future.
Hope this help
Bye
Riccardo
Print This Post
The following is a simple (and very row) init script for Bacula 5.0.
I wrote it because I really hate to execute script not registered with chkconfig on a production systems.
The following is the script :
#!/bin/sh
#
# BACULA Control Script
# chkconfig: 2345 99 01
# Description: Here is a little startup/shutdown script for RedHat/CentOS systems
#
# processname: bacula
# bacula-dir pidfile: /var/run/bacula-dir.9101.pid
# bacula-fd pidfile: /var/run/bacula-fd.9102.pid
# bacula-sd pidfile: /var/run/bacula-sd.9103.pid
#
# bacula-dir config: /etc/bacula/bacula-dir.conf
# bacula-fd config: /etc/bacula/bacula-fd.conf
# bacula-sd config: /etc/bacula/bacula-sd.conf
#
# Author : Riccardo Riva
#
# description: It comes by night and sucks the vital essence from your computers.
#
SCRIPTDIR=/etc/bacula
#
# Disable Glibc malloc checks, it doesn't help and it keeps from getting
# good dumps
MALLOC_CHECK_=0
export MALLOC_CHECK_
# Source function library.
. /etc/rc.d/init.d/functions
RETVAL=0
# See how we were called.
case "$1" in
start)
[ -x ${SCRIPTDIR}/bacula-ctl-sd ] && ${SCRIPTDIR}/bacula-ctl-sd $1 $2
[ -x ${SCRIPTDIR}/bacula-ctl-fd ] && ${SCRIPTDIR}/bacula-ctl-fd $1 $2
[ -x ${SCRIPTDIR}/bacula-ctl-dir ] && ${SCRIPTDIR}/bacula-ctl-dir $1 $2
;;
stop)
# Stop the FD first so that SD will fail jobs and update catalog
[ -x ${SCRIPTDIR}/bacula-ctl-fd ] && ${SCRIPTDIR}/bacula-ctl-fd $1 $2
[ -x ${SCRIPTDIR}/bacula-ctl-sd ] && ${SCRIPTDIR}/bacula-ctl-sd $1 $2
[ -x ${SCRIPTDIR}/bacula-ctl-dir ] && ${SCRIPTDIR}/bacula-ctl-dir $1 $2
;;
restart)
$0 stop
sleep 2
$0 start
;;
status)
[ -x ${SCRIPTDIR}/bacula-ctl-sd ] && ${SCRIPTDIR}/bacula-ctl-sd status
[ -x ${SCRIPTDIR}/bacula-ctl-fd ] && ${SCRIPTDIR}/bacula-ctl-fd status
[ -x ${SCRIPTDIR}/bacula-ctl-dir ] && ${SCRIPTDIR}/bacula-ctl-dir status
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
exit 1
;;
esac
exit $RETVAL
#--- End of file ---
You should download the script from here :
http://www.riccardoriva.com/shared-files/bacula_init_script.sh
Hope this help
Bye
Riccardo
Print This Post
This post will explain how to create users and mailboxes for Zarafa.
I’ve tested it with CentOS 5.4 X86_64 and Zarafa 6.30.9 but it will fit with nearly all installation.
First of all you have to create a test file with all the users you want to create, providing the following information :
- username
- password
- email address
- name
- surname
For example :
johndoe password johndoe@example.com John Doe
janedoe password janedoe@example.com Jane Doe
Save the text file whatever you want.
The following is the shell script that read your text file and create all Zarafa users.
If you use the script, all the users will not be administrator, so you have to create manually and administrator.
#!/bin/bash # Written by Matteo Predieri - m.predieri_AT_damsistemi_DOT_it # Written by Riccardo Riva - r.riva_AT_damsistemi_DOT_it # # Simple and raw script to create zarafa users and mailboxes from a test file # # The full fill-in of the text file is mandatory # So fill in both "Name" and "Surname" with the following syntax # # username password email name surname # USERS_LIST=/tmp/userlists.txt ZARAFA_CMD=/usr/bin/zarafa-admin LOGFILE=/tmp/zara_user_creation.log echo "Zarafa User Creation Log" > $LOGFILE what="user"; for item in $( cat $USERS_LIST ); do if [ $what = "user" ]; then user=$item; what="passwd"; else if [ $what = "passwd" ]; then passwd=$item; what="email"; else if [ $what = "email" ]; then email=$item; what="name"; else if [ $what = "name" ]; then name=$item; what="surname"; else surname=$item; echo "Result in creating User: $user, with password: $passwd, with email address: $email with Full Name: $name $surname :" >> $LOGFILE FULLNAME="'$name $surname'" $ZARAFA_CMD -c $user -p $passwd -e $email -f "$FULLNAME" -a0 >> $LOGFILE echo -ne "-------------------------------\n" >> $LOGFILE what="user"; fi fi fi fi done # --- End of file ---
You’ve done.
Hope this help
Bye
Riccardo
Print This Post
This is a simple shell script that count all files in a local directory and all subdir. It doesn’t care what extention the file has, it will just recursively go through each directory and count any files within it, plus recurse into any more directories it finds. Give it as a parameter the directory you want to count.
#!/bin/sh
NUMBER=0
count ()
{
for temporary in $1/* ; do
if [ -d "$temporary" ] ; then
count "$temporary"
elif [ -f "$temporary" ] ; then
NUMBER=$(($NUMBER+1))
fi
done
}
count $1
echo "I found $NUMBER files, in the specified folder and all subfolders"
I know you should also did it with
ls -R | wc -l
but it was a shell exercise.
Hope this help
Bye
Riccardo
Print This Post
The following is a simple memo on how to use the three powerful tools above.
It will not be a complete guide, and you should find only a small part of the possible use, but this would be a review only for the most common use (for me) and would not go a deep dive.
Grep
grep : print lines matching a pattern (equals “grep -G” which is the default)
egrep : equals grep -E (interpret extended regexp)
grep -n : line numbered
grep -i : ignore case
grep -c : count matches
grep -v : print non-matching lines
grep -r : recursivity, read all files under each directory
grep pattern file.txt
Will display the lines containing the pattern
grep -c pattern file.txt
Will display how many lines contain the pattern
grep -i pattern file.txt
Will display the lines containing the pattern regardless of the case
grep -A 1 -B 1 pattern output.txt
Will print the one line before (-B) and one line after (-A) the matching pattern
Awk
awk '{ print $0 }' file
Output the content of the file
awk '{ print $2 }' file
Output the second field of data of the file, space is the default separator
awk -F ':' '{ print $2 }' file
Same but separator is “:”
Sed
cat file | sed -e 's/old_pattern/new_pattern/g'
sed would replace old_pattern by new_pattern in the output
cat file | sed -e '4,10s/old_pattern/new_pattern/g'
sed would replace old_pattern by new_pattern in the output between line 4 and 10
cat file | sed '/pattern/d'
Delete a pattern
cat file | sed '/pattern/!d'
Delete everything but the pattern (this equals grep “string_to_remove”)
Hope this help
Bye
Riccardo
Print This Post
This would be another little memo of all the most used (by me) Input/output redirections and pipes.
As other times this would not be a complete guide, and would not go into the deep.
The base :
Standard input (stdin) : 0
Standard output (stdout) : 1
Error output (stderr) : 2
> : output redirection
< : input redirection
>> : append output
| : pass the output to the next utility
|| : execute the next command if the previous failed
&& : execute the next command only if the previous has succeded
Examples :
cat file.txt > /tmp/file.txt
If file.txt exists, the output will be written in /tmp/file.txt
If file.txt doesn’t exist, the error message will be output to the screen while nothing will be written to /tmp/file.txt (but the file will be created if not existing)
cat file.txt 2> /tmp/error_file.txt > /tmp/file.txt
In this case the error message would be written to /tmp/error_file.txt if the file doesn’t exist
cat file.txt 2> /tmp/error_file.txt >> /tmp/file.txt
The error output would still go in error_file.txt while the standard output would be APPENDED to file.txt
cat file1 > file2
Will copy the content of file1 to file2
cat > file3 Hello world
Will write “Hello world” to file3
[/bash]wc < file.txt > count_file.txt[/bash]
This would count the number of lines, words and bytes in file.txt (”wc < file.txt”) and output the result to count_file.txt
Several ways of counting lines etc. :
$ wc file.txt
7 2 17 file.txt
$ wc < file.txt
7 2 17
$ cat file.txt | wc
7 2 17
ls -l test10 > file.txt 2>&1
This would output anything under file.txt
<code>ls -l test10 2>&1 | mail -s “output in a mail” address@domain.com
Any output in a mail
Hope this help
Bye
Riccardo
Print This Post
This pot will show some useful example on how to use the “grep” command to find an occurency in a Linux system.
Grep searches the input file (or files) for lines containing a match to a given pattern. Whe an occurency math it copies to standard input the line with the occurrency or you should rediret the output whatever you want.
You should simpy invoke grep with the following :
grep 'STRING' filename
The above is a very simple use f grep, infact it check only in a single file searching all the occurency for ‘STRING’.
You should also use it to find ‘STRING1 STRING2′ in all files in your current location, running ::
grep 'STRING1 STRING2' *
or if you want to make the same research on a given path (i.e. all files in /etc) you should use :
grep 'STRING1 STRING2' /etc/*
Notice the use of single quotes; This are not essential but in this example it was required since the name contains a space. Double quotes could also have been used in this example.
In case of too much occurency you should redirect the output o a file to make more comfortable the research, for example using :
grep 'STRING 1 STRING2" /etc/* > /tmp/grepresults.txt
The following is a simple list for Grep Regular Expression
grep can search for complicated pattern to find what you need using some special characters used to create a regular expression:
`.’ The period `.’ matches any single character.
`?’ The preceding item is optional and will be matched at most once.
`*’ The preceding item will be matched zero or more times.
`+’ The preceding item will be matched one or more times.
for example, a regular expression search would be :
grep "\<[A-Za-z].*" file
The search above will search for any word which begins with a letter upper or lower case.
For more details check :
man grep
Hope this help
Bye
Riccardo
Print This Post
This should be an example on how to configure a simple HA (High Availability) without VMware Virtual Center in a two hosts configuration. It requires shared storage between the two hosts, and it works great letting save you a lot of money. Obviously it not provide all Virtual Center features, but it works great. When I have some time to waste, I will add also email notification capabilities. The script will check the “other hosts” with some ICMP packet, and if the host don’t answer for 14 times, it will register all the other host’s VMs and power it on automatically, then wait for 16 seconds and execute all tasks again for paranoid sysadmin. I’ll schedule the job execution every minutes, so it will run twice every minute. I think the script is just pretty commented, but if you have any questions, feel free to ask. The only thing you should do will be export in a file all the VMs registered on the two hosts, and put it on both hosts, for doing this you should simply run :
vmware-cmd -l
and copy and paste the output on a text file, or if you are a script addicted, you should execute on the first host :
vmware-cmd -l | sed 's/\ /\\ /g' > /root/esx01
and on the second host :
vmware-cmd -l | sed 's/\ /\\ /g' > /root/esx02
then you should copy the VMs list between the host, using for example scp, with the following syntax :
usage: scp [-pqrvBC1246] [-F config] [-S program] [-P port] [-c cipher] [-i identity] [-l limit] [-o option] [[user@]host1:]file1 [...] [[user@]host2:]file2
And finally here’s the script :
#!/bin/bash
#
# Manual VMware HA script for two host configuration
# You should keep updated the /root/esx0X file on both hosts if you add or remove VMs
#
# Script created by Riccardo Riva
# Script created 2009/06/29
#
# ESX01 – 10.10.10.11 (VMs list on /root/esx01 on both hosts)
# ESX02 – 10.10.10.12 (VMs list on /root/esx02 on both hosts)
#
# Schedule this script to be executed every minutes by executing ‘crontab -e’ and add the following
# * * * * * /somewhere/this_script.sh
#
# Remeber to assign executable permissions to this script by running ‘chmod +x this_script.sh’
# Modify only the following variables according to your installation
HOSTtoCHECK=10.10.10.11
HOSTtoCHECK_VMs=/root/esx01
# Do not change nothing below this line
if ! ping -c 14 $HOSTtoCHECK > /dev/null; then
while read line
do
vmware-cmd -s register “${line}” && vmware-cmd “${line}” start ;
done < $HOSTtoCHECK_VMs
fi
sleep 16
if ! ping -c 14 $HOSTtoCHECK > /dev/null; then
while read line
do
vmware-cmd -s register “${line}” && vmware-cmd “${line}” start ;
done < $HOSTtoCHECK_VMs
fi
Hope this help
Bye
Riccardo
Print This Post
The following is a simple script to monitor a Software Raid configuration on a Linux System.
It execute a /proc/mdstat check to search a ‘blocks_’ occurency which indicates problems on the Raid system and in case of match it notify the system administrator with a mail message.
It should be very useful for non-presidiated system, even if I always prefer Hardware Raid.
#!/bin/bash # # Script created by Riccardo Riva # http://www.riccardoriva.com # # It check a Software Raid subsystem and notify by mail any occurency problem # Define variable LOG_FILE=/tmp/raid-check.log SYSTEM=`uname --nodename` MAILTO='systemadmin@mail.exp' # Checking /proc/mdstat cat /proc/mdstat | grep 'blocks.*_' > $LOG_FILE # Define function in case of problems detected if [ $? -eq 0 ] then echo "The $SYSTEM system has RAID failures on it." >> $LOG_FILE echo "Below is the output from /proc/mdstat" >> $LOG_FILE echo "===========================================" >> $LOG_FILE cat /proc/mdstat >> $LOG_FILE echo "===========================================" >> $LOG_FILE cat $LOG_FILE | mail -s 'URGENT: RAID disk failure detected' $MAILTO fi # Deleting log file rm -f >> $LOG_FILE # Exit exit 0
Save the file above as /usr/local/bin/raidcheck.sh and assign to it correct permission and ownership with the folowing :
chmod 700 /usr/local/bin/raidcheck.sh chown root:nobody /usr/local/bin/raidcheck.sh
Change the email address variable with a real email address who will receive the notification.
You should now schedule the script execution at every time interval you want (i.e. twice a day, or hourly if you are paranoic).
Remember that is better to be paranoic that have a degraded system with unrecoverable data.
Hope this help
Bye
Riccardo
Print This Post
This simple init script is for daemonize freshclam (Clamd Antivirus Updater) on RHEL or CentOS.
Create a brand new file called freshclam in /etc/init.d/ with the following content :
#!/bin/sh
#
# Startup script for the Clam AntiVirus Update Tool
#
# chkconfig: 2345 62 38
# description: freshclam is an update daemon for Clam AV database.
#
# processname: freshclam
# config: /etc/freshclam.conf
# pidfile: /var/run/clamav/freshclam.pid
#
# Author: Riccardo Riva
# WebSite: http://www.riccardoriva.com
#
# This script is realeased under the terms of the GPL.
#====================================================================
# Source function library
. /etc/init.d/functions
# Get network config
. /etc/sysconfig/network
test -f /etc/freshclam.conf || exit 0
RETVAL=0
start() {
echo -n $"Starting freshclam: "
daemon /usr/bin/freshclam -d -p /var/run/clamav/freshclam.pid
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/freshclam
return $RETVAL
}
stop() {
echo -n $"Stopping freshclam: "
killproc freshclam
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && rm -f /var/run/clamav/freshclam.pid /var/lock/subsys/freshclam
return $RETVAL
}
restart() {
stop
start
}
reload() {
echo -n $"Reloading DB: "
killproc freshclam -ALRM
RETVAL=$?
echo
return $RETVAL
}
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status freshclam
;;
restart)
restart
;;
condrestart)
[ -f /var/lock/subsys/freshclam ] && restart || :
;;
reload)
reload
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart|reload}"
exit 1
esac
exit $?
Assign to it corect ownership and permission :
chown root:root /etc/init.d/freshclam chmod 755 /etc/init.d/freshclam
Test if the scripts works correctly on your system with the following commands :
service freshclam start service freshclam stop service freshclam restart service freshclam reload service freshclam condstart
If all works fine you should add freshclam to the automatic startup services with the following command :
chkconfig freshclam on
Hope this help
Bye
Riccardo
Print This Post
This post will show a simple perl tool to manage (delete) one or more message in Postfix mail queue.
The main script to use is delete-mailq.pl
Create a file called delete-mailq.pl in /usr/local/bin with the the following content :
</pre>
#!/usr/bin/perl -w
# Postfix mailq cleanup utility
$REGEXP = shift || die "no email-adress given (regexp-style, test.*\@example.com)!";
@data = qx</usr/sbin/postqueue -p>;
for (@data) {
if (/^(\w+)\*?\s/) {
$queue_id = $1;
}
if($queue_id) {
if (/$REGEXP/i) {
$Q{$queue_id} = 1;
$queue_id = "";
}
}
}
open(POSTSUPER,"|postsuper -d -") || die "couldn't open postsuper" ;
foreach (keys %Q) {
print POSTSUPER "$_\n";
};
close(POSTSUPER);
<pre>
Assign it correct ownership and permission with the following commands :
</pre> chown root:root /usr/local/bin/delete-mailq.pl chmod 700 /usr/local/bin/delete-mailq.pl <pre>
You should run the file directly passing the variables directly on comand line, or you should (and I prefer) create another file in /usr/local/bin called clean-mailq.sh with the following content :
</pre> #!/bin/sh if [ -z $1 ] then echo "Insert the E-Mail address or a string to find it in mailqueue and delete it" read STRING else STRING=$1 fi /usr/local/bin/delete_mailq.pl $STRING <pre>
Assign it correct ownership and permission with the following commands :
</pre> chown root:root /usr/local/bin/clean-mailq.sh chmod 700 /usr/local/bin/clean-mailq.sh <pre>
At this time, you should execute /usr/local/bin called clean-mailq.sh as root and pass the value to find and to delete from mail queue.
Hope this help
Bye
Riccardo
The following wuold be a simpe example to define a function in a bash shell script.
You should use it to execute the same set of command more time in a single shell script simply calling the function name and avoiding to type it all the time.
The following is a very simple example :
</pre>
#!/bin/sh
# Start define function "function01"
# Function name
function01 ()
# Function content
{
# Put the content here
}
# Stop define function
# insert whatever you want here
# call function
function01
# insert whatever you want here
# call function
function01
<pre>
Hope this help
Bye
Riccardo
Print This Post
This post will assume you just have a fully functional working mail server and you want do download all emails from some mailboxes located on another mail server, tipically located on your service provider’s one.
This post guide will guide you to install and configure fetchmail and use it with your RHEL 5 or newer, you should use all the following information also with CentOS without change any line, but you shoud adapt it to every Linux distribution.
Most likely you want to setup fetchmail to download your domain mailbox over pop3 and inject into Postfix (or whatever you use as MTA).
To install fetchmail use the following :
yum install fetchmail -y
You should decide how to use fetchmail :
* as a daemon
* as a cron scheduled task
This post will show a backup script used to create copies for a server running Oracle 10.2, some application server like FourJS and JBoss and some custom application written in java.
The backup process is divided in some parts :
- Variable declaration and export
- Oracle export and compress
- Data folder export and compress
- Application Server export and compress
- Tape writing of all compress file
- Tape checking
- Mail logging
This post assume you have the following enviroments, if you have something different you should only change variable declaration and comment some lines to have this script works.
- Oracle SID : DB01
- Oracle main folder : /oracle/product/10.2/db_1
- Oracle user/password : system/system
- DATA main folder to backup : /data
- APPSERVER main Folder : /appsrv
- Main backup folder : /data/backup
- Tape device : /dev/st0
Read the rest of this entry »
This post will show a simple post installation script for VMware ESX server to avoid a lot of manual configuration and some reboot to apply changes.
In the script I’m going to :
- Add an SSH banner text
- Unload unuseful modules (i.e. vmfs2 support)
- Adjust some settings for SAN access
- Increase Service Console Memory reservation to 800 MB
- Configure networking with portgroup and vlan
- Set mgmg.local as the local domain
- Add to hosts file all other esx
- Configure NTP
This script assume you have 4 esx hosts (esx01.mgmt.local, esx02.mgmt.local and so on), and you have 4 phisical NICs on each host.
Assume also you want to create networking for the following networks :
- LAN (with VLAN ID 1) for Internal Network Virtual Machines
- DMZ (with VLAN ID 10) for Virtual Machines accessible from externals network
- TS (with VLAN ID 11) for Terminal Service Virtual Machines
- LAB (with VLAN ID 12) for LAB VMs
- TEST (with VLAN ID 99) for Testing purpose
When using Oracle 10g Release 2, a call to “dbstart" might result (perhaps every time) in the following error message:
Failed to auto-start Oracle Net Listener using /ade/vikrkuma_new/oracle/bin/tnslsnr
This is due to an internal path in the dbstart script.
To correct this, edit the “$ORACLE_HOME/bin/dbstart” script and replace the following line :
ORACLE_HOME_LISTNER=/ade/vikrkuma_new/oracle
With this:
ORACLE_HOME_LISTNER=$ORACLE_HOME
The dbstart script shold now start the listener as expected.
Automating Shutdown and Startup (10.2)
Automating Startup and Shutdown (10.1)
Automating Database Startup and Shutdown (9.2)
Hope this help
Bye
Riccardo
The following is a very simple init script for Oracle on Red Hat Enterprise Linux.
I’m using it successfully in RHEL 5.2 but you can use it on other systems, only double check the various path.
#!/bin/sh
#
# ORACLE Control Script
# chkconfig: 3 80 20
#
# Description: Here is a little startup/shutdown script for Oracle 10g on RedHat systems
#
# Author : Riccardo Riva
#
# Source LSB function library.
[ -f /lib/lsb/init-functions ] && . /lib/lsb/init-functions
#Assuming have Oracle installed on :
# /oracle/product/10.2.0/db1
ORACLE_HOME=/oracle/product/10.2.0/db_1
#Assuming have “oracle” user
ORACLE_OWNER=oracle
# Edit this with your DB instance name
ORACLE_DB=DB_INSTANCE_NAME
if [ ! -f $ORACLE_HOME/bin/dbstart ]
then
echo “Oracle startup: cannot start”
exit
fi
case “$1″ in
’start’)
# Start the Oracle databases:
su – $ORACLE_OWNER -c “$ORACLE_HOME/bin/lsnrctl start”
su – $ORACLE_OWNER -c $ORACLE_HOME/bin/dbstart
;;
’stop’)
# Stop the Oracle databases:
su – $ORACLE_OWNER -c $ORACLE_HOME/bin/dbshut
su – $ORACLE_OWNER -c “$ORACLE_HOME/bin/lsnrctl stop”
;;
’status’)
if su -l $ORACLE_OWNER -c “${ORACLE_HOME}/bin/tnsping ${ORACLE_DB} >/dev/null 2>&1″
then
exit 0
else
exit 1
fi
;;
esac
Create this script and put it in your /etc/init.d/ directory
Make this script excutable
Use “chkconfig” to set the startup or the shutdown for this script in the desired runlevels.
Hope this help avoid wasting time
Bye
Riccardo
This has been written to detail how to generate a CPU load in a Virtual Machine..
Some tipical scenarios where you may wish to generate CPU load within a virtual machine include stress testing an ESX server and triggering DRS VirtualMachines migrations for demonstration or testing purposes.
The simple scripts below can be used to generate CPU load in Windows and Unix\Linux virtual machines and will run continuously until terminated.
- Windows Virtual Machines
The VBscript script below should be saved as cpubusy.vbs.
Start it by double clicking it and terminate it by ending the wscript.exe process in Task Manager.
Dim goal
Dim before
Dim x
Dim y
Dim i
goal = 2181818
Do While True
before = Timer
For i = 0 to goal
x = 0.000001
y = sin(x)
y = y + 0.00001
Next
y = y + 0.01
Loop
- Unix\Linux Virtual Machines
The Perl script below should be saved as cpubusy.pl
Start it by opening a terminal window, changing to the directory where it is saved and typing the following:
chmod 744 cpubusy.pl
./cpubusy.pl
Terminate it pressing CTRL-C.
#!/usr/bin/perl
$goal = 2181818;
while (TRUE) {
for ($i=0; $i<=$goal; $i++) {
$x = 0.000001;
$y = sin($x);
$y = $y + 0.00001;
}
next;
$y = $y + 0.01;
}
Hope this help
Bye
Riccardo























