SHELL训练营--day27_shell练习76-80

#!批量杀进程
#!/bin/bash
cat > kill_tomcat.expect <<EOF
#!/usr/bin/expect
set passwd [ lindex $argv 0]
set host [lindex $argv 1]
spawn ssh root@$host

expect {
    "yes/no"  { send "yes\r";exp_continue }
    "password:" { send "$passwd\r" }
}

expect "]*"
send "killall java\r"
expect "]*"
send "exit\r"
EOF

chmod a+x kill_tomcat.expect

cat ip-pwd.ini|while read line
do
    ip=`echo $line |awk -F ',' '{print $1}'`
    pw=`echo $line|awk -F ',' '{print $3}'`
    ./kill_tomcat.expect $pw $ip
done

#查找日志打包
#!/bin/bash
cd /data/log
find . -type f -name "*.log" -mtime +3 > /tmp/old_log

d=`date +%F`

tar czf $d.tar.gz `cat /tmp/old_log|xargs`
rsync -a $d.tar.gz 192.168.1.2:/data/log/
cat /tmp/old_log|xargs rm

#处理文本
#!/bin/bash
for w in `awk -F ':' '{print $1}' 3.txt|sort |uniq`
do
    echo "[$w]"
    awk -v w2=$w -F ':' '$1==w2 {print $2}' 3.txt|sort
done

#批量删除日志
#!/bin/bash

dir1=/opt/cloud/log
dir2=/opt/cloud/instance/

if [ -d $dir1 ]
then
    find $dir1 -type f -mtime +7 |xargs rm
elif [ -d $dir2 ]
then
    find $dir2 -name "*.log" -type f -mtime +15 |xargs rm
fi
上一篇:Xcode 如何计算整个项目的代码行数


下一篇:xargs命令详解