Python employment class shell operations exercise training

Source: Internet
Author: User
Tags log log disk usage

Note: Beginner shell, the following is my own written answer, if there is better, please advise!

1. Ask for the sum of 2 numbers:

2. Calculate 1-100 of the and

3. change the extension of all files in a directory to bak

4. Compile and execute all. c files in the current directory

5. Print the swap partition size of the machine, processing result: swap:1024m

6. Text analysis, remove the number of occurrences of the shell in/etc/password

The result of the first method:

4/bin/bash

1/sbin/halt

2/sbin/nologin

7. Document collation, employee document records the work number and the name

Jason Smith

John Doe

Sanjay Gupta

Ashok Sharma

Record work number and salary in bonus file:

100 $5,000

200

300 $3,000

400 $1,250

Request to merge two files and output as follows, processing the result:

Ashok Sharma $1,250

Jason Smith $5,000

John Doe

Sanjay Gupta $3,000

Sort employee.txtsort Salary.txtjoin Employee.txt salary.txt | Sort-k2

8. Write a shell script to get the current date, time, user name and current working directory.

1 #!/bin/bash 2 echo "The present date is: ' Date '"  3 echo "The present user is: ' WhoAmI '" 4 echo "The present Dir i S: ' pwd ' "   

9. Write the shell script to get the network address of this machine.

# !/bin/bash " ip=$ (ifconfig eth3| sed-n '/inet addr:/p ' |awk ' {print $} ' |awk-f: ' {print $} ') "

10. Write a shell script to transfer files larger than 10K in the current directory to the/tmp directory

1 #!/bin/bash 2 for file in $ (ls-l | awk "$ >100 {print $9} ') 3 do 4         

11. Write a script named myfirstshell.sh, which includes the following content.

A) contains a comment that lists your name, the name of the script, and the purpose of writing the script.

b) Greeting the user.

c) Displays the date and time.

d) display the calendar for this month.

E) Displays the name of your machine.

f) Displays the name and version of the current operating system.

g) Displays a list of all files in the parent directory.

h) Shows all processes that root is running.

i) Displays the value of the variable term, path, and home.

j) Display of disk usage.

k) Print out your group ID with the ID command.

m) say "good bye" with the user

  1 #!/bin/bash  2 echo "hello!"  3 echo "Today is: $ (date)"  4 #echo $ (date)  5 echoes "This month was:"  6 cal  7 echo "The hostname is: $ (hos Tname) "   8 echo" The name of the OS is $ (uname-r) and the verion was $ (uname-r) "  9 echo" The files are: $ (ls-l. /) "Ten echoes" the running process of root is $ (ps-u root) "One echo" term= $TERM "echo" path= $PATH "echo" Home= $HOME " echo "The use of disk was: $ (DF-LH)" echo "The ID of the group is $ (id-g)" echo "Goodbye sir!"

12. File move copy, have m1.txt m2.txt m3.txt m4.txt, create the corresponding directory, M1 m2 M3 M4 and move the file to the corresponding directory

  1 #!/bin/bash  2 touch m1.txt m2.txt m3.txt m4.txt  3 for ((i=1;i<=4;i++))  4 do  5         mkdir m$i  6< C7/>MV m$i.txt  m$i  7 Done

13. Terminal Enter a file name to determine if the device file

  1 #!/bin/bash  2 #coding =utf-8  3 echo "Please input a filename:"  4 read filename  5 if [-C $fileName-O -B $fileName]  6 then  7         echo "$fileName is a device file! "  8 Else  9         echo" $fileName not a device file! "Ten fi

14. Statistics IP access: Requires analysis of Apache access logs to find out the number of access pages in the first 100 bits of IP. The log size is around 78M. The following is an excerpt of Apache's access log:

202.101.129.218--[26/mar/2006:23:59:55 +0800] "get/online/stat_inst.php?pid=d065 http/1.1" 302 20-"-" "-" "MOZILLA/4. 0 (compatible; MSIE 6.0; Windows NT 5.1) "

For more information on Apache logs, see 70153166

The sixth item of logging information is the status code. It tells us whether the request was successful or what kind of error was encountered. Most of the time, this value is 200, which indicates that the server has successfully responded to browser requests and everything is fine. You are not prepared to give a complete list of status codes and to explain what they mean, please refer to the relevant information. In general, however, a status code starting with 2 indicates success , and a status code starting with 3 indicates that the user request was redirected to a different location for a variety of reasons, in 4 The status code at the beginning indicates that a client has some kind of error , and a status code starting with 5 indicates the server An error was encountered .

1 #!/bin/bash2 awk ' {print $} ' |sort |uniq-c |SORT-K1NR | Head-n 100
Execute script: Source apache.sh Apache (file)

15. Design a shell program, set up 50 directories in the/userdata directory, that is, USER1~USER50, and set the permissions of each directory, where the permissions of the other users are: Read, the file owner's permissions are: Read, write, execute, the permissions of the group of the file owner are: Read, execute.

  1 #!/bin/bash  2 cd/userdata  3 for ((i=1;i<=50;i++))  4 do  5         mkdir user$i  6         chmod 754 User$i  7 Done

16. Design a shell program, add a new group as Class1, and then add 30 users belonging to this group, the user name is Stdxx, where xx from 01 to 30, and set the password for the corresponding stdxx.

  1 #!/bin/bash  2 #coding =utf-8  3 #设计一个shell程序, add a new group for Class1, and then add 30 users belonging to this group, the user name is Stdxx, where xx is from 01 to 30, and set the password for the corresponding stdxx.  4 groupadd Class1  5 I=1  6 while [$i-le]  7 does  8         if [$i-lt] 9 then         10
   useradd-g Class1 std0$i                 passwd std0$i std0$i (         else                 ) useradd-g Class1 std$i PASSW D std$i std$i         "i++"

17. Write Shell program, realize the function of automatically delete 30 accounts. The account name is STD01 to Std30.

  1 #!/bin/bash  2 i=1  3 while [$i-le]  4 does  5         if [$i-lt] 6 then  7                 Userdel std 0$i  8         Else  9                 userdel std$i         fi one Let         "i++"

18. User cleanup, clear all users except the current login user

Kill $ (Who-u | grep-v ' WhoAmI ' | awk ' {print $6} ' |sort-u)

19. Script implementation, you can use Shell, Perl and so on. Locate 100 files starting with ABC in the Directory/TMP, and then save the first line of these files to the file new.

  1 #!/bin/bash  2 #coding =utf-8  3 #在目录/tmp find 100 files beginning with ABC, and then save the first line of these files to the file new.  4 files= ' Find-type f-name "d*" | head-n ' 5 for  file in $files 6 do  7         sed-n ' 1p ' $file >> New  

20. Save all the rows in file B, but not in file a, to file C and count the number of lines in C.

21. View TCP Connection Status

Netstat-ant | awk ' {print $6} ' |sort |UNIQ-C|SORT-K1NR

22. The number of lookup requests is 20 IP (often used to find the attack source)

Netstat-atn | grep |awk ' {print $} ' |awk-f: ' {print $} ' |sort|uniq-c |sort

23. Find more Time_wait connections

Netstat-n | grep ' time_wait ' | awk ' {print $} ' |sort | Uniq-c |SORT-K1NR

24. Get access to the top 10 IP addresses, access.log log records

61.155.149.20--[13/jan/2017:15:42:47 +0800] "get/category/db/http/1.1" 200 23225

Cat Access.log | awk ' {print '} ' | Sort |uniq-c |sort-nr | Head-n10

 

Python employment class shell operations exercise training

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.