mdalerts, mdcheck

Here below are two useful Bash scripts to monitor mdadm software RAIDs on a GNU/Linux system.

The mdalerts script is intented to output events detected by mdadm –monitor, thus it should be set in the PROGRAM line of the mdadm.conf file in order to be run by mdmadm. Arguments are passed by mdmadm.
When mdadm detect any event, the script output the event details (using echo) and also send a notification (using notify-send) to desktop applets (panels and notifiers).

The mdcheck script is intented to check and output the status of mdadm devices. It check and output (using echo) the status of mdmadm RAID devices and also send a notification (using notify-send) to desktop applets (panels and notifiers) when a device is not clean.

For both scripts, the mdadm devices list should be configured inside the code. Superuser rights are not required.

For more details and settings, please look inside the code. See also: man mdadm and man mdadm.conf.

The mdalerts and the mdcheck are free software, released under the terms of the GNU General Public License version 3 or (at your option) any later version.

Comments, suggestions and bug reports are welcome.

mdalerts

#!/bin/bash
#
# NAME
# 	mdalerts
# 
# SYNOPSIS
# 	Output (using echo and notify-send) events detected by mdadm monitor.
# 
# DESCRIPTION
# 	This script is intented to output events detected by 'mdadm --monitor', 
# 	thus it should be set in the PROGRAM line of the 'mdadm.conf' file in order 
# 	to be run by mdmadm. Arguments are passed by mdadm.
# 	When mdadm detect any event, the script output the event details (using 
# 	echo) and also send a notification (using notify-send) to desktop applets 
# 	(panels and notifiers).
# 	The mdadm devices list should be configured inside the script itself.
# 	The script do not need superuser rights.
# 	See also: 'man mdadm' and 'man mdadm.conf'.
# 
# VERSION
# 	1.0 (03/06/2017)
# 
# AUTHOR
# 	Alexus
# 	
# COPYRIGHT
# 	Copyright (c) 2016+ Alexus
# 	License: GPLv3+ (GNU GPL version 3 or later)
# 	This program is free software: you can redistribute it and/or modify
# 	it under the terms of the GNU General Public License as published by
# 	the Free Software Foundation, either version 3 of the License, or
# 	(at your option) any later version.
# 	This program is distributed in the hope that it will be useful,
# 	but WITHOUT ANY WARRANTY; without even the implied warranty of
# 	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# 	GNU General Public License for more details.
# 	You should have received a copy of the GNU General Public License
# 	along with this program.  If not, see .
# 	

## @file
## @name       mdalerts
## @brief      Output events detected by 'mdadm --monitor'
## @author     alexus
## @copyright  GPLv3+
## @version    1.0
## @date       03/06/2017
## @pre        mdadm, notify-send
## @note       Do not need superuser rights
## @param      string  $1  event (passed by mdadm)
## @param      string  $2  md device (passed by mdadm)
## @param      string  $3  related component device (possibly passed by mdadm)
## @return     int     1   parent command was not mdadm

# Declarations
declare -i alarm_ms  # milliseconds
declare    parent_cmd='mdadm'
declare    msg

# ### Script configuration ###
alarm_ms=10000
# ### End script configuration ###

# Check parent command
if [[ $parent_cmd != "$(ps -o comm= $PPID)" ]] ; then echo -e "ERROR! This script should be run by mdadm.\nSet it in the PROGRAM line of the 'mdadm.conf' file.\See: 'man mdadm'.\n"; exit 1 ;fi

# Outputs and notifications
msg="Event: $1, Device: $2"
if [[ -n "$3" ]] ; then msg+=", Component: $3" ; fi
echo "MD MONITOR EVENT!" "$msg$"
notify-send -u "normal" -t "$alarm_ms" "MD MONITOR EVENT!" "$msg"

# Exit
exit 0

mdcheck

#!/bin/bash
#
# NAME
# 	mdcheck
# 
# SYNOPSIS
# 	Check and output mdadm devices status.
# 
# DESCRIPTION
# 	This script is intented to check and output the status of mdadm devices.
# 	The script check and output (using echo) the status of mdadm devices and 
# 	also send a notification (using notify-send) to desktop applets (panels and 
# 	notifiers) when a device is not clean.
# 	The mdadm devices list should be configured inside the script itself.
# 	The script do not need superuser rights.
# 	See also: 'man mdadm' and 'man mdadm.conf'.
# 
# VERSION
# 	1.0 (03/06/2017)
# 
# AUTHOR
# 	Alexus
# 	
# COPYRIGHT
# 	Copyright (c) 2016+ Alexus
# 	License: GPLv3+ (GNU GPL version 3 or later)
# 	This program is free software: you can redistribute it and/or modify
# 	it under the terms of the GNU General Public License as published by
# 	the Free Software Foundation, either version 3 of the License, or
# 	(at your option) any later version.
# 	This program is distributed in the hope that it will be useful,
# 	but WITHOUT ANY WARRANTY; without even the implied warranty of
# 	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# 	GNU General Public License for more details.
# 	You should have received a copy of the GNU General Public License
# 	along with this program.  If not, see .
# 	

## @file
## @name       mdcheck
## @brief      Output the status of mdadm devices for monitoring applets
## @author     alexus
## @copyright  GPLv3+
## @version    1.0
## @date       03/06/2017
## @pre        mdadm, notify-send
## @note       Do not need superuser rights
## @return     int  1  one or mode mdadm devices is not clean working

# Declarations
declare raid
declare raid_status='ok'
declare raids
declare unit_state
declare unit_recovery
declare unit_resync
declare out_pre
declare out_post
declare -i alarm_ms  # milliseconds
declare -i exitCode=0

# ### Script configuration ###
raids="md1 md2 md3 md4"
alarm_ms=5000
out_pre='| MD:'
out_post=''
# ### End script configuration ###

# Checking...
for raid in $raids ; do
	mdstat="$(grep -A2 ^$raid "/proc/mdstat")"
	if [[ $(echo -e $mdstat | grep '\[.*F.*\]') ]] ; then unit_state="failed" ; raid_status='KO'
	elif [[ $(echo -e $mdstat | grep '\[.*_.*\]') ]] ; then unit_state="degraded" ; raid_status='KO'
	else unit_state="working" ; fi
	unit_recovery=$(echo -e $mdstat | grep recovery | awk '{print $16}')
	unit_resync=$(echo $mdstat | grep resync | awk '{print $16}')
	if [[ $raid_status == "KO" ]] ; then 
		notify-send -u "critical" -t "$alarm_ms" "MD RAID ALARM!" "${0##*/} - Device '$raid' has $unit_state unit(s). Recovery: $unit_recovery. Resync: $unit_resync."
		exitCode=1
	fi
done

# Output
echo "$out_pre$raid_status$out_post"

# Exit
exit $exitCode

hddetach

The hddetach script is a Bash script to safely detach (umount+sync+stop) an external hard disk on a GNU/Linux system.

The only argument $1 must be the label of a volume (partition) in the hard disk (e.g. MYDATA) which is mounted on the file system.
The script gets the device path (e.g. /dev/sdb) of the disk which holds the volume labeled $1 and then try to umount all the disk’s volumes, sync the internal cache and stop the disk and finally to removes it from the system (delete volume icon(s), file manager, desktop etc.).
Superuser rights are requested.

The hddetach script is free software, released under the terms of the GNU General Public License version 3 or (at your option) any later version.

Comments, suggestions and bug reports are welcome.

#!/bin/bash
#
# NAME
# 	hddetach
# 
# SYNOPSIS
# 	hddetach 
# 
# DESCRIPTION
# 	This script safely detach an external hard disk.
# 	The only argument $1 must be the label of one volume (partition) of 
# 	the hard disk (e.g. MYDATA) which is mounted on the file system.
# 	The script gets the device path (e.g. /dev/sdb) of the disk which holds 
# 	the volume labeled $1 and then try to umount all the disk's volumes, sync 
# 	the internal cache and stop the disk and finally to removes it from the 
# 	system (delete volume icon(s), file manager, desktop etc.).
# 	Superuser rights are requested.
# 	
# AUTHOR
# 	Alexus
# 	
# COPYRIGHT
# 	Copyright (c) 2014+ Alexus
# 	License: GPLv3+ (GNU GPL version 3 or later)
# 	This program is free software: you can redistribute it and/or modify
# 	it under the terms of the GNU General Public License as published by
# 	the Free Software Foundation, either version 3 of the License, or
# 	(at your option) any later version.
# 	This program is distributed in the hope that it will be useful,
# 	but WITHOUT ANY WARRANTY; without even the implied warranty of
# 	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# 	GNU General Public License for more details.
# 	You should have received a copy of the GNU General Public License
# 	along with this program.  If not, see http://www.gnu.org/licenses/.

# Function desc
desc() {
echo ""
echo "${0##*/}: safely detach an external hard disk"
echo "$COPY, version $VER $DATE"
echo ""
}

# Function usage
usage() {
echo "  Usage: ${0##*/} "
echo "  : label of one volume (partition) of the disk to detach"
press_key
exit 1 
}

# Function press_key
press_key() { echo ""; read -rsn 1 -p "Press any key to exit..."; echo ""; echo "";}

# Function umount_all
umount_all() { local dev="$DEVNAME"; mount | cut -d' ' -f1 | while read vol; do if [[ $vol =~ /dev/$dev. ]]; then umount "$vol"; fi; done; } 

# Intro
VER="1.0"
DATE="18/11/2014"
COPY="Copyright (c) 2014+ Alexus, GPLv3+"
desc

# Check argument
if [[ $# -eq 0 ]]; then echo "  *** Fatal error: Missing argument."; usage; fi

# Get disk device path and device name
LABEL=$1
PATTERN="\[$LABEL\]"
DEVPATH=$(mount -l | grep $PATTERN | cut -d' ' -f1)
DEVNAME=$(echo $DEVPATH | cut -d'/' -f3 | grep -Eo "[[:alpha:]]*")

# Check disk presence
if [[ ${#DEVNAME} -eq 0 ]]; then echo "  *** Fatal error: Not found any device with a volume labeled '$LABEL'."; usage; fi

# Ask user confirmation
echo "  Disk /dev/$DEVNAME holding a volume labeled '$LABEL' will be detached."
echo "  Superuser rights might be requested."
read -p "  Continue? (y/N) " -n 1 -r
if [[ ! "$REPLY" =~ ^[Yy]$ ]]; then echo "  Nothing done."; press_key; exit 0; fi
echo ""

# Unmount partitions on disk
echo "  Trying to umount all the volumes on $DEVPATH..."
umount_all

# Detaches (sync, stop, forget) disk and exit
echo "  Trying to sync, stop and forget $DEVNAME disk..."
sudo sdparm --command=sync /dev/$DEVNAME
sudo sdparm --command=stop /dev/$DEVNAME
sudo sh -c "echo 1 >/sys/block/$DEVNAME/device/delete"
echo "  Done."
press_key
exit 0

Back again

Hey!

Still alive and back again.
Next days I will try to publish some useful (?) Bash scripts.

GNU IceCat 14.0.1 prebuild binaries tarball

Image: GNU IceCat logo.

A tarball containing the prebuild binaries of GNU IceCat 14.0.1, compiled by me for a GNU/Linux i386 system based on Debian stable, is available at the GNU IceCat downloads page of this site.

Language files should be available at the Gnuzilla FTP site: ftp://ftp.gnu.org/gnu/gnuzilla/lang/.

Also see how to install GNU IceCat tarballs.

Enjoy!

GNU IceCat 13.0.1 prebuild binaries tarball

Image: GNU IceCat logo.

A tarball containing the prebuild binaries of GNU IceCat 13.0.1, compiled by me for a GNU/Linux i386 system based on Debian Squeeze, is available at the GNU IceCat downloads page of this site.

Language files should be available at the Gnuzilla FTP site: ftp://ftp.gnu.org/gnu/gnuzilla/lang/.

Also see how to install GNU IceCat tarballs.

Enjoy!

GNU IceCat 10.0 prebuild binaries tarball

Image: GNU IceCat logo.

A tarball containing the prebuild binaries of GNU IceCat 10.0, compiled by me for a GNU/Linux i386 system based on Debian Squeeze, is available at the GNU IceCat downloads page of this site.

Also see how to install GNU IceCat tarballs.

Enjoy!

How to install GNU IceCat tarballs

To install a generic prebuild binaries tarball package just unpack it in a folder (which is usually already defined decompressing the file itself) and copy or move it (also renaming it if necessary) in a suitable position, usually into your /home directory or in the /opt system directory. Might also be necessary to change the permissions of the directory and/or the contained files (see the instructions which usually come with the package).

I suggest this way to install the GNU IceCat prebuild binaries tarball packages provided by this website:

prepare the system

  • update your system (this is not strictly necessary, but it is better before removing or installing software):

    $ sudo apt-get update
    $ sudo apt-get upgrade
    
  • if you are updating a previous version already installed in /opt/icecat, then it is better to rename this folder before to install the new package:

    $ sudo mv /opt/icecat /opt/icecat-old
    

    so that you might eventually delete it later (be very careful using the rm command!):

    $ sudo rm -R /opt/icecat-old
    

download and install

(notice: below you should substitute x.y.z with the actual version number of the tarball package to install)

  • download the wanted GNU IceCat x.y.z tarball package from the GNU IceCat downloads page of this site
  • rename the downloaded package to fix the file extension (this is need as, due to bugs in WP, the file extensions of the tarballs have been changed from ‘.tar.gz’ to ‘tar_.gz’):

    $ mv icecat-x.y.z.tar_.gz icecat-x.y.z.tar.gz
    
  • unpack it (you will have a icecat-x.y.z folder):

    $ tar -jxvf icecat-x.y.z.tar.gz
    
  • move the icecat-x.y.z folder to the /opt system directory, renaming it at the same time to icecat:

    $ sudo mv icecat-x.y.z /opt/icecat
    
  • now you can finally run IceCat:

    $ /opt/icecat/icecat
    

Enjoy!

GNU IceCat 9.0.1 prebuild binaries tarball

Image: GNU IceCat logo.

A tarball containing the prebuild binaries of GNU IceCat 9.0.1, compiled by me for a GNU/Linux i386 system based on Debian Squeeze, is available at the GNU IceCat downloads page of this site.

Enjoy!

Update: Also see how to install GNU IceCat tarballs.

Back

Hey!
After a long time… still alive and back here!

fSimpleX 3.0

fSimpleX version 3.0!

Until August 2011, NoBlogs.org was using the LifeType blogging platform. So this blog was using fSimpleX, a free (GNU GPLv3) template for the LifeType blogging platform by al3xu5/dotcommon (based on the fSimple theme by Fredrik Fahlstad).

The fSimpleX 3.0 template I was using is available at the fSimpleX downloads page of this site.

Release notes (fSimpleX 3.0, 17/06/2010):

  • Layout fully revisited and code optimized! Now pages have a liquid 2 columns right-menu layout which comes with a lot of improvements:
    • percentage widths
    • no CSS hacks
    • SEO (Search Engine Optimisation) friendly (the the left-hand main page comes first, then the right column)
    • full length column background colours
    • no images
    • no JavaScript
    • resizable text compatible
    • no quirks mode (XML declaration to display correctly in older versions of IE is not required)
    • no IE conditional comments
    • high browser compatibility
    • valid XHTML 1.0 strict
    • valid CSS 2.1
  • Better graphics (css)
  • Better images (from the gnome theme image set)
  • Fixed a lot of minor code bugs

Enjoy!