Initial import

This commit is contained in:
Christoph 2017-02-21 02:14:51 +01:00
commit 6846bebd83
9 changed files with 799 additions and 0 deletions

23
bundle_certs.sh Executable file
View File

@ -0,0 +1,23 @@
#!/bin/sh
#
# Convert PEM Certificate to ca-bundle.crt format
#
# example:
# ./bundle_certs.sh myserver.crt >myserver.chain
# ./bundle_certs.sh intermediate.crt >>myserver.chain
# ./bundle_certs.sh root.crt >>myserver.chain
test ! $1 && printf "Usage: `basename $0` certificate" && exit 1
# Friendly Name and Underline Friendly Name with equal signs
openssl x509 -in $1 -text -noout | sed -e 's/^ *Subject:.*CN=\([^,]*\).*/\1/p;t c' -e 'd;:c' -e 's/./=/g'
# Output Fingerprint and swap = for :
openssl x509 -in $1 -noout -fingerprint | sed -e 's/=/: /'
# Output PEM Data:
echo 'PEM Data:'
# Output Certificate
openssl x509 -in $1
# Output Certificate text swapping Certificate with Certificate Ingredients
openssl x509 -in $1 -text -noout | sed -e 's/^Certificate:/Certificate Ingredients:/'

54
clean_log_files.sh Executable file
View File

@ -0,0 +1,54 @@
#!/usr/bin/env bash
system_log_dir="/var/log"
if [ ! -d "$system_log_dir" ]; then
exit 1
fi
cd $system_log_dir
for i in ${system_log_dir}/*.log ; do
> $i
done
[[ -f "syslog" ]] && > syslog
[[ -f "messages" ]] && > messages
[[ -f "mail.err" ]] && > mail.err
[[ -f "mail.info" ]] && > mail.info
[[ -f "mail.warn" ]] && > mail.warn
[[ -f "faillog" ]] && > faillog
[[ -f "debug" ]] && > debug
[[ -f "wtmp" ]] && > wtmp
[[ -f "lastlog" ]] && > lastlog
[[ -f "dmesg" ]] && > dmesg
[[ -f "btmp" ]] && > btmp
[[ -f "fsck/checkroot" ]] && > fsck/checkroot
[[ -f "fsck/checkfs" ]] && > fsck/checkfs
[[ -f "apt/history.log" ]] && > apt/history.log
[[ -f "apt/term.log" ]] && > apt/term.log
[[ -f "${system_log_dir}/named/bind.log" ]] && > ${system_log_dir}/named/bind.log
[[ -f "${system_log_dir}/named/query.log" ]] && > ${system_log_dir}/named/query.log
[[ -f "${system_log_dir}/named/axfr.log" ]] && > ${system_log_dir}/named/axfr.log
[[ -f "${system_log_dir}/named/dnssec.log" ]] && > ${system_log_dir}/named/dnssec.log
if [[ -d "${system_log_dir}/openvpn" ]] ; then
for i in "${system_log_dir}/openvpn/*.log" ; do
rm $i
done
fi
if [[ -d "${system_log_dir}/unifi" ]] ; then
for i in "${system_log_dir}/unifi/*.log" ; do
rm $i
done
fi
exit 0

193
disk-space_usage.sh Executable file
View File

@ -0,0 +1,193 @@
#!/usr/bin/env bash
SUMMERY=false
right_tabstop=30
warn (){
echo ""
echo -e " [ Warning ] $*"
echo ""
}
function usage() {
echo
[ -n "$1" ] && echo -e "Error: $1\n"
cat<<EOF
Usage: `basename $0` [-oq] <dir>
Prints out a summary of disk space usage for a given directory.
The Output contains also the amount of diskspace usage of the
subdirectories.
Options:
-o <directory>
A summary file will be stored in the given directory. The filename contains
the directory name of the determined directory and also a timestamp in human
readable form.
-q
Suppresses the output to stdout. Only useful in conjunction with "-o"
EOF
exit 1
}
_be_quiet=false
_output_to_file=false
while getopts o:q opt ; do
case $opt in
q) _be_quiet=true
;;
o) _output_to_file=true
if [ -d "$OPTARG" ]; then
_out_dir=$OPTARG
else
usage "Output directory not found"
fi
;;
h) usage
;;
\?) usage
esac
done
shift `expr $OPTIND - 1`
if [ $# -eq 0 ]; then
usage "Missing parameter for \"<dir>\""
elif [ $# -gt 1 ]; then
usage "To many parameters given"
fi
base_dir=$1
if [ ! -d $base_dir ]; then
usage "Directory \"$base_dir\" not found!"
fi
if $_output_to_file ; then
_out_file="${_out_dir}/`basename \"$base_dir\"`_space_usage.`date +%Y%m%d-%H%M`"
touch $_out_file
fi
if $_be_quiet && ! $_output_to_file ; then
warn "You have told me to be quiet (-q), but gives no output directory."
exit
fi
## - print out
## -
outnl(){
echo X\\c > /tmp/shprompt$$
if [ `wc -c /tmp/shprompt$$ | awk '{print $1}'` -eq 1 ]; then
if $_output_to_file ; then
echo -e "$*\\c" >> $_out_file
fi
if ! $_be_quiet ; then
echo -e "$*\\c" 1>&2
fi
else
if $_output_to_file ; then
echo -e "$*" >> $_out_file
fi
if ! $_be_quiet ; then
echo -e "$*" 1>&2
fi
fi
rm /tmp/shprompt$$
}
outnl ""
outnl "Disk Space Usage Directory \"$base_dir\":"
outnl ""
cd $backup_base_dir
## - Read list of (sub)directories inside $base_dir into
## - an array.
## -
dir_list_arr=()
while IFS='' read -r -d '' _dir; do
dir_list_arr+=($_dir);
done < <(find $base_dir -mindepth 1 -maxdepth 1 -type d -print0)
## - Sort the array
## -
dir_list_sorted_arr=()
readarray -t dir_list_sorted_arr < <(for a in "${dir_list_arr[@]}"; do echo "$a"; done | sort)
for _dir in "${dir_list_sorted_arr[@]}"; do
## - Determin space usage of $_dir
## -
_out_du=$(du -sh "$_dir")
_space=`echo ${_out_du} | cut -d ' ' -f1`
_host=`basename "$_dir"`
## - Formatted Output
## -
## - Determin number of signs between directory name
## - and directory size
## -
_strlen=${#_host}
_count_blank=`expr $right_tabstop - $_strlen`
_str_blanks=""
while [ $_count_blank -gt 2 ]; do
_str_blanks="${_str_blanks}."
_count_blank=`expr $_count_blank - 1`
done
_str_blanks="${_str_blanks}: "
_outstring="\t${_host}${_str_blanks}${_space}"
outnl "$_outstring"
done
## - Summary
## -
if $SUMMERY ; then
## - overall usage of directory $$base_dir
## -
_overall_usage=`du -sh $base_dir | awk '{print$1}'`
## - Print Summary Line
## -
_strlen=${#_overall_usage}
_count_blank=`expr $right_tabstop + $_strlen`
_str_blanks=""
_outstring="\t"
while [ $_count_blank -gt 0 ]; do
_str_blanks="${_str_blanks}. "
_count_blank=`expr $_count_blank - 1`
_outstring="${_outstring}="
done
outnl ""
outnl "$_outstring"
## - Print Summary
## -
_strlen=${#base_dir}
_count_blank=`expr $right_tabstop - $_strlen`
_str_blanks=""
while [ $_count_blank -gt 0 ]; do
_str_blanks="${_str_blanks} "
_count_blank=`expr $_count_blank - 1`
done
_outstring="\t${base_dir}${_str_blanks}${_overall_usage}"
outnl "$_outstring"
fi
outnl
exit 0

190
disk-space_usage.sh.00 Executable file
View File

@ -0,0 +1,190 @@
#!/usr/bin/env bash
right_tabstop=30
warn (){
echo ""
echo -e " [ Warning ] $*"
echo ""
}
function usage() {
echo
[ -n "$1" ] && echo -e "Error: $1\n"
cat<<EOF
Usage: `basename $0` [-oq] <dir>
Prints out a summary of disk space usage for a given directory.
The Output contains also the amount of diskspace usage of the
subdirectories.
Options:
-o <directory>
A summary file will be stored in the given directory. The filename contains
the directory name of the determined directory and also a timestamp in human
readable form.
-q
Suppresses the output to stdout. Only useful in conjunction with "-o"
EOF
exit 1
}
_be_quiet=false
_output_to_file=false
while getopts o:q opt ; do
case $opt in
q) _be_quiet=true
;;
o) _output_to_file=true
if [ -d "$OPTARG" ]; then
_out_dir=$OPTARG
else
usage "Output directory not found"
fi
;;
h) usage
;;
\?) usage
esac
done
shift `expr $OPTIND - 1`
if [ $# -eq 0 ]; then
usage "Missing parameter for \"<dir>\""
elif [ $# -gt 1 ]; then
usage "To many parameters given"
fi
base_dir=$1
if [ ! -d $base_dir ]; then
usage "Directory \"$base_dir\" not found!"
fi
if $_output_to_file ; then
_out_file="${_out_dir}/`basename \"$base_dir\"`_space_usage.`date +%Y%m%d-%H%M`"
touch $_out_file
fi
if $_be_quiet && ! $_output_to_file ; then
warn "You have told me to be quiet (-q), but gives no output directory."
exit
fi
## - print out
## -
outnl(){
echo X\\c > /tmp/shprompt$$
if [ `wc -c /tmp/shprompt$$ | awk '{print $1}'` -eq 1 ]; then
if $_output_to_file ; then
echo -e "$*\\c" >> $_out_file
fi
if ! $_be_quiet ; then
echo -e "$*\\c" 1>&2
fi
else
if $_output_to_file ; then
echo -e "$*" >> $_out_file
fi
if ! $_be_quiet ; then
echo -e "$*" 1>&2
fi
fi
rm /tmp/shprompt$$
}
outnl ""
outnl "Disk Space Usage Directory \"$base_dir\":"
outnl ""
cd $backup_base_dir
## - Read list of (sub)directories inside $base_dir into
## - an array.
## -
dir_list_arr=()
while IFS='' read -r -d '' _dir; do
dir_list_arr+=($_dir);
done < <(find $base_dir -mindepth 1 -maxdepth 1 -type d -print0)
## - Sort the array
## -
dir_list_sorted_arr=()
readarray -t dir_list_sorted_arr < <(for a in "${dir_list_arr[@]}"; do echo "$a"; done | sort)
for _dir in "${dir_list_sorted_arr[@]}"; do
## - Determin space usage of $_dir
## -
_out_du=$(du -sh "$_dir")
_space=`echo ${_out_du} | cut -d ' ' -f1`
_host=`basename "$_dir"`
## - Formatted Output
## -
## - Determin number of signs between directory name
## - and directory size
## -
_strlen=${#_host}
_count_blank=`expr $right_tabstop - $_strlen`
_str_blanks=""
while [ $_count_blank -gt 2 ]; do
_str_blanks="${_str_blanks}."
_count_blank=`expr $_count_blank - 1`
done
_str_blanks="${_str_blanks}: "
_outstring="\t${_host}${_str_blanks}${_space}"
outnl "$_outstring"
done
## - Summary
## -
## - overall usage of directory $$base_dir
## -
_overall_usage=`du -sh $base_dir | awk '{print$1}'`
## - Print Summary Line
## -
_strlen=${#_overall_usage}
_count_blank=`expr $right_tabstop + $_strlen`
_str_blanks=""
_outstring="\t"
while [ $_count_blank -gt 0 ]; do
_str_blanks="${_str_blanks}. "
_count_blank=`expr $_count_blank - 1`
_outstring="${_outstring}="
done
outnl ""
outnl "$_outstring"
## - Print Summary
## -
_strlen=${#base_dir}
_count_blank=`expr $right_tabstop - $_strlen`
_str_blanks=""
while [ $_count_blank -gt 0 ]; do
_str_blanks="${_str_blanks} "
_count_blank=`expr $_count_blank - 1`
done
_outstring="\t${base_dir}${_str_blanks}${_overall_usage}"
outnl "$_outstring"
outnl
exit 0

9
os-upgrade.sh Executable file
View File

@ -0,0 +1,9 @@
#!/usr/bin/env bash
apt-get update
apt-get upgrade -y
apt-get clean
#postsuper -d ALL
exit 0

94
reboot_gateway Executable file
View File

@ -0,0 +1,94 @@
#!/usr/bin/env bash
## - On gateway server adjust sudoers file. Edit that
## - file by typing 'visudo' as root user.
## -
## - Add lines:
## - Cmnd_Alias REBOOT = /sbin/reboot
## - Cmnd_Alias UTILS = /bin/cp
## --- Some functions
## ---
echononl(){
echo X\\c > /tmp/shprompt$$
if [ `wc -c /tmp/shprompt$$ | awk '{print $1}'` -eq 1 ]; then
echo "$*\\c" 1>&2
else
echo -e -n "$*" 1>&2
fi
rm /tmp/shprompt$$
}
clear
company="Sprachenatelier Berlin"
gateway_ip=192.168.92.254
echo ""
echo -e "\tRestart $company Gateway"
echo ""
echo -e "Choose type of internet connection\n"
_opt1="DSL"
_opt2="VDSL"
_opt3="Abort program"
options=("$_opt1" "$_opt2" "$_opt3" )
PS3="Choose type of connection [1-3]: "
select opt in "${options[@]}"
do
case $opt in
$_opt1)
line=DSL
break
;;
$_opt2)
line=VDSL
break
;;
$_opt3)
echo -e "\n\tExiting now..\n"
exit 1
break
;;
*)
echo ""
echo "!! INVALID CHOISE !!"
echo ""
echo "1) $_opt1"
echo "2) $_opt2"
echo "3) $_opt3"
echo ""
;;
esac
done
ssh sysadm@$gateway_ip sudo /bin/cp /etc/network/interfaces.$line /etc/network/interfaces
ssh sysadm@$gateway_ip sudo /bin/cp /etc/ppp/peers/dsl-provider.$line /etc/ppp/peers/dsl-provider
echo ""
echo "--"
echo ""
echo ""
reboot=
while [ "X${reboot}" = "X" ]; do
echononl "Reboot Gateway? [yes/no]: "
read reboot
if [ "$reboot" != "yes" -a "$reboot" != "no" ];then
echo ""
echo "Please type \"yes\" for rebooting gateway system, \"no\" to abort"
echo ""
fi
done
if [ "$reboot" = "yes" ]; then
ssh sysadm@$gateway_ip sudo /sbin/reboot
echo -e "\n\tRestarting Gateway \"$company\" with $line line..\n"
else
echo ""
echo -e "\tWarning!"
echo -e "\tThe Gateway System is now configured for \"$line\". Reconecting/Rebooting"
echo -e "\twill fail, if internet line isn't connected via \"$line\"."
echo
fi
exit

52
reconnect_inet.sh Executable file
View File

@ -0,0 +1,52 @@
#!/usr/bin/env bash
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
device=$1
device=${device:="ppp0"}
provider=$2
provider=${provider:="dsl-provider"}
reconnect() {
## - shutdown dsl line
## -
ifdown $provider >/dev/null 2> /dev/null
sleep 2
## - If shutdown wasn't successful, kill the concerning pid
## -
PID=`ps ax | grep pppd | grep -v grep | grep $provider | awk '{print$1}'`
while [ -n "$PID" ]; do
kill -9 $PID
sleep 2
PID=`ps ax | grep pppd | grep -v grep | grep $provider | awk '{print$1}'`
done
## - Bring up dsl line
## -
_date=`date +"%d.%m.%Y %H:%M:%S"`
ifup $provider >/dev/null 2> /dev/null
sleep 2
#echo -n "`hostname --long` reconnected at `date +\"%d.%m.%Y %H:%M:%S\"`"
declare -i _number=0
ptp_addr=`ifconfig $device 2>/dev/null | grep -e "P-[tz]-P" | cut -d":" -f3 | cut -d " " -f1`
while [ -z "$ptp_addr" ]; do
[[ $_number -eq 90 ]] && break
sleep 1
ptp_addr=`ifconfig $device 2>/dev/null | grep -e "P-[tz]-P" | cut -d":" -f3 | cut -d " " -f1`
let _number++
done
if [ "X$ptp_addr" = "X" ] ; then
echo ""
echo "[ ERROR ]: reconnection host `hostname --long` failed at `date +\"%d.%m.%Y %H:%M:%S\"`"
fi
}
reconnect
exit 0;

89
swap_usage.sh Executable file
View File

@ -0,0 +1,89 @@
#!/usr/bin/env bash
function usage() {
echo
[ -n "$1" ] && echo -e "Error: $1\n"
cat<<EOF
Usage: ` basename $0` < -a | -A |-p <program name to filter output> >
Shows swap-usage either for all programs (-a/-A) or filtered for
a given program name (-p program_name).
Options:
-A
Show swap-usage for all running processes, even if no swap
is in use. Not realy useul, but gives a short overview about
running processes.
-a
Show swap-usage for all running processes that have swap space allocated.
-p <programm_name>
Show swap-usage for all processes of the given program name.
`basename $0` -p amavisd
EOF
exit 1
}
[ $# -eq "0" ] && usage "wrong number of arguments"
all=false
while getopts Aahp: opt ; do
case $opt in
A) all=true ;;
a) ;;
h) usage ;;
p) filter_prog_name=$OPTARG ;;
\?) usage
esac
done
shift `expr $OPTIND - 1`
[ $# -eq "0" ] || usage "wrong number of arguments"
declare -i total_prog=0
declare -i total=0
for _dir in `find /proc/ -maxdepth 1 -type d | egrep "^/proc/[0-9]"` ; do
#_pid=`basename $_dir`
_pid=`echo $_dir | cut -d "/" -f 3`
_prog_name=`ps -p $_pid -o comm --no-headers`
if [ -n "$filter_prog_name" ]; then
[ "$_prog_name" != "$filter_prog_name" ] && continue
fi
for _mem in `grep Swap $_dir/smaps 2>/dev/null| awk '{print$2}'` ; do
[ $_mem -eq 0 ] && ! $all ] && continue
let total_prog=$total_prog+$_mem
let tmp=$tmp+$_pid
done
[ $total_prog -eq 0 ] && ! $all && continue
echo "PID = $_pid - Swap used: $total_prog kb - ( $_prog_name )"
let total=$total+$total_prog
total_prog=0
done
if [ $total -eq 0 ]; then
if [ -z $filter_prog_name ] ; then
echo -e "\n\tNo swap space alocated.\n"
else
echo -e "\n\tNo swap space alocated by \"$filter_prog_name\" processes.\n"
fi
else
if [ -z $filter_prog_name ] ; then
echo -e "\n\tTotal allocated swap space: $total kb\n"
else
echo -e "\n\tAllocated swap space by \"$filter_prog_name\" processes: $total kb\n"
fi
fi
exit 0

95
test_email.sh Executable file
View File

@ -0,0 +1,95 @@
#!/usr/bin/env bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin
datum=`/bin/date +"%d.%m.%Y"`
email_to=$1
email_to=${email_to:="root"}
email_from="`whoami`@`hostname --long`"
file=/tmp/mail_ip-up$$
if [ -f /etc/ddclient.conf ]; then
# Check, if this is the interface used for DynDNS (there could be other pppds
eval `sed -n 's/\(if=[^ ,]*\)/\1/p' /etc/ddclient.conf`
## - check if interface used by dydns is present
## -
for _IFACE in `ifconfig | grep -e"^ppp" | cut -d" " -f1 `; do
if [ "$_IFACE" = "$if" ];then
PPP_IFACE=$_IFACE
break
fi
done
fi
if [ "$PPP_IFACE" ] ; then
PPP_REMOTE=`ifconfig $PPP_IFACE 2>/dev/null | grep -e "P-[tz]-P" | cut -d":" -f3 | cut -d " " -f1`
PPP_LOCAL=`ifconfig $PPP_IFACE 2>/dev/null | grep -e "P-[tz]-P" | cut -d":" -f2 | cut -d " " -f1`
else
INET_INTERFACE=`netstat -rn | grep -e"^0.0.0" | awk '{print$8}'`;
EXTERN_IP=`ifconfig | grep -A 1 $INET_INTERFACE | grep "inet Adresse" | cut -d":" -f2 | cut -d " " -f1`
fi
DNS_SERVER=`cat /etc/resolv.conf | grep -v -e"^#" | grep nameserver | cut -d " " -f2`
DEFAULT_GW=`netstat -rn | grep -e"^0.0.0" | awk '{print$2}'`;
echo "" > $file
echo " *******************************************************" >> $file
echo " *** This is an autogenerated mail ***" >> $file
echo "" >> $file
echo -e "\tHost.........................: `hostname --long`" >> $file
echo "" >> $file
echo -e "\tSender.......................: $email_from" >> $file
echo "" >> $file
if [ "$PPP_IFACE" ] ; then
echo -e "\tInterface name...............: $PPP_IFACE" >> $file
echo -e "\tLocal IP number..............: $PPP_LOCAL" >> $file
echo -e "\tPeer IP number..............: $PPP_REMOTE" >> $file
if [ "$USEPEERDNS" ] && [ "$DNS1" ] ; then
echo -e "\tNameserver 1.................: $DNS1" >> $file
if [ "$DNS2" ] ; then
echo -e "\tNameserver 2.................: $DNS2" >> $file
fi
fi
else
if [ "$INET_INTERFACE" ];then
echo -e "\tInterface extern.............: $INET_INTERFACE" >> $file
echo "" >> $file
declare -i i=1
for ip in $EXTERN_IP ; do
if [ $i -eq 1 ]; then
echo -e "\tLocal IPv4 address...........: $ip" >> $file
else
echo -e "\t $ip" >> $file
fi
let i++
done
fi
fi
echo "" >> $file
if [ "$DEFAULT_GW" ] ; then
echo -e "\tDefault Gateway..............: $DEFAULT_GW" >> $file
fi
echo "" >> $file
declare -i i=1
for dns in $DNS_SERVER ; do
echo -e "\tNameserver $i.................: $dns" >> $file
let i++
done
echo "" >> $file
echo -e "\tDate.........................: `date +\"%d.%m.%Y\"`" >> $file
echo -e "\tTime.........................: `date +\"%H:%M:%S\"`" >> $file
echo "" >> $file
echo " *** ***" >> $file
echo " *******************************************************" >> $file
echo -e "From:${email_from}\nTo:${email_to}\nSubject:Test on `hostname --long` at $datum\n\n`/bin/cat $file`" | /usr/sbin/sendmail -F '`whoami`' -f $email_from $email_to
rm -f $file