-
-
Save pi0/9c9aab4f74dfc6a0f2dd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#trap USR1 signal | |
function on_usr1() { | |
read line < `cat my_conf` | |
echo $line > /dev/tty2 | |
echo "Got SIGUSR1 !" | |
} | |
trap on_usr1 SIGUSR1 | |
#trap Errors | |
error() { | |
message="$2" | |
echo "Error : $message" >> /var/log/my_script.log | |
} | |
trap 'error ${LINENO}' ERR | |
#Check backport | |
if [ ! "$(cat /etc/apt/sources.list|grep backports)" ] ;then | |
echo "Adding backports repository ..." | |
echo "deb http://archive.ubuntu.com/ubuntu/ `lsb_release -cs`-backports main restricted universe multiverse" >> /etc/apt/sources.list | |
fi | |
#Check for tar package | |
if [ ! "$(dpkg --get-selections|grep ^tar)" ] ;then | |
apt-get install -y tar | |
fi | |
#Report top proccesses (async) | |
function report() { | |
t=$( ps -aux --sort size|head -n 5 ) | |
echo $t > /dev/tty1 | |
} | |
export -f report | |
watch -n 3 bash -t -c report & > /dev/null & | |
#Backup every 500 seconds | |
while [ true ] ; do | |
echo "Backing up ..." | |
tar -czf /root/backup_`date`.tar.gz /etc | |
sleep 500 | |
done | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment