(ext.) 2017 the shell of the newest enterprise face Test (I, II)

Source: Internet
Author: User

2017 the latest enterprise face Test shell (i)

**********************************************

Enterprise Shell face question 1: Batch generate random character file name case *

**********************************************

Use the For loop to bulk create 10 HTML files in the/oldboy directory, where each file needs to contain 10 random lowercase characters plus a fixed string oldboy, with the following name examples:

12345 [[email protected] C19]# ls /oldboyapquvdpqbk_oldboy.html  mpyogpsmwj_oldboy.html  txynzwofgg_oldboy.htmlbmqiwhfpgv_oldboy.html  mtrzobsprf_oldboy.html  vjxmlflawa_oldboy.htmljhjdcjnjxc_oldboy.html  qeztkkmewn_oldboy.htmljpvirsnjld_oldboy.html  ruscyxwxai_oldboy.html

Answer:

The script reads as follows: (For loop implementation script)

12345678 #!/bin/bash#date=2017-8-3cd /oldboyfor(( i=0;i<10;i++ ))do   r=` head-c 500 /dev/urandom|tr-dc[a-z]|head-c 10|sed-r ‘s#[^a-z]#m#g‘`   touch"$r"_oldboy.htmldone

Description

The script execution results are as follows:

1234567891011121314 [[email protected] oldboy]# ll总用量 8-rw-r--r-- 1 root root   0 8月   3 13:35 defozmpplm_oldboy.html-rw-r--r-- 1 root root 175 8月   3 13:35 for.sh-rw-r--r-- 1 root root   0 8月   3 13:35 fpwxukgqho_oldboy.html-rw-r--r-- 1 root root   0 8月   3 13:35 gwtwtmdwaf_oldboy.html-rw-r--r-- 1 root root   0 8月   3 13:35 htttummyjh_oldboy.html-rw-r--r-- 1 root root   0 8月   3 13:35 myqmgyixuj_oldboy.html-rw-r--r-- 1 root root   0 8月   3 13:35 rmsyxakjbx_oldboy.html-rw-r--r-- 1 root root   0 8月   3 13:35 sxarorojil_oldboy.html-rw-r--r-- 1 root root   0 8月   3 13:35 wfqaymdmxc_oldboy.html-rw-r--r-- 1 root root 184 8月   3 13:32 while.sh-rw-r--r-- 1 root root   0 8月   3 13:35 yvgviwswze_oldboy.html-rw-r--r-- 1 root root   0 8月   3 13:35 zhikoyxipv_oldboy.html

The script reads as follows: (While loop implementation script)

12345678910 #!/bin/bash#date=2017-8-3cd/oldboyi=0while(( i<10 ))do   r=` head-c 500 /dev/urandom|tr-dc[a-z]|head-c 10|sed-r ‘s#[^a-z]#m#g‘`   touch"$r"_oldboy.html   ((i++))done

Description

The script execution results are as follows:

12345678910111213 [[email protected] oldboy]# ll总用量 4-rw-r--r-- 1 root root   0 8月   3 13:28 atncjmfwtd_oldboy.html-rw-r--r-- 1 root root   0 8月   3 13:28 bmbhdhvqmb_oldboy.html-rw-r--r-- 1 root root   0 8月   3 13:28 bmuqvcehgc_oldboy.html-rw-r--r-- 1 root root   0 8月   3 13:28 irfrxjjmny_oldboy.html-rw-r--r-- 1 root root   0 8月   3 13:28 mvprsmwvah_oldboy.html-rw-r--r-- 1 root root   0 8月   3 13:28 nxyfjkvekl_oldboy.html-rw-r--r-- 1 root root   0 8月   3 13:28 omqyxuykgq_oldboy.html-rw-r--r-- 1 root root   0 8月   3 13:28 smkxwfjepd_oldboy.html-rw-r--r-- 1 root root 184 8月   3 13:28 while.sh-rw-r--r-- 1 root root   0 8月   3 13:28 wkwmkktdcn_oldboy.html-rw-r--r-- 1 root root   0 8月   3 13:28 xtznpcuxem_oldboy.html

************************************

Enterprise Shell face question 2: Batch renaming special case *

************************************

The Oldboy string in the result file name in question 1 above will be changed to oldgirl (preferably with a For loop), and the extension HTML will all be changed to uppercase.

Answer:

The For Loop implementation script is as follows:

1234567 #!/bin/bash#date=2017-8-3cd/oldboyforin`ls|grep.*html`do  mv $i  `echo$i|sed-r ‘s#(.*)_oldboy.html#\1_oldgirl.HTML#‘`done

Description

The script execution results are as follows:

1234567891011 [[email protected] oldboy]# sh for2.shahqrvgmewi_oldgirl.HTMLcekphjpxmf_oldgirl.HTMLfodvkohejd_oldgirl.HTMLllymsvwhim_oldgirl.HTMLmejlzbfmna_oldgirl.HTMLmxqrnbgmnt_oldgirl.HTMLpkviyuhrum_oldgirl.HTMLshmmlxzkdu_oldgirl.HTMLwmgokfirna_oldgirl.HTMLwmmknomcmy_oldgirl.HTML

Other methods reference:http://wutengfei.blog.51cto.com/10942117/1951146

********************************************

Enterprise Shell face question 3: Batch Create special requirements user Stories *

********************************************

Batch Create 10 System account OLDBOY01-OLDBOY10 and set the password (password is random number, require characters and numbers and so on mixed).

Without a For loop implementation idea: http://user.qzone.qq.com/49000448/blog/1422183723

Answer:

1234567 #!/bin/bash #date =2018-8-3 for   in   ' seq  -w 1 10 ' Do     useradd  < Code class= "Bash plain" >oldboy$i -m     echo   Code class= "Bash plain" >| passwd   --stdin oldboy$i Code class= "Bash keyword" >done

Description

2017 the latest enterprise face Test Shell (ii)


Exercise 1:
write a shell script that lists the IP of the 192.169.5.0/24 network segment online. (Locate the active IP)

Requirements are as follows:

1. The online IP and the online IP are placed in two files respectively to facilitate later inspection;

2. Do not affect the operation of the current terminal;

3. After the script has finished running, give the message that the script has finished running.

The script reads as follows:

Method One:

1234567891011121314151617 #!/bin/bash[ -f /etc/init.d/functions] && . /etc/init.d/functions||exit1# 验证系统函数文件是否存在,如存在则调用系统函数,否则退出!ips="192.169.5."forin$(seq254)doping-c 2 $ips$i >/dev/null 2>/dev/nullif"$?"== "0"]then        echo"echo $ips$i is online">>/root/ip_online.txtelse        echo"echo $ips$i is not online">>/root/ip_noline.txtfidoneif"$ips$i"!= "192.169.5.255"];then        action "shell脚本执行完毕!"/bin/truefi

Method Two:

12345678910111213141516 #!/bin/bash[ -f /etc/init.d/functions] && . /etc/init.d/functions||exit1 # 验证系统函数文件是否存在,如存在则调用系统函数,否则退出!forip in$(cat/root/ip.txt)doping-c 2 $ip >/dev/null2>/dev/nullif "$?"== "0"]then        echo"echo $ip is online">>/root/ip_online.txtelse        echo "echo $ip is not online">>/root/ip_noline.txtfidoneif"$ip"!= "192.169.5.255"];then        action "shell脚本执行完毕!"/bin/truefi

Description

(1) If the script name ip_online.sh, execute the script without affecting the use of the current terminal, using the SH ip_online.sh & command.

(2) It is not recommended to use method two because editing a/root/ip.txt file is a waste of time.

This article is from the "Hand of the Paladin Control" blog, please make sure to keep this source http://wutengfei.blog.51cto.com/10942117/1961226

(ext.) 2017 the shell of the newest enterprise face Test (I, II)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.