Simple shell Script Programming example

Source: Internet
Author: User

1, write script/root/bin/systeminfo.sh, display the current host system information, including host name, IPV4 address, operating system version, kernel version, CPU model, memory size, hard disk size.


Script content:

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/85/E3/wKioL1etfkTxkwxZAAA_-okK9Bk385.png "style=" float: none; "title=" 1.png "alt=" Wkiol1etfktxkwxzaaa_-okk9bk385.png "/>

Execution Result:

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M02/85/E4/wKiom1etfkWRsFbCAAArgQP1C8s247.png "style=" float: none; "title=" 2.png "alt=" Wkiom1etfkwrsfbcaaargqp1c8s247.png "/>

2, scripting/root/bin/backup.sh, can be implemented daily/etc/directory backup to/root/etcyyyy-mm-dd

Script content:

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M00/85/E4/wKioL1etfsfDkssEAAAWFi_UOyI621.png "style=" float: none; "title=" 2.2.png "alt=" Wkiol1etfsfdksseaaawfi_uoyi621.png "/>

Execution Result:

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M00/85/E4/wKiom1etfsfzgNdMAAAbstX6qjU643.png "title=" 2.1. PNG "style=" Float:none; "alt=" Wkiom1etfsfzgndmaaabstx6qju643.png "/>

3. Write script/root/bin/disk.sh, showing the maximum space utilization value in the current hard disk partition

Script content:

650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M01/85/E4/wKioL1etf0HToCiKAAAmkpMMmsI984.png "style=" float: none; "title=" 3.1.png "alt=" Wkiol1etf0htocikaaamkpmmmsi984.png "/>

Execution Result:

650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M02/85/E4/wKioL1etf0KhNdp-AAAkuugzxj8752.png "style=" float: none; "title=" 3.2.png "alt=" Wkiol1etf0khndp-aaakuugzxj8752.png "/>

4. Write Script/root/bin/links.sh, show the IPV4 address and connection number of each remote host connecting to this host, and sort by the number of connections from large to small

Script content:

650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M01/85/E4/wKioL1etf7ChajggAAAp9FNiX6o465.png "style=" float: none; "title=" 4.1.png "alt=" Wkiol1etf7chajggaaap9fnix6o465.png "/>

Execution Result:

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M01/85/E4/wKiom1etgR2husSGAAAP1y9LuDk360.png "title=" 4.2. PNG "alt=" Wkiom1etgr2hussgaaap1y9ludk360.png "/>

5, write a script/root/bin/sumid.sh, calculate the/etc/passwd file of the 10th user and the 20th user ID of the sum

Script content:

650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M01/85/E4/wKioL1etgC_wRdooAAAvB3xEYQs369.png "style=" float: none; "title=" 5.1.png "alt=" Wkiol1etgc_wrdooaaavb3xeyqs369.png "/>

Execution Result:

650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M00/85/E4/wKiom1etgJiQlyTPAAAIwn3u6-s113.png "title=" 5.2. PNG "alt=" Wkiom1etgjiqlytpaaaiwn3u6-s113.png "/>

6, write a script/root/bin/sumspace.sh, pass two file paths as parameters to the script, calculate the sum of all the blank lines in these two files

Script content:

650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M01/85/E4/wKiom1etgZvwRqrIAAA65InbEX4262.png "style=" float: none; "title=" 6.1.png "alt=" Wkiom1etgzvwrqriaaa65inbex4262.png "/>

Execution Result:

650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M01/85/E4/wKioL1etgZuALnKcAAAQr_AIpF4320.png "style=" float: none; "title=" 6.2.png "alt=" Wkiol1etgzualnkcaaaqr_aipf4320.png "/>

7, write a script/root/bin/sumfile.sh, statistics/etc,/var,/usr directory total number of sub-directories and files

Script content:

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M01/85/E4/wKiom1etggOhiZ5EAAAyBkYzwBs520.png "style=" float: none; "title=" 7.1.png "alt=" Wkiom1etggohiz5eaaaybkyzwbs520.png "/>

Execution Result:

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M00/85/E4/wKiom1etggPCzjD4AAANYcJv56o413.png "style=" float: none; "title=" 7.2.png "alt=" Wkiom1etggpczjd4aaanycjv56o413.png "/>

8, write a script/root/bin/argsnum.sh, accept a file path as a parameter, if the number of parameters is less than 1, the user is prompted "at least one parameter should be given" and immediately exit, if the number of arguments is not less than 1, the number of blank lines in the file pointed to by the first parameter is displayed

Script content:

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/85/E4/wKiom1etgnjgXTXwAAA8UDwEYA0415.png "style=" float: none; "title=" 8.1.png "alt=" Wkiom1etgnjgxtxwaaa8udweya0415.png "/>

Execution Result:

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/85/E4/wKiom1etgnjA8cnNAAAXmsykDmg163.png "style=" float: none; "title=" 8.2.png "alt=" Wkiom1etgnja8cnnaaaxmsykdmg163.png "/>

9, write a script/root/bin/hostping.sh, accept a host's IPv4 address as parameters, test whether it can be connected. If Ping is available, the user is prompted to "the IP address is accessible" and if it is not ping, the user is prompted "The IP address is inaccessible"

Script content:

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/85/E4/wKioL1etg12BL4SNAAAyp2Ck94Q008.png "style=" float: none; "title=" 9.1.png "alt=" Wkiol1etg12bl4snaaayp2ck94q008.png "/>

Execution Result:

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/85/E4/wKiom1etg13Ah43AAAAWhgFxkiU110.png "style=" float: none; "title=" 9.2.png "alt=" Wkiom1etg13ah43aaaawhgfxkiu110.png "/>

10, Chmod-rw/tmp/file1, write script/root/bin/per.sh, determine whether the current user/tmp/fiile1 file is not readable and not writable

Script content:

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M01/85/E4/wKioL1etg8SDVARzAAAd7pzEaLA478.png "style=" float: none; "title=" 10.1.png "alt=" Wkiol1etg8sdvarzaaad7pzeala478.png "/>

Execution Result:

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M01/85/E4/wKiom1etg8WidvsDAAAuXI0Jd28778.png "style=" float: none; "title=" 10.2.png "alt=" Wkiom1etg8widvsdaaauxi0jd28778.png "/>

11, write scripts/root/bin/nologin.sh and login.sh, implement prohibit and allow ordinary user login system.

Script nologin.sh:

650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M00/85/E4/wKioL1ethAaCs7_GAAAju8hGZKI593.png "style=" float: none; "title=" 11.1.png "alt=" Wkiol1ethaacs7_gaaaju8hgzki593.png "/>

Script login.sh

650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M02/85/E4/wKiom1ethAeD2eepAAAeN4m1OXY613.png "style=" float: none; "title=" 11.2.png "alt=" Wkiom1ethaed2eepaaaen4m1oxy613.png "/>

12, write a script/root/bin/hostping1.sh, accept a host of the IPV4 address as a parameter, first determine whether the IP, no, prompt IP format is not valid and exit, is, test whether can be connected. If Ping is available, the user is prompted to "the IP address is accessible" and if it is not ping, the user is prompted "The IP address is inaccessible"

Script content:

650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M00/85/E4/wKioL1ethNzjiM_SAABNObJSp-M072.png "style=" float: none; "title=" 12.1.png "alt=" Wkiol1ethnzjim_saabnobjsp-m072.png "/>

Execution Result:

650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M01/85/E4/wKiom1ethNySrmrTAAAnassVfwY321.png "style=" float: none; "title=" 12.2.png "alt=" Wkiom1ethnysrmrtaaanassvfwy321.png "/>

13, calculate the value of 1+2+3+...+100

Script content:

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/85/E4/wKioL1ethUXiFe4oAAAYRbN0Ao4263.png "style=" float: none; "title=" 13.1.png "alt=" Wkiol1ethuxife4oaaayrbn0ao4263.png "/>

Execution Result:

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/85/E4/wKioL1ethUaTw6x9AAAJremGS9U917.png "style=" float: none; "title=" 13.2.png "alt=" Wkiol1ethuatw6x9aaajremgs9u917.png "/>

14. Calculate the sum of all the numbers from the first parameter a of the script to the second parameter B, to determine if B is greater than a, to indicate the error and

Exit, is the calculation of the

Script content:

650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M01/85/E4/wKiom1ethfuRNAmsAAAunRw3Yk4808.png "style=" float: none; "title=" 14.1.png "alt=" Wkiom1ethfurnamsaaaunrw3yk4808.png "/>

Execution Result:

650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M00/85/E4/wKioL1ethfvioAWIAAAlJ8XHcRU152.png "style=" float: none; "title=" 14.2.png "alt=" Wkiol1ethfvioawiaaalj8xhcru152.png "/>


This article is from the "I ' m Groot" blog, so be sure to keep this source http://groot.blog.51cto.com/11448219/1837345

Simple shell Script Programming example

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.