1、检测网站地址是否存活
#!/bin/bash
. /etc/init.d/functions
url_list=(www.tec.com www.stu.com)
function chkurl(){
i=0
while [
i
−
l
t
2
]
d
o
c
u
r
l
h
t
t
p
:
/
/
i -lt 2 ] do curl http://
i−lt2]docurlhttp://{url_list[$i]} &>/dev/null
if [
?
−
e
q
0
]
t
h
e
n
a
c
t
i
o
n
"
? -eq 0 ] then action "
?−eq0]thenaction"{url_list[KaTeX parse error: Expected 'EOF', got '}' at position 3: i]}̲" /bin/true …{url_list[$i]}" /bin/false
fi
let i++
done
}
function main(){
while true
do chkurl
sleep 3
done
}
main
2、mysql分库分表备份
#!/bin/bash
user=“root”
password=“123456”
mycmd=“mysql -u
u
s
e
r
−
p
user -p
user−ppassword -h 192.168.100.1”
mydump=“mysqldump -u
u
s
e
r
−
p
user -p
user−ppassword -h 192.168.100.1 --lock-tables=0”
for dbname in $mycmd -e "show databases;"|egrep -v "Database|schema"
do
[ -d /opt/
d
b
n
a
m
e
]
∣
∣
m
k
d
i
r
−
p
/
o
p
t
/
dbname ]||mkdir -p /opt/
dbname]∣∣mkdir−p/opt/dbname
for tabname in $mycmd -e "show tables from $dbname"|sed 1d
do $mydump $dbname
t
a
b
n
a
m
e
>
/
o
p
t
/
tabname > /opt/
tabname>/opt/dbname/KaTeX parse error: Expected group after '_' at position 10: {tabname}_̲(date +%F).sql
done
done
3、检测MySQL主从复制是否异常
#!/bin/bash
user=“root”
password=“123456”
mycmd=“mysql -u
u
s
e
r
−
p
user -p
user−ppassword -h 192.168.100.20”
function chkdb() {
list=(
(
(
(mycmd -e “show slave status \G”|egrep “Running|Behind”|awk -F: ‘{print $2}’))
if [ ${list[0]} = “Yes” -a ${list[1]} = “Yes” -a ${list[2]} -lt 120 ]
then echo “Mysql slave is ok”
else echo “Mysql slave replation is filed”
fi
}
function main() {
while true
do chkdb
sleep 3
done
}
main
4、mysql日志切割
#!/bin/bash
logfile=/var/log/httpd/access_log
pid=/run/httpd/httpd.pid
mv KaTeX parse error: Expected group after '_' at position 20: …ile /opt/access_̲(date -d “yesterday” +"%Y-%m-%d").log
kill -USR1 $(cat $pid)
size=du -sh /opt|awk '{print $1}'|awk -F "M" '{print $1}'
if [ $size -gt 1000 ]
then find /opt -type f -name access* -mtime +30 -exec rm -f {} ;
fi