サーバを同じpackages状況にする為に、dpkg -lで出力された内容を確認 †
CronでInsert文を発効してつねにI/Oをさせておく †#!/bin/bash ID=1 while [ $ID -lt 10 ]; do NUM=`expr $RANDOM % 10000` mysql --user=hoge --password=hoge <<EOF INSERT INTO database.table VALUES('', "$ID","$NUM" ) EOF let ID=ID+1 done CronでSELECT文を発効して、つねにMySQLに負荷を与えておく †#!/bin/bash ID=1 while [ $ID -lt 10 ]; do mysql --user=hoge --password=hoge <<EOF select * From database.table where id = "$ID"; EOF let ID=ID+1 sleep 4 #好みの秒数 done これをcrontabに何個かセットしておくとよいと思う。 awk †http://lagendra.s.kanazawa-u.ac.jp/ogurisu/manuals/awk/intro/awk-intro.html Mailmanのarchiveの容量チェックをする †#!/bin/bash touch /home/hoge/all.txt for alpa in a b c d e f g h i j k l m n o p q r s t u v w x y z ; do du -sm /var/lib/mailman/archives/private/$alpa* >> /home/hoge/all.txt done .gz †#!/bin/bash for filename in `cat ./list.txt` ; do echo $filename | sed -e "s/\.gz//" >> list2.txt done ログから特定の文字を出して、IPを取り出し、ユニークIPか調べるスクリプト。。。? †のようだ。こんなの作ってたんだなー #!/bin/bash lv access.log | grep 'www.example.jp/hogepage.html' >> url.log sleep 2; cat url.log | cut -c 1-15 > IP.txt for IP in `cat ./IP.txt` ; do check=`lv unique.txt | grep $IP` if [ $check -n ]; then echo $IP >> unique.txt else echo 'already!' fi done adduserを自分でやってくれるスクリプト †新規userを追加する方法が分からずとりあえず書いてみた。 adduserをつかって #!/bin/bash for fullname in `cat ./userlist` ; do user=`expr $fullname : '\(.*:\)'` user=`echo $user | sed 's/://'` pass=`expr $fullname : '.*:\(.*\)'` pass2=`expr $fullname : '.*:\(.*\)'` expect -c " spawn /usr/sbin/adduser $user expect \"Enter new UNIX password: \"; send \""$pass"\" expect \"Retype new UNIX password: \"; send \""$pass2"\" sleep 1 expect \"フルネーム []: \"; send \"name\r\" sleep 1 expect \"部屋番号 []: \"; send \"elife\r\" sleep 1 expect \"職場電話番号 []: \" ; send \"03\r\" sleep 1 expect \"自宅電話番号 []: \" ; send \"03\r\" sleep 1 expect \"その他 []: \" ; send \"email\r\" sleep 1 expect \"以上で正しいですか? \" ; send \"y\r\" expect eof " >> /var/log/adduser/add.log done useraddをつかって #!/bin/bash for fullname in `cat ./userlist` ; do user=`expr $fullname : '\(.*:\)'` user=`echo $user | sed 's/://'` pass=`expr $fullname : '.*:\(.*\)'` pass2=`expr $fullname : '.*:\(.*\)'` cp -r /etc/skel/ /home/ mv /home/skel /home/$user chown -R $user:$user /home/$user chmod 755 /home/$user chmod 700 -R /home/$user/Maildir expect -c " spawn passwd $user expect \"Enter new UNIX password: \" ; send \""$pass"\r\" expect \"Retype new UNIX password: \" ; send \""$pass"\r\" expect eof " >> /var/log/adduser/add-user.log done 大量にパスワードをhtpasswdで追加する †#!/bin/bash for fullname in `cat ./userlist` ; do user=`expr $fullname : '\(.*:\)'` user=`echo $user | sed 's/://'` pass=`expr $fullname : '.*:\(.*\)'` expect -c " spawn htpasswd -d ./passwd-file $user expect \"New password: \" ; send \""$pass"\r\" sleep 1 expect \"Re-type new password: \" ; send \""$pass"\r\" expect eof " >> /var/log/adduser/passwd.log done ファイルを削除する(未確認) †#! /bin/sh RmWeek=$(date +%y%m%d --date='5 week ago') if [ -e $RmWeek ] then rm -r /home/bk/$RmWeek echo 'Remove backup :'$RmWeek > result.txt else mail -s "File server could not remove file" aya@example.jp < errormail.txt echo 'Cannot remove backup '$RmWeek > error.txt fi Mailman生存確認 †Mailmanの特別なプロセスだけ落ちる事がたびたびあり(ArchRunner?)確認する為に書いてみた。根本的な問題解決にはなってないんだけど。。。 #!/bin/sh LOG='/var/log/mailman/live-status.log' currenttime=$(date +%y%m%d%H%M) for Runner in BounceRunner CommandRunner IncomingRunner NewsRunner OutgoingRunner VirginRunner RetryRunner ArchRunner do Run=`ps -ef | grep $Runner | grep -v grep | wc -l` if [ $Run = 0 ]; then echo $Runner.' is dead!'.$currenttime >> $LOG echo `/etc/init.d/mailman restart` echo 'Mailman '.$Runner.' seems to die. I tried to restart. Please check it'.$currenttime | mail -s "[Alert]".$Runner." dead?" mailman-error@example.jp else echo $Runner.' is ok'.$currenttime >> $LOG fi done dir making †#!/bin/bash datetime=`date +%y%m%d` mv /home/bk/temp /home/bk/$datetime mkdir /home/bk/temp #!/bin/bash datetime=$(date +%y%m%d) RmWeek=$(date +%y%m%d --date='5 week ago') echo 'Back up shell starts' >> result.log chown -R root:root /home/bk/temp/ if [ ! -e /home/bk/$datetime ]; then mv /home/bk/temp /home/bk/$datetime mkdir /home/bk/temp echo 'Back up finish for :'$datetime >> result.log else echo 'Could not rename backup :'$datetime >> result.log fi if [ -e $RmWeek ]; then rm -r /home/bk/$RmWeek echo 'Remove backup :'$RmWeek >> result.log else echo 'Could not Remove Backup or remove file does not exist:'$RmWeek >> result.log fi symbolic link †#!/bin/bash for fullname in `cat ./all` ; do #名簿を読み込み rm -r /home/$fullname/.spamassassin/ #spamassassinの各userのDBを削除 mkdir /home/$fullname/.spamassassin/ chown $fullname:$fullname /home/$fullname/.spamassassin/ chmod 700 /home/$fullname/.spamassassin/ ln -s /etc/spamassassin/local.cf /home/$fullname/.spamassassin/user_prefs #リンクにしちゃう chown $fullname:$fullname /home/$fullname/.spamassassin/user_prefs echo $fullname.'add user pref done \n'>> /home/amori/replace.log done replace file †#!/bin/bash for fullname in `cat ./all` ; do cp /home/.procmailrc /home/$fullname/ chown -R $fullname:$fullname /home/$user/.procmailrc echo $fullname.'done \n'>> /var/log/adduser/replace.log done passwd †#!/bin/bash for fullname in `cat ./nopass` ; do user=`expr $fullname : '\(.*:\)'` user=`echo $user | sed 's/://'` pass=`expr $fullname : '.*:\(.*\)'` expect -c " spawn passwd $user sleep 1 expect \"Enter new UNIX password: \" ; send \""$pass"\n\" sleep 1 expect \"Retype new UNIX password: \" ; send \""$pass"\n\" sleep 1 expect eof " >> /var/log/adduser/nopass.log done 未完成(多分更新されたものだけアップデートしようとしたのか?) †#!/bin/bash #desination(remote ip) to="XXX.XXX.XXX.XXX" #destination directories (remote direcotries) todir="/home/bk/staging/" #copy original (local directories) senddir="/home/original/public_html/" echo "----------------" echo "Copy destination:${to}" echo "copy destination directries:${todir}" echo "Original files:${senddir}" echo "RSYNC option :-a -z ${options}" echo "----------------" rsync -azu --stats -e ssh --delete ${senddir} ${to}:${todir} |