======スクリプト集======
=====定期的reboot=====
sudo crontab -e
30 2 * * * /root/bin/maintenance_reboot > /dev/null 2>&1
# touch /var/log/maintenance_reboot.log
# chmod 644 /var/log/maintenance_reboot.log
# vi /root/bin/maintenance_reboot
maintenance_reboot
#!/bin/bash
logmsg() {
echo $1 >> /var/log/maintenance_reboot.log
echo $1
}
msg="`date` uptime: `cat /proc/uptime | awk '{print $1 / 60 }'` : reboot "
/root/bin/mailnotify
sleep 30
if [ "${1}" = "-t" ] ;then
logmsg "$msg (test)"
else
logmsg "$msg (execute)"
# /sbin/shutdown -r 1
fi
=====mailnotify=====
====スクリプト====
#!/bin/bash
subject="maintenance report (`date '+%Y/%m/%d %T'`)"
msg="$subject"
msg="$msg\nuptime: `cat /proc/uptime | awk '{print $1 / 60}'` min"
tmp=""
for i in `/sbin/ifconfig | /bin/grep "Link encap:" | /usr/bin/awk '{print $1}'`;
do tmp="$tmp$i:`/sbin/ifconfig $i | \\
/bin/sed 's/inet addr:/inet addr: /' | \\
/bin/grep "inet addr:" | \\
/usr/bin/awk '{print $3}'`, ";
done
msg="$msg\n$tmp"
msg="$msg\n----"
msg="$msg\n`cat /var/log/messages`"
#echo -e "$msg"
#echo -e "$msg" | /usr/bin/mail -s "$subject" root
echo -e "$msg" | /usr/bin/mail -s "$subject" hiroshi.yamada@gmail.com
====mail設定====
http://blog.muchuu.net/post/113402952220/
postfixよりnullmailの方が簡単
# apt-get install nullmailer mailutils
# vi /etc/nullmailer/remotes
smtp.gmail.com smtp --port=465 --auth-login --user=namahamu.hiroshi@gmail.com --pass=h1r0sh1n0m0h03u --ssl
# chown mail:mail /etc/nullmailer/remotes (不要?)
# chmod 600 /etc/nullmailer/remotes
# /etc/init.d/nullmailer restart
vi /etc/rsyslog.conf
#daemon.*;mail.*;\
# news.err;\
# *.=debug;*.=info;\
# *.=notice;*.=warn |/dev/xconsole
=====コンソール文字出力=====
関連URL
*http://www.m-bsys.com/linux/echo-color-1
*http://d.hatena.ne.jp/foussin/20140503/1399122536
基本
# echo > /dev/tty1
赤色
# c > /dev/tty1
クリア
# echo -e "\e[2J" > /dev/tty1
カーソル位置
# echo -e "\e[0;0H " > /dev/tty1
クリア (カーソル位置も初期化)
# echo -e "\e[2J\e[0;0H" > /dev/tty1
=====fbclock=====
# apt-get install sysvbanner
vi fbclock
#!/bin/bash
while true;
do
# echo `date` > /dev/tty1
echo -e "\e[2J\e[0;0H" > /dev/tty1
banner `date +%H%M%S` > /dev/tty1
sleep 1
done
=====cleanlog=====
#!/bin/bash
file_clean() {
if [ -f $1 ]; then
#:> $1
cp /dev/null $1
fi
}
find /var/log -name "*.?" -type f -exec rm -f {} \;
find /var/log -name "*.gz" -type f -exec rm -f {} \;
find /var/log -name "*.old" -type f -exec rm -f {} \;
find /var/log -type f -exec cp /dev/null {} \;
find /home -name ".bash_history" -type f -exec cp /dev/null {} \;
find /root -name ".bash_history" -type f -exec cp /dev/null {} \;