标签:shell
1. linux如何挂在windows下的共享目录?
#匿名共享 [root@node2 ~]# mount.cifs //192.168.174.1/isos /media/ [root@node2 media]# ls CentOS-6.8-x86_64-bin-DVD1.iso ubuntu-16.04.2-desktop-amd64.iso CentOS-7-x86_64-Everything-1511.iso win_7激活工具.exe coreos_production_iso_image.iso 系统映像WindowsServer2003SP2EnterpriseEdition.iso SW_DVD5_Win_Pro_7w_SP1_64BIT_ChnSimp_-2_MLF_X17-59526.iso #认证共享 [root@node2 /]# umount /media/ [root@node2 /]# cd /media/ [root@node2 media]# ls [root@node2 media]# cd .. [root@node2 /]# mount.cifs //192.168.174.1/isos /media/ -o username=ftp1 Password for ftp1@//192.168.174.1/isos: ********* [root@node2 /]# cd /media/ [root@node2 media]# ls CentOS-6.8-x86_64-bin-DVD1.iso ubuntu-16.04.2-desktop-amd64.iso CentOS-7-x86_64-Everything-1511.iso win_7激活工具.exe coreos_production_iso_image.iso 系统映像WindowsServer2003SP2EnterpriseEdition.iso SW_DVD5_Win_Pro_7w_SP1_64BIT_ChnSimp_-2_MLF_X17-59526.iso [root@node2 media]#
2.使用for循环在/oldboy目录下通过随机小写10个字母加固定字符串oldboy批量创建10个html文件,名称例如为:
[root@localhost ~]# sh create_html.sh [root@localhost ~]# ls /oldboy/ bdjcfhebff_oldboy.html dffgcabcci_oldboy.html fgjeaafbaf_oldboy.html iadfffigib_oldboy.html bjggfdaafa_oldboy.html dfhbffaaaa_oldboy.html gfbabcadjc_oldboy.html cbdeaacfdd_oldboy.html efeaffhgab_oldboy.html hbcdjicacg_oldboy.html [root@localhost ~]# cat create_html.sh #!/bin/bash for i in {1..10} do name=`echo $RANDOM|md5sum|cut -c 1-10 |tr ‘[0-9]‘ ‘[a-z]‘` touch /oldboy/"$name"‘_oldboy.html‘ done [root@localhost ~]#
3.请使用两种方法将上题的oldboy改成oldgirl并将html该为HTML。
#方法一 [root@localhost ~]# sh modify_html.sh [root@localhost ~]# ll /oldboy/ total 0 -rw-r--r-- 1 root root 0 Jul 27 19:47 bdjcfhebff_oldgirl.HTML -rw-r--r-- 1 root root 0 Jul 27 19:47 bjggfdaafa_oldgirl.HTML -rw-r--r-- 1 root root 0 Jul 27 19:47 cbdeaacfdd_oldgirl.HTML -rw-r--r-- 1 root root 0 Jul 27 19:47 dffgcabcci_oldgirl.HTML -rw-r--r-- 1 root root 0 Jul 27 19:47 dfhbffaaaa_oldgirl.HTML -rw-r--r-- 1 root root 0 Jul 27 19:47 efeaffhgab_oldgirl.HTML -rw-r--r-- 1 root root 0 Jul 27 19:47 fgjeaafbaf_oldgirl.HTML -rw-r--r-- 1 root root 0 Jul 27 19:47 gfbabcadjc_oldgirl.HTML -rw-r--r-- 1 root root 0 Jul 27 19:47 hbcdjicacg_oldgirl.HTML -rw-r--r-- 1 root root 0 Jul 27 19:47 iadfffigib_oldgirl.HTML [root@localhost ~]# cat modify_html.sh #!/bin/bash cd /oldboy/ for name in `ls` do x=`echo $name |sed ‘s/html$/HTML/g‘` y=`echo $x | sed ‘s/boy/girl/g‘` mv "$name" "$y" done [root@localhost ~]# #方法二 [root@localhost ~]# cat modify_html_2.sh #!bin/bash cd /oldboy/ rename ‘html‘ ‘HTML‘ * rename ‘boy‘ ‘girl‘ * [root@localhost ~]#
4.批量创建10个账号oldboy01-oldboy10 密码为随机8个字符串。
[root@localhost ~]# sh useradd_batch.sh Changing password for user oldboy01. passwd: all authentication tokens updated successfully. Changing password for user oldboy02. passwd: all authentication tokens updated successfully. Changing password for user oldboy03. passwd: all authentication tokens updated successfully. Changing password for user oldboy04. passwd: all authentication tokens updated successfully. Changing password for user oldboy05. passwd: all authentication tokens updated successfully. Changing password for user oldboy06. passwd: all authentication tokens updated successfully. Changing password for user oldboy07. passwd: all authentication tokens updated successfully. Changing password for user oldboy08. passwd: all authentication tokens updated successfully. Changing password for user oldboy09. passwd: all authentication tokens updated successfully. Changing password for user oldboy10. passwd: all authentication tokens updated successfully. [root@localhost ~]# cat useradd_batch.sh #!/bin/bash for i in {01..10} do PassWord=`echo $RANDOM|md5sum|cut -c 1-8` UserName=‘oldboy‘"$i" useradd -M $UserName echo $PassWord |passwd --stdin $UserName done [root@localhost ~]# grep ‘oldboy‘ /etc/passwd oldboy01:x:1000:1000::/home/oldboy01:/bin/bash oldboy02:x:1001:1001::/home/oldboy02:/bin/bash oldboy03:x:1002:1002::/home/oldboy03:/bin/bash oldboy04:x:1003:1003::/home/oldboy04:/bin/bash oldboy05:x:1004:1004::/home/oldboy05:/bin/bash oldboy06:x:1005:1005::/home/oldboy06:/bin/bash oldboy07:x:1006:1006::/home/oldboy07:/bin/bash oldboy08:x:1007:1007::/home/oldboy08:/bin/bash oldboy09:x:1008:1008::/home/oldboy09:/bin/bash oldboy10:x:1009:1009::/home/oldboy10:/bin/bash [root@localhost ~]#
5.写一个脚本,判断192.168.174.0/24 有多少在线IP?
[root@localhost ~]# sh ping_batch_2.sh UP: 4 DOWN: 250 #单进程的ping耗时太长 #本来想用命名管道的,但是没有成功 #借助一个文件来实现并发的ping,但是这个文件没有加锁,这样不安全 [root@localhost ~]# cat ping_batch_2.sh #!/bin/bash ip=192.168.174 UP=0 DOWN=0 for i in {1..254} do IP="$ip"‘.‘"$i" ping -c 3 $IP >/dev/null 2>&1 && echo "1 $IP" >> .npipe_ping || echo "0 $IP" >> .npipe_ping & done wait cat .npipe_ping |awk ‘{host[$1]++;} END{print "UP: "host[1],"DOWN: "host[0];}‘ rm -f .npipe_ping [root@localhost ~]#
6.请用两种方法实现for循环打印下面这句话字母数不大于 6的单词。
I am oldboy teacher welcome to oldboy training class
[root@localhost ~]# x="I am oldboy teacher welcome to oldboy training class" [root@localhost ~]# echo $x | awk ‘END{for(i=1;i<=NF;i++){if(length($i)<=6){print $i}}}‘ I am oldboy to oldboy class [root@localhost ~]# for((i=1;;i++));do split=`echo $x|cut -d" " -f$i`;if [ "$split" == "" ];then break;fi; echo $split;done I am oldboy teacher welcome to oldboy training class
7.提取文件test.log中FAILD与SUCCESSFUL的字符但不包括DONE的行,然后以:为隔符,提取第三列
[root@localhost ~]# cat text.log FAILD:SUCCESSFUL:DONE:CRITICAL FAILD:SUCCESSFUL:NO:GOOD FAILD:NO:DO:QINGYUN SUCCESSFUL:DONE:CRITICAL::CRITICAL [root@localhost ~]# cat text.log |grep -E "(SUCCESSFUL|FAILD)"|grep -v "DONE" |cut -d":" -f3 NO DO [root@localhost ~]# cat text.log |grep -E "(SUCCESSFUL|FAILD)"|grep -v "DONE" |awk -F‘:‘ ‘{print $3}‘ NO DO [root@localhost ~]#
本文出自 “Chauncey” 博客,请务必保留此出处http://cqwujiang.blog.51cto.com/10808946/1952097
标签:shell
原文地址:http://cqwujiang.blog.51cto.com/10808946/1952097