Hi people!
Please, post here useful scripts which can help to do some useful or difficult operation on FreeBSD OS.
I will be the first:
Script which restarts the PPP daemon if connection is lost or daemon hung up.
The principe: ping remote ~100% uptime server to determine if Internet connection available.
ppp_check.sh
Next one - Firebird databases backup script.
Assumed that catalogues have the next structure:
- /Data
| | |
| | Database1 - DB1.FDB, DB2.FDB, ...
| |
| |
| Database2 - Data.FDB, Protocol.FDB, ...
The result of script work will be two archives in backup directory:
Database1-14-11-08_03_04.tar.gz
Database2-14-11-08_04_04.tar.gz
db_backup.sh
Please, post here useful scripts which can help to do some useful or difficult operation on FreeBSD OS.
I will be the first:
Script which restarts the PPP daemon if connection is lost or daemon hung up.
The principe: ping remote ~100% uptime server to determine if Internet connection available.
ppp_check.sh
Code:
#!/usr/bin/perl
use Net::Ping;
$server_to_ping="ya.ru";
sub check_ping_server
{
$host_alive=1;
$ping=Net::Ping->new('icmp');
if( $ping->ping($_[0]) ) { $host_alive=1;}
else {$host_alive=0;}
return $host_alive;
}
if(!check_ping_server($server_to_ping))
{
system("killall ppp");
system("sleep 2");
# Start PPP ADSL connection
system("/usr/sbin/ppp -quiet -ddial adsl");
# Send the message to
system("echo PPP restarted by timeout...");
}
exit;
Next one - Firebird databases backup script.
Assumed that catalogues have the next structure:
- /Data
| | |
| | Database1 - DB1.FDB, DB2.FDB, ...
| |
| |
| Database2 - Data.FDB, Protocol.FDB, ...
The result of script work will be two archives in backup directory:
Database1-14-11-08_03_04.tar.gz
Database2-14-11-08_04_04.tar.gz
db_backup.sh
Code:
#!/bin/sh
#----------------- DB Backup Script -------------------
#------------- by Dr_Phoenix Lutsk 2007 ---------------
# mount backup volume if needed
#mkdir /mnt/temp
mount /dev/ad2s1d /mnt/DB_BACKUP
clear
#---------------- Configure section -------------------
# Path to bases
db_path="/Data"
# Path to Backup directory
backup_path="/mnt/DB_BACKUP"
Set path to GBAK
gbak_path="/usr/local/bin/gbak" #
# Set date format to be attached to file name
current_date=`date "+%d-%m-%y_%H_%M"`
# Enable Logging to console 1-yes/0-no
enable_verbose=1
#------------------------------------------------------
# Creating backup directory if not exist
if [ ! -d $backup_path ]; then
mkdir $backup_path
fi
# Print short info about system
if [ $enable_verbose -gt 0 ]; then
host_name=`uname -i -m -s`
echo " ----> $host_name "
echo " ----> ${current_date} "
fi
# Begin main cycle of backuping :)
for i in `ls $db_path`
do
if [ -d $db_path/$i ]; then
for n in `ls $db_path/$i/`
do
if [ -f $db_path/$i/$n ]; then
if [ $enable_verbose -gt 0 ]; then
echo "Backuping file : < $n >"
echo "File Full Path : $db_path/$i/$n"
fi
# check if backup dir exist
if [ ! -d $backup_path/$i ]; then
mkdir $backup_path/$i
fi
# backuping current database file
$gbak_path -USER SYSDBA -PASS masterkey -b $db_path/$i/$n $backup_path/$i/$n.GBK -V -IG -Y $backup_path/$i/$n.log
fi
done
fi
# Creating GZIPped tar archive of current bases directory
if [ $enable_verbose -gt 0 ]; then
echo "----> GZipping Databases in $i ..."
fi
tar -czf $backup_path/$i-$current_date.tar.gz $backup_path/$i/*
# Clearing DB directory...
if [ $enable_verbose -gt 0 ]; then
echo "----> Clearing DB directory $i ..."
fi
rm $backup_path/$i/*
done