欢迎来到淘文阁 - 分享文档赚钱的网站! | 帮助中心 好文档才是您的得力助手!
淘文阁 - 分享文档赚钱的网站
全部分类
  • 研究报告>
  • 管理文献>
  • 标准材料>
  • 技术资料>
  • 教育专区>
  • 应用文书>
  • 生活休闲>
  • 考试试题>
  • pptx模板>
  • 工商注册>
  • 期刊短文>
  • 图片设计>
  • ImageVerifierCode 换一换

    通用shell脚本收集.doc

    • 资源ID:3029439       资源大小:22.07KB        全文页数:19页
    • 资源格式: DOC        下载积分:8金币
    快捷下载 游客一键下载
    会员登录下载
    微信登录下载
    三方登录下载: 微信开放平台登录   QQ登录  
    二维码
    微信扫一扫登录
    下载资源需要8金币
    邮箱/手机:
    温馨提示:
    快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。
    如填写123,账号就是123,密码也是123。
    支付方式: 支付宝    微信支付   
    验证码:   换一换

     
    账号:
    密码:
    验证码:   换一换
      忘记密码?
        
    友情提示
    2、PDF文件下载后,可能会被浏览器默认打开,此种情况可以点击浏览器菜单,保存网页到桌面,就可以正常下载了。
    3、本站不支持迅雷下载,请使用电脑自带的IE浏览器,或者360浏览器、谷歌浏览器下载即可。
    4、本站资源下载后的文档和图纸-无水印,预览文档经过压缩,下载后原文更清晰。
    5、试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。

    通用shell脚本收集.doc

    !-常用shell脚本小工具摘自www.chinaunix.net,作者:mxin1.批量改名或拷贝文件比如将 start*.sh文件改为stop*.sh拷贝先查看ls -l start*.sh|awk m=$9; gsub(/start/,"stop",$9);print "cp "m " "$9再运行ls -l start*.sh|awk m=$9; gsub(/start/,"stop",$9);print "cp "m " "$9|sh改名先查看ls -l start*.sh|awk m=$9; gsub(/start/,"stop",$9);print "mv "m " "$9再运行ls -l start*.sh|awk m=$9; gsub(/start/,"stop",$9);print "mv "m " "$9|sh2.改进grep 2048字符限制的小工具我们查找匹配文件时常常遇到grep报行长度超过2048这样的错误,我做了这个小工具,findtxt,可查找当前目录下的匹配文件,如果需要,把注释打开,可显示匹配内容。希望对大家有所帮助。for file in find . ! -type ddoline=sed -n /$1/p $file if "$line" != "" ; then echo $file# echo $line fidone3.查看文件使用者的小工具 对fuser的一点改进:1.vi showuser 建立一个文件,内容只有一句: find $1 -exec fuser -u ; 2>&1|awk if ($2 != "" print $1 $2 2. chmod 755 showuser3. cp showuser /usr/bin4. showuser . showuser /usr会把当前目录下的在使用的文件的文件名,使用者的id,name显示出来. 4.清理垃圾,可放在crontab里每天执行。#rmlog.shfind /tmp ! -name "*.X11*" -mtime +7 -exec rm -f ;find /var/tmp -mtime +5 -exec rm -f ;find /var/preserve /recycle -mtime +7 -exec rm -f ;crontab0 1 * * * /home/scripts/rmlog.sh > /tmp/rmlog.log 2>&15.强制关闭vg(包括umount所有相关文件系统)#varyoffvg_force.shif $# -le 0 ;thenecho "no para, example:varyoff_vg.sh erpapp_vg "exitfidf -k|awk print $7 |grep -v Mounted >/tmp/fs_mounted.txtfor i in lsvg -l $1 |grep -vE "N/A|vg|MOUNT"|awk print $7doif grep -c $i /tmp/fs_mounted.txt -ge 1 ; then echo fuser -kc $i umount $ifidonevaryoffvg $1 6.kill_fs_user.sh (停掉使用某文件系统的用户,自动判断该文件系统是否mount,避免kill掉其他用户)if $# -le 0 ;then echo "no para, example:kill_user.sh /applprod " exitfidf -k|awk print $7 |grep -v Mounted >/tmp/du_.txtif grep -c $1 /tmp/du_.txt -eq 1 ; then echo fuser -kc $1 fi7.mklvcopy做镜像相当于mirror rootvg,但当rootvg里有不想mirrror的lv或盘大小不一时比较有用。#mkmirrorvg.shmklvcopy -k hd5 2 $1mklvcopy -k hd6 2 $1mklvcopy -k hd8 2 $1mklvcopy -k hd4 2 $1mklvcopy -k hd9var 2 $1mklvcopy -k hd3 2 $1mklvcopy -k hd1 2 $1mklvcopy -k hd2 2 $1mklvcopy -k hd10opt 2 $1mklvcopy -k lg_dumplv 2 $1 bosboot -ad $1bootlist -m normal $1 8.察看根目录各文件和子目录大小,去除文件系统统计# du_.shdf -k|awk print $7 |grep -v Mounted >/tmp/df_mounted.txtcd /for i in ls -l|awk print $9|grep -v "-i"doif grep -c $i /tmp/df_mounted.txt -eq 0 ; then du -sk $ifi done 9.防止文件系统下和根目录下rm -rf * 误操作#deny_rmall.shcd /;touch ./-i;df -k|grep -v Mounted|grep -v proc|grep -v "/tmp"|awk print "cp "./-i" " $7|shcp "/-i" /etccp "/-i" /dev10. 保存清理errpt,(当然可以改为其他目录 )#errclear.sherrpt >/home/mxin/mon/log/errpt_date +%Y%m%d.logerrpt -a >>/home/mxin/mon/log/errpt_date +%Y%m%d.logerrclear 0 11.起大量shell脚本#start_procs.shcat start_procs.list|awk print "sh "$1".sh"|sh#start_procs.list(可追加修改)startprocessorProcProcessor/home/scripts/startArocessorp_mj_deal_cardevent12.停大量进程# stop_procs.shcat procs.list|awk print "stop_proc.sh "$1|sh#stop_proc.shps -ef|grep $1|grep -v grep|awk print "kill -9 "$2|sh#stop_procs.list(可追加修改)startprocessorProcProcessorJackrocessorp_mj_deal_cardevent 13.收集系统信息echo -hostname-prtconfecho -lsvg;lsvg lsvg -oecho "-lsvg -l "lsvg -l lsvg -oecho "-lslv lv "lsvg -l lsvg -o|grep -v "LV NAME"|grep -v awk print "lslv "$1|shecho -df;df -k;lsfsecho -netstat;netstat -in;netstat -i;netstat -recho -ps;ps -efk;ps guecho -lscfg;lscfg -vpecho -lssrc;lssrc -aecho -lsslot;lsslot -c pciecho -lspv;lspvecho -lslpp;lslpp -lecho -lsattr; lsdev -C|awk print "echo -"$1"lsattr -El " $1|shecho -prtconf -v;prtconf -vecho -errpt; errpt ;errpt -aecho -major; ls -al /dev/*echo -hosts file; cat /etc/hostsif ps -ef|grep cluster|grep -v grep|wc -l -ge 1 ;thenecho -HA INFO/usr/es/sbin/cluster/utilities/cltopinfo -c;/usr/es/sbin/cluster/utilities/cltopinfo -n;/usr/es/sbin/cluster/utilities/clshowres -nhostname;/usr/es/sbin/cluster/utilities/cldispfi14.将多级子目录的权限放开#chmod_dir.shecho for example:chmod_dir.sh rwx /home/mxin/monecho $1$2 >/tmp/chmod_dir.txtcat /tmp/chmod_dir.txt|awk -F / print "chmod o+x /"$2"chmod o+x /"$2"/"$3"chmod o+x /"$2"/"$3"/"$4"chmod o+x /"$2"/"$3"/"$4"/"$5"chmod -R o+"$1" /"$2"/"$3"/"$4"/"$5"/"$6|sh 15.监控oracle是否有锁。#mon_db_lock.sh. .profilecd /home/mxin/monif date +%H%M = "0800" ; thenecho 0 > warn_count fi warn_count=cat warn_countsqlplus "/as sysdba" <<EOFset feed off;set heading off;spool /tmp/db_lock.out1;mon_db_lock.sqlspool off;exitEOFsleep 13 sqlplus "/as sysdba" <<EOFset feed off;set heading off;spool /tmp/db_lock.out2;mon_db_lock.sqlspool off;exitEOFsleep 27sqlplus "/as sysdba" <<EOFset feed off;set heading off;spool /tmp/db_lock.out3;mon_db_lock.sqlspool off;exitEOFcat /tmp/db_lock.out1|grep -v SQL|grep 0-9 >/tmp/mon_db_lock.out1cat /tmp/db_lock.out2|grep -v SQL|grep 0-9 >/tmp/mon_db_lock.out2cat /tmp/db_lock.out3|grep -v SQL|grep 0-9 >/tmp/mon_db_lock.out3cat /tmp/mon_db_lock.out1|grep -v SQL|grep 0-9|awk print "grep ""$0"" /tmp/mon_db_lock.out2"|sh >/tmp/db_lock1if cat /tmp/db_lock1|wc -l -gt 0 ; then cat /tmp/mon_db_lock.out2|grep -v SQL|grep 0-9|awk print "grep ""$0"" /tmp/mon_db_lock.out3"|sh >/tmp/db_lock2 if cat /tmp/db_lock2|wc -l -gt 0 ; then cat /tmp/mon_db_lock.out3|grep -v SQL|grep 0-9|awk print "grep ""$0"" /tmp/mon_db_lock.out.old"|sh >/tmp/db_lock3 if cat /tmp/db_lock3|wc -l -gt 0 ; then cat /tmp/db_lock3|awk print "wall db lock-" "$0 ""!" |sh let warn_count=$warn_count+1 fi fificp /tmp/mon_db_lock.out3 /tmp/mon_db_lock.out.oldif $warn_count -gt 4 ; then beep.sh echo 0 > warn_countfi#mon_db_lock.sqlset linesize 256col object_name format a18col object_id format 99999999col Locked_Mode format a15col SERIAL# format 9999999col session_id format 999999col oracle_username format a15col os_user_name format a15col process format 9999999SELECT substr(b.object_name,1,1 object_name,a.object_id, decode( a.locked_mode, 0, None, /* Mon Lock equivalent */ 1, Null, /* N */ 2, Row-S (SS), /* L */ 3, Row-X (SX), /* R */ 4, Share, /* S */ 5, S/Row-X (SSX), /* C */ 6, Exclusive, a.locked_mode) Locked_Mode, /* X */ session_id, SERIAL#,oracle_username, os_user_name, a.process FROM v$LOCKED_OBJECT a, dba_OBJECTS b,v$session cWHERE a.object_id = b.object_id and a.session_id=c.sid/ 16.监控oracle的表空间# mon_ts_space.shcd /home/oraprodsqlplus "/as sysdba" <<EOFset feed off;set heading off;spool /tmp/mon_ts_space.out;mon_ts_space.sqlexitEOFcat /tmp/mon_ts_space.out|grep -v SQL|grep 0-9|awk -f mon_ts_space.awk# mon_ts_space.sqlselect df.tablespace_name "Tablespace", (df.totalspace - fs.freespace) "Used MB", fs.freespace "Free MB", df.totalspace "Total MB", round(100 * (fs.freespace / df.totalspace) "Pct. Free"from dba_tablespaces ts, (select tablespace_name, round(sum(bytes) / 1048576) TotalSpace from dba_data_files group by tablespace_name) df, (select tablespace_name, round(sum(bytes) / 1048576) FreeSpace from dba_free_space group by tablespace_name) fswhere ts.tablespace_name = fs.tablespace_nameand df.tablespace_name = fs.tablespace_name(+) and round(100 * (fs.freespace / df.totalspace) <20and df.tablespace_name not in (APPS_UNDOTS1,TEMP);17.只清除所有当前使用该vg的用户#kill_vg_user.shif $# -le 0 ;then echo "no para, example:kill_vg_user.sh erpapp_vg " exitfidf -k|awk print $7 |grep -v Mounted >/tmp/fs_mounted.txtfor i in lsvg -l $1 |grep -vE "N/A|vg|MOUNT"|awk print $7doif grep -c $i /tmp/fs_mounted.txt -ge 1 ; then echo fuser -kc $i fuser -kc $ifi done18.每月月底执行的脚本#month_lastday.sh. .profileTZ=TZ-24echo date +%dif date +%d = "01" ; thenecho "ok. today is last day of this month. run it!"#insert your shell scriptsfi19.每月1日执行的脚本#month_firstdy.sh. .profileTZ=TZ+24echo date +%dif date +%d = "02" ; thenecho "ok. today is firstday of this month. run it!"#insert your shell scriptsfi20.跟踪oracle export结果的脚本(放在exp脚本最后)#exp_check.shif tail /tmp/exp_dvlp.log|grep " success"|wc -l -lt 1 ;then echo "db dvlp export fail!" #报警 wall "db dvlp export fail!"fi 21.检查系统的进程a.check_proc.sh:#check_proc.shcat check_proc.list|awk -F "," print "Check_proc.sh "$1" ""$2""" " "$3 |shb.check_proc.list:(可修改)telnet,telnetd -a,2 xcom,xcommanager.py,1c.Check_proc.sh:#Check_proc.sh export LANG=en_UScount=ps -ef|grep "$2"|grep -v grep|wc -lif $count -lt $3 ;then echo $1 has not be started all,the number is $count/$3!fi运行示例:test3root/home/mxin>ps -ef UID PID PPID C STIME TTY TIME CMD root 1 0 0 Aug 10 - 0:11 /etc/init root 77910 1 0 Aug 10 - 5:53 /usr/sbin/syncd 60 root 102470 1 0 Aug 10 - 0:00 /usr/ccs/bin/shlap64 root 106572 1 0 Aug 10 - 0:00 /usr/lib/errdemon root 139366 1 0 Aug 10 - 0:00 /usr/sbin/srcmstr root 164068 139366 0 Aug 10 - 0:00 /usr/sbin/snmpd root 184466 139366 0 Aug 10 - 4:38 /usr/sbin/aixmibd root 246002 1 0 Aug 10 vty0 8:50 -ksh root 409612 139366 0 Aug 10 - 0:05 sendmail: accepting connections root 417830 139366 0 Aug 10 - 0:00 /usr/sbin/syslogd root 421898 1 0 Aug 10 - 0:00 /usr/sbin/uprintfd root 442602 782494 0 16:19:29 - 0:00 telnetd -a root 446688 442602 0 16:19:29 pts/1 0:00 -ksh root 466976 782494 0 Sep 07 - 0:00 ftpd root 471108 139366 0 Aug 10 - 0:01 /usr/sbin/hostmibd root 495680 1 0 Aug 10 - 0:04 /usr/sbin/cron root 508018 139366 0 Aug 10 - 0:00 /usr/sbin/portmap root 708686 782494 0 Sep 07 - 0:00 ftpd root 729196 139366 0 Aug 10 - 0:04 /usr/sbin/snmpmibd root 733290 139366 0 Aug 10 - 0:00 /usr/sbin/muxatmd root 762026 446688 0 17:46:17 pts/1 0:00 ps -ef root 782494 139366 0 Sep 07 - 0:00 /usr/sbin/inetd test3root/home/mxin>check_proc.sh telnet has not be started all,the number is 1/2!xcom has not be started all,the number is 0/1!22文件中抽取指定字符,并定向到新文件举例:从监控结果中抽取PGA使用情况的数据,这个数据的特点是所在行只有一个变量#!/usr/bin/ksh#Script name: Grep specific word from a file#Usage: filegrep filenamefile_time=$(date +%Y%m%d%H%M)newfile=$PWD/$1.$file_timelines=$(cat $1 |wc -l)#cat $1 | while read LINEdoif -n "$LINE" && (print $LINE|grep -v # >/dev/null) then set $LINE if ( $# = 1 ) then print $LINE |grep -v "SUM(S.PGA_USED_MEM)" | awk print $1 >>$newfile fifidone exit 0扩展用法:除了PGA使用情况的前面添加时间。时间所在行有两个变量,可以将时间和PGA使用数值同时过滤出来,定义到$.tmp1,然后将时间和PGA使用数值打印到同一行,并用tab键隔离开,定向到$.tmp2,这时,对于每一行,$1与$2都是时间,而$3是PGA使用数值,故对每一行只打印$1与$3,定向到$newfile。#!/usr/bin/ksh#Script name: Grep specific word from a file#Usage: filegrep filenamefile_time=$(date +%Y%m%d%H%M)cat $1|grep -v weblogic|grep -v SQL|grep -v -|grep -v SUM |grep -v SID|grep -v rows |grep -v Copy|grep -v With|grep -v and>>$.tmpnewfile=$PWD/$1.$file_timelines=$(cat $1 |wc -l)#cat $.tmp | while read LINEdo if -n "$LINE" #&& (print $LINE|grep -v # >/dev/null) then set $LINE if ( $# < 3 ) then print $LINE |grep -v "SUM(S.PGA_USED_MEM)" | awk print $1 >>$.tmp1 fi fidone rm $.tmp#cat $.tmp1 | while read LINEdo if -n "$LINE" && -n print $LINE|grep ":" then print -n "$LINEt" >>$.tmp2 else print "$LINEt" >>$.tmp2 fidone rm $.tmp1#cat $.tmp2 | while read LINEdo set $LINE print "$1t$3" >>$newfiledonerm $.tmp2exit 0按行号循环整理数据,实例:每8行输出到一行,循环执行:#!/usr/bin/ksh#Script name: Grep specific word from a file#Usage: filegrep filenamefile_time=$(date +%Y%m%d%H%M)newfile=$PWD/$1.$file_timecat $1 |grep -v *|grep -v ALERT|grep -v "GBL_SWAP_SPACE_AVAIL" |awk print $2" "$3" "$5" " >>$.tmp#i=1cat $.tmp | while read LINEdo if -n "$LINE" && $i -lt 9 then if $i != 8 then print -n "$LINEt" >> $newfile else print "$LINE" >> $newfile fi (i+=1) else print -n "$LINEt" >> $newfile i=2 fidone rm $.tmpexit 0

    注意事项

    本文(通用shell脚本收集.doc)为本站会员(小**)主动上传,淘文阁 - 分享文档赚钱的网站仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知淘文阁 - 分享文档赚钱的网站(点击联系客服),我们立即给予删除!

    温馨提示:如果因为网速或其他原因下载失败请重新下载,重复下载不扣分。




    关于淘文阁 - 版权申诉 - 用户使用规则 - 积分规则 - 联系我们

    本站为文档C TO C交易模式,本站只提供存储空间、用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。本站仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知淘文阁网,我们立即给予删除!客服QQ:136780468 微信:18945177775 电话:18904686070

    工信部备案号:黑ICP备15003705号 © 2020-2023 www.taowenge.com 淘文阁 

    收起
    展开