October 2017

Bash script to change the Zoneminder's state

Script to change the Zoneminder's state via crontab and to check at boot if the correct state is set. zoneminder_state.sh: #!/bin/bash zmdbuser=`cat /etc/zm/zm.conf | grep ZM_DB_USER | awk -F= '{print $2}' | tr -d ' '` zmdbpass=`cat /etc/zm/zm.conf | grep ZM_DB_PASS | awk -F= '{print $2}' | tr -d ' '` runstate=`mysql -N -B -u$zmdbuser -p$zmdbpass zm -e "select Name from States where isActive=1 LIMIT 1;"` alarmedstate='Armed' #echo $runstate # for debug only function state { if [ "$runstate" != "$alarmedstate" ]; then /usr/bin/zmpkg.pl ${1} else exit fi } function boot { hour=$(date +%H) daystate='Day' nightstate='Night' hour_day_start='8' hour_day_end='24' if [ "$runstate" == "$alarmedstate" ]; then exit elif (( $hour_day_start <= 10#$hour && 10#$hour < $hour_day_end ));...

Linux: bash script to backup the OS

This is a really simple command/script to backup via rsync an entire Linux OS: #!/bin/bash rsync -aAXv --delete --exclude={"/dev/","/home/","/lost+found/","/media/","/mnt/","/proc/","/run/","/sys/","/tmp/"} / /media/Data_Backup/OS/ Source: wiki.archilinux.com

Bash script to backup a Drupal site with an SQLite database

Script to backup via ftp a Drupal site that uses a database SQLite and to then archive it. backup_site.sh: #!/bin/bash # HOST='ftp.site.com' USER='username' PASSWORD='password' BACKUPDIR=$HOME'/backup/site' WORKINGDIR='/tmp' DBPATH='sites/default/files' DBNAME='.ht.sqlite' cd $WORKINGDIR wget -m --preserve-permissions --user=$USER --password=$PASSWORD ftp://$HOST sqlite3 $HOST/$DBPATH/$DBNAME "VACUUM;" while [ $? -ne 0 ]; do wget -m --preserve-permissions --user=$USER --password=$PASSWORD ftp://$HOST/$DBPATH/$DBNAME sqlite3 $HOST/$DBPATH/$DBNAME "VACUUM;" done mkdir -p "$BACKUPDIR" 7z a -mhe -p$PASSWORD "$BACKUPDIR/$HOST-`date +%Y%m%dT%H%M`.7z" "$HOST" rm -r $HOST The script can been executed via cron in this way: 0 20 1 * * bin/backup_site.sh >> bin/cron.log 2>&1