免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
楼主: send_linux
打印 上一主题 下一主题

[学习共享] 2013年ChinaUnix社区Shell编程大赛!(获奖名单公布)!  关闭 [复制链接]

论坛徽章:
71
15-16赛季CBA联赛之同曦
日期:2018-08-23 15:41:42辰龙
日期:2014-08-15 09:07:43狮子座
日期:2014-06-03 13:55:33亥猪
日期:2014-06-02 11:17:08巨蟹座
日期:2014-05-06 10:02:03午马
日期:2014-05-04 08:18:27亥猪
日期:2014-04-29 11:11:32技术图书徽章
日期:2014-04-24 15:51:26技术图书徽章
日期:2014-04-17 11:01:53辰龙
日期:2014-04-15 12:45:46亥猪
日期:2014-04-11 09:06:23射手座
日期:2014-04-01 15:28:10
1 [报告]
发表于 2013-06-20 14:46 |显示全部楼层
本帖最后由 zhaopingzi 于 2013-06-25 12:53 编辑

1.

  1. grep -oE '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' illegal.log|awk -F. '{a[$0]++}END{for(i in a)print i ,a[i]}'|sort -k2|tail -1
  2. 192.74.224.245 9
复制代码
3.

  1. #/bin/bash
  2. ips=`seq 3 100`
  3. for ip in $ips
  4. do

  5. dday=`date +"%y%m%d"`
  6. file=192.168.3.$ip-$dday.tar.bz2


  7. week=`date +%w`

  8. case $week in
  9.               7 )  ssh 192.168.3.$ip tar -g snapshot -zcf  backup_full.$file   --exclude=/opt/WebSphere/AppServer/profiles/bin --exclude=/opt/WebSphere/AppServer/profiles/log --exclude=*.log --exclude=*heapdump* --exclude=*.gz --exclude=*.tar --exclude=*.zip ==exclude=*.bak /opt/WebSphere/AppServer/profiles/
  10.                    scp  192.168.3.$ip:/backup_full.$file   /var/ChinaUnix/
  11.                    ;;
  12.     1|2|3|4|5|6 )  ssh 192.168.3.$ip tar -g snapshot -zcf  backup_incremental.$file   --exclude=/opt/WebSphere/AppServer/profiles/bin --exclude=/opt/WebSphere/AppServer/profiles/log --exclude=*.log --exclude=*heapdump* --exclude=*.gz --exclude=*.tar --exclude=*.zip ==exclude=*.bak /opt/WebSphere/AppServer/profiles/
  13.                    scp  192.168.1.$ip:/backup_incremental$file   /var/ChinaUnix/
  14.                    ;;
  15. esac

  16. done
复制代码
4.

  1.    第一种格式command命令正确执行返回0,第2种正确执行返回1
复制代码
5.

  1. echo "1234"|awk -F "" '{for(i=1;i<=NF;i++)SUM+=$i}END{print SUM}'
  2. 10
复制代码
6.

  1. #!/bin/bash

  2. echo "please input date(YYYY-MM-DD:)注意这个格式一定要输入对,程序没有判断输入有效性"
  3.      read ymd
  4.   year=`echo $ymd|awk -F"-" '{print $1}'`
  5.   mon=`echo $ymd|awk -F"-" '{print $2}'`
  6.   day=`echo $ymd|awk -F"-" '{print $3}'`

  7.   monnums=(0 31 28 31 30 31 30 31 31 30 31 30 31)

  8.     if(($year%400==0||($year%4==0&&$year%100!=0)))
  9.       then
  10.        leap=1;
  11.       else
  12.       leap=0;
  13.     fi
  14.         if((10#$mon>2))
  15.           then
  16.             for((i=0;i<10#$mon;i++))
  17.             {
  18.              x=`expr $x + ${monnums[$i]}`
  19.             }
  20.           total=`expr $x + $day + $leap`
  21.           else
  22.           for((i=0;i<10#$mon;i++))
  23.             {
  24.              x=`expr $x + ${monnums[$i]}`
  25.             }
  26.           total=`expr $x + $day`
  27.          fi


  28.    echo -e "this day is $total day of this year"

  29.   if(((10#$day<=31))&&((10#$day>1)))
  30.    then
  31.     day=$((10#$day-01))
  32.   fi

  33.   if((10#$day==1))&&(((10#$mon==5))||((10#$mon==7))||((10#$mon==8))||((10#$mon==10))||((10#$mon==12)))
  34.     then
  35.      mon=$((10#$mon-1))
  36.   fi

  37.   if(((10#$day==1)))&&(((10#$mon==2))||((10#$mon==4))||((10#$mon==6))||((10#$mon==9))||((10#$mon==11)))
  38.    then
  39.      day=31
  40.      mon=$((10#$mon-1))
  41.   fi

  42.   if((10#$day==1))&&((10#$mon==3))&&((leap==1))
  43.    then
  44.      day=29
  45.      mon=$((10#$mon-1))
  46.   fi

  47.   if((10#$day==1))&&((10#$mon==3))&&((leap==0))
  48.    then
  49.      day=28
  50.      mon=$((10#$mon-1))
  51.   fi

  52.   if((10#$day==1))&&((10#$mon==1))
  53.    then
  54.    year=$(($year-1))
  55.    mon=12
  56.    day=31
  57.   fi

  58. day=$((10#$day))
  59. year=$((10#$year))
  60. mon=$((10#$mon))

  61. printf "yesterday is "
  62. printf "%04d-" $year
  63. printf "%02d-" $mon
  64. printf "%02d\n" $day
复制代码
测试情况

  1. please input date(YYYY-MM-DD:)
  2. 2000-01-01
  3. this day is 1 day of this year
  4. yesterday is 1999-12-31

  5. please input date(YYYY-MM-DD:)
  6. 2008-09-09
  7. this day is 253 day of this year
  8. yesterday is 2008-09-08

  9. please input date(YYYY-MM-DD:)
  10. 2013-01-01
  11. this day is 1 day of this year
  12. yesterday is 2012-12-31

  13. please input date(YYYY-MM-DD:)
  14. 2000-03-01
  15. this day is 61 day of this year
  16. yesterday is 2000-02-29

  17. please input date(YYYY-MM-DD:)
  18. 2013-06-21
  19. this day is 172 day of this year
  20. yesterday is 2013-06-20
复制代码
8.

  1. 不可以
  2. rm认为是以空格隔开的多个文件呢
  3. 想要删除掉,把这个文件用""括起来
复制代码
10
用最简洁的命令列出当前目录下的非 20130605开头的文件

  1. ls|grep -v "^20130605"
复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP