ICode9

精准搜索请尝试: 精确搜索
首页 > 系统相关> 文章详细

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

2019-01-23 23:55:30  阅读:287  来源: 互联网

标签:dir2 xargs shell old log tar dir1 76 SHELL


#!批量杀进程
#!/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

标签:dir2,xargs,shell,old,log,tar,dir1,76,SHELL
来源: http://blog.51cto.com/sincethen/2346021

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有