随笔分类 -  shell相关

shell脚本,awk实现文件a的每行数据与文件b的相对应的行的值相减,得到其绝对值。
摘要:解题思路 文件 shu 是下面这样的。220 34 50 70553 556 32 211 1 14 98 33 文件 jian是下面这样的。1082 想要得到结果是下面这样的。210 24 40 60545 548 24 131 1 12 96 31 用awk来得到想要的结果 [root@loca 阅读全文

posted @ 2016-09-26 00:11 王月波 阅读(3001) 评论(0) 推荐(0) 编辑

shell脚本,awk 根据文件某列去重并且统计该列频次。
摘要:解题方法如下: 解题思路 [root@localhost study]# awk 'NR==FNR{a[$2]++}NR!=FNR&&++b[$2]==1{print $1,$2,a[$2]}' a a1 a 34 s 26 d 1 NR=FNR处理第一个文件a > {a[$2]++} a[$2]+ 阅读全文

posted @ 2016-09-25 00:23 王月波 阅读(9901) 评论(0) 推荐(0) 编辑

shell脚本,awk实现行列转换
摘要:[root@localhost study]# cat file 张三 语文 81 张三 数学 81 李四 语文 76 李四 数学 90 王五 语文 81 王五 数学 100 王五 英语 90 怎么实现为下面的排序??? 81 81 76 90 81 100 90 语文 数学 语文 数学 语文 数学 ... 阅读全文

posted @ 2016-09-25 00:10 王月波 阅读(8803) 评论(0) 推荐(0) 编辑

shell脚本,计算学生分数的题目。
摘要:1.计算学生平均分数的值是多少? 2.计算每门课都大于80分的学生姓名。3.计算每门课都小于90分的学生姓名。 阅读全文

posted @ 2016-09-22 00:21 王月波 阅读(1845) 评论(0) 推荐(0) 编辑

shell脚本,如何用shell打印金字塔
摘要: 阅读全文

posted @ 2016-09-18 01:21 王月波 阅读(3609) 评论(0) 推荐(0) 编辑

shell脚本,通过传入的参数来计算最大值和最小值以及平均值。
摘要:[root@localhost zuoye]# cat quansges.sh #!/bin/bash > file [ ! $# -ge 3 ] && echo "please input three number or more number!" && exit 2 || echo $* >file for i in $* do expr $i + 1 &> /dev/... 阅读全文

posted @ 2016-09-15 23:14 王月波 阅读(4735) 评论(0) 推荐(0) 编辑

shell脚本,如何监控mysql数据库。
摘要:[root@localhost wyb]# cat jkmysql #!/bin/bash status=`/etc/init.d/mysqld status|grep running|wc -l` process=`ps -ef |grep mysqld|grep -v grep|wc -l` port=`lsof -i:3306|grep -i listen|wc -l` mysql... 阅读全文

posted @ 2016-09-14 00:22 王月波 阅读(2718) 评论(0) 推荐(0) 编辑

shell脚本,如何破解字符串对应的md5sum前的RANDOM对应数字?
摘要:已知下面的字符串是通过RANDOM随机数变量md5sum|cut-c 1-8截取后的结果,请破解这些字符串对应的md5sum前的RANDOM对应数字?[root@localhost md5]# cat zifuchuang 21029299 00205d1c a3da1677 1f6d12dd 890684b [root@localhost md5]# cat shuzi.sh #!/bin... 阅读全文

posted @ 2016-09-14 00:06 王月波 阅读(2154) 评论(0) 推荐(0) 编辑

shell脚本,如何监控目录下的文件内容是否被修改。
摘要:第一种方法是通过cmp来进行比对[root@localhost bo]# ls 1.html 2.html 3.html 4.html 5.html 6.html 7.html 8.html 9.html cat.sh [root@localhost bo]# cat cat.sh #!/bin/bash [ ! -f /root/wyb/bo/cat.log ] &&... 阅读全文

posted @ 2016-09-13 00:15 王月波 阅读(6357) 评论(0) 推荐(0) 编辑

shell脚本,一个经典题目。
摘要:[root@localhost wyb]# cat zhuijiu.sh #!/bin/bash #1、写一个脚本执行后,输入名字,产生随机数01-99之间的数字。 #2、如果相同的名字重复输入,抓到的数字还是第一次抓取的结果, #3、前面已经抓到的数字,下次不能在出现相同数字。 #4、第一个输入名字后,屏幕输出信息,并将名字和数字记录到文件里,程序不能退出,继续等待别的学生输入 file... 阅读全文

posted @ 2016-09-10 01:00 王月波 阅读(1301) 评论(0) 推荐(0) 编辑

shelll脚本,根据软链接,找到真实路径
摘要:[root@localhost tmp]# ls -l total 60520 lrwxrwxrwx 1 root root 11 Sep 9 22:54 abc -> /etc/passwd lrwxrwxrwx 1 root root 8 Sep 9 23:02 cde -> /tmp/abc lrwxrwxrwx 1 root root 8 S... 阅读全文

posted @ 2016-09-10 00:19 王月波 阅读(6726) 评论(0) 推荐(0) 编辑

shell脚本,awk实现每个数字加1.
摘要:[root@localhost add]# cat file 1 3 4 5 7 8 9 [root@localhost add]# cat file|awk '{for(i=1;i<=NF;i++){$i+=1}}1' 2 4 5 6 8 9 10 [root@localhost add]# cat file|awk '{for(i=1;i<=NF;i++){$i+=1}}1{print $... 阅读全文

posted @ 2016-09-07 23:47 王月波 阅读(5509) 评论(0) 推荐(0) 编辑

shell脚本,对MySQL数据库进行分库加分表备份
摘要:[root@localhost wyb]# cat table_backup.sh #!/bin/bash flag=0 user=root pass=test mysql -u$user -p"$pass" -e "show databases;" &>/dev/null [ $? -ne 0 ] && read -p "Mysql do not running,start it?(`... 阅读全文

posted @ 2016-09-07 01:18 王月波 阅读(1487) 评论(0) 推荐(0) 编辑

shell脚本,批量创建10个系统帐号并设置密码为随机8位字符串。
摘要:[root@localhost wyb]# cat user10.sh #!/bin/bash #批量创建10个系统帐号wangyb01-wangyb10并设置密码(密码为随机8位字符串)。 >user.list for user in `seq -w 10` do useradd wangyb$user password=`echo $RANDOM|md5sum|cut -... 阅读全文

posted @ 2016-09-06 23:46 王月波 阅读(1764) 评论(0) 推荐(0) 编辑

shell脚本,在指定目录下通过随机小写10个字母加固定字符串oldboy批量创建10个html文件。
摘要:[root@localhost wyb]# cat test10.sh #!/bin/bash #使用for循环在/test10目录下通过随机小写10个字母加固定字符串oldboy批量创建10个html文件 dir=/root/wyb/test10/ [ ! -d $dir ] && mkdir -p $dir for i in `seq 10` do touch $d... 阅读全文

posted @ 2016-09-06 22:59 王月波 阅读(4081) 评论(2) 推荐(0) 编辑

shell脚本,按字母出现频率降序排序。
摘要:[root@localhost oldboy]# cat file the squid project provides a number of resources toassist users design,implement and support squid installations. Please browsethe documentation and support section... 阅读全文

posted @ 2016-09-06 18:17 王月波 阅读(1835) 评论(0) 推荐(0) 编辑

shell脚本,按单词出现频率降序排序。
摘要:[root@localhost oldboy]# cat file the squid project provides a number of resources toassist users design,implement and support squid installations. Please browsethe documentation and support sections... 阅读全文

posted @ 2016-09-06 18:16 王月波 阅读(593) 评论(0) 推荐(0) 编辑

shell脚本,录制和回放终端的小工具script。
摘要:action.log和time.log这两个配置文件被当做script命令的参数。这两个文件可以随便命名。这里用time.log和action.log。其中time.log用于存储时序信息,描述每一个指令在何时运行;action.log用于存储命令信息输出。-t选项用于将时序数据导入stderr。2>用于stderr重定向到time.log。 [root@localhost ~]# script... 阅读全文

posted @ 2016-09-05 12:54 王月波 阅读(1202) 评论(0) 推荐(0) 编辑

shell脚本,alias别名命令用法。
摘要:[root@localhost ~]# alias alias cp='cp -i' alias mv='mv -i' alias rm='rm -i' [root@localhost ~]# [root@localhost ~]# [root@localhost ~]# [root@localhost ~]# [root@localhost ~]# alias cp alias cp=... 阅读全文

posted @ 2016-09-05 12:38 王月波 阅读(12334) 评论(0) 推荐(0) 编辑

shell脚本,一个字符一个字符输出。
摘要:[root@localhost wyb]# cat file 123 abc 456 456 def 1 23 5678 abc 789 789de f567 [root@localhost wyb]# cat fffile.sh #!/bin/bash cat file| while read line do for i in `seq 1 ${#line}` do a=`e... 阅读全文

posted @ 2016-09-04 22:53 王月波 阅读(2602) 评论(0) 推荐(0) 编辑

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示