Automation scripts

From vpsget wiki
Jump to: navigation, search

yum update at system boots and remove itself:

Note: cron task in our case is line 16 at /etc/crontab

#!/bin/bash
wait 10 &
/usr/bin/yum -y update &
wait
/bin/sed -i '16d' /etc/crontab
/bin/rm /root/update.sh

OpenVPNas

/usr/local/src/openvpnas.sh

#!/bin/bash

cd /tmp/
wget http://swupdate.openvpn.org/as/openvpn-as-2.0.3-CentOS6.i386.rpm
rpm -i *.rpm                   
echo -e "Hbf%2sc$&]4f[\nHbf%2sc$&]4f[" | passwd openvpn
service openvpnas start
chkconfig openvpnas on
chkconfig iptables on
rm -rf /usr/local/src/openvpnas.sh

Check logs and email when keywords found

#!/bin/bash

log1=/var/log/secure
mydate=$(date +%b\ %d)

if [ -e $log1 ] && [ -s $log1 ]
then

mail -s "cp1 tmp check" "dave.hartigan@vpsget.com" <<EOF
$(grep -E "$mydate" $log1 | grep -E 'Failed')
EOF

fi

Kill processes running from /tmp/ folder

#!/bin/bash

s1=`ps aux|grep /tmp/|awk 'NR==1{print $11}'`
s2=`ps aux|grep /tmp/|awk '{print $11}'|grep tmp`

if $s1 == "grep" ;
then
       echo "nothing"
else
mail -s "cp1 tmp check" "dave.hartigan@vpsget.com" <<EOF
killed '$s2'
EOF
kill -9 `ps aux|grep /tmp/|awk '{print $11,$2}'|grep tmp|awk '{print $2}'`

fi