linux 运维习题
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了linux 运维习题相关的知识,希望对你有一定的参考价值。
1. linux如何挂在windows下的共享目录?
#匿名共享 [[email protected] ~]# mount.cifs //192.168.174.1/isos /media/ [[email protected] 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 #认证共享 [[email protected] /]# umount /media/ [[email protected] /]# cd /media/ [[email protected] media]# ls [[email protected] media]# cd .. [[email protected] /]# mount.cifs //192.168.174.1/isos /media/ -o username=ftp1 Password for [email protected]//192.168.174.1/isos: ********* [[email protected] /]# cd /media/ [[email protected] 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 [[email protected] media]#
2.使用for循环在/oldboy目录下通过随机小写10个字母加固定字符串oldboy批量创建10个html文件,名称例如为:
[[email protected] ~]# sh create_html.sh [[email protected] ~]# 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 [[email protected] ~]# 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 [[email protected] ~]#
3.请使用两种方法将上题的oldboy改成oldgirl并将html该为HTML。
#方法一 [[email protected] ~]# sh modify_html.sh [[email protected] ~]# 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 [[email protected] ~]# 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 [[email protected] ~]# #方法二 [[email protected] ~]# cat modify_html_2.sh #!bin/bash cd /oldboy/ rename ‘html‘ ‘HTML‘ * rename ‘boy‘ ‘girl‘ * [[email protected] ~]#
4.批量创建10个账号oldboy01-oldboy10 密码为随机8个字符串。
[[email protected] ~]# 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. [[email protected] ~]# 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 [[email protected] ~]# 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 [[email protected] ~]#
5.写一个脚本,判断192.168.174.0/24 有多少在线IP?
[[email protected] ~]# sh ping_batch_2.sh UP: 4 DOWN: 250 #单进程的ping耗时太长 #本来想用命名管道的,但是没有成功 #借助一个文件来实现并发的ping,但是这个文件没有加锁,这样不安全 [[email protected] ~]# 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 [[email protected] ~]#
6.请用两种方法实现for循环打印下面这句话字母数不大于 6的单词。
I am oldboy teacher welcome to oldboy training class
[[email protected] ~]# x="I am oldboy teacher welcome to oldboy training class" [[email protected] ~]# echo $x | awk ‘END{for(i=1;i<=NF;i++){if(length($i)<=6){print $i}}}‘ I am oldboy to oldboy class [[email protected] ~]# 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的行,然后以:为隔符,提取第三列
[[email protected] ~]# cat text.log FAILD:SUCCESSFUL:DONE:CRITICAL FAILD:SUCCESSFUL:NO:GOOD FAILD:NO:DO:QINGYUN SUCCESSFUL:DONE:CRITICAL::CRITICAL [[email protected] ~]# cat text.log |grep -E "(SUCCESSFUL|FAILD)"|grep -v "DONE" |cut -d":" -f3 NO DO [[email protected] ~]# cat text.log |grep -E "(SUCCESSFUL|FAILD)"|grep -v "DONE" |awk -F‘:‘ ‘{print $3}‘ NO DO [[email protected] ~]#
本文出自 “Chauncey” 博客,请务必保留此出处http://cqwujiang.blog.51cto.com/10808946/1952097
以上是关于linux 运维习题的主要内容,如果未能解决你的问题,请参考以下文章