Linux Nineth Day: (August 11) Exercises and assignments

Source: Internet
Author: User

Linux Nineth Day: (August 11) Exercises and assignments

Scripting/root/bin/systeminfo.sh Displays current host system information including hostname IPv4 address OS version kernel version CPU signal memory size hard disk size

server_ip= ' ifconfig|grep ' inet\b ' |grep-v ' 127.0.0.1 ' |tr-s "|cut-d '-f3 '
cpumod= ' lscpu|grep-i ' model name: '
meminfo= ' free-h|sed-n ' 2p ' |tr-s ' |cut-d '-f2 '
diskinfo= ' fdisk-l |sed-n ' 2p ' |sed-r ' s/.*[[:space:]][0-9].*gb). */\1/g '

Echo ' hostname: ' $ (hostname)
Echo ' HostIP: ' ${server_ip}
Echo ' OS version: ' $ (cat/etc/redhat-release)
Echo ' Kernel version: ' $ (uname-r)
Echo ' CPU: ' $CPUmod
Echo ' Memory: ' $Meminfo
Echo ' harddisk: ' $DISKinfo


Scripting/root/bin/backup.sh enables daily backup of/etc/directories to/ROOT/ETCYYYY-MM-DD

Backupdir= "/root/etc$ (date +%f)"
CP-A/etc $backdir
echo "Backup $backdir finished."


Scripting/root/bin/disk.sh Displays the maximum space utilization in the current hard disk partition

Maxused= ' df-h|grep '/dev/sd ' |tr-s "|sort-nr-t"-k5 |head-l |cut-d '-f5 '
echo ' HDD partition utilization maximum: ' $maxused


Scripting/root/bin/links.sh shows the number of IPV4 addresses and connections for each remote host connecting to this host, sorted by number of connections

Netstat-nt |tr-s ' |cut-d '-f5|tr-cs ' 0-9. ' ' \ n ' |egrep ' ([0-9]+.) {3} [0-9]+ ' |sort |uniq-c|sort-nr|tr-s ' \ t '


Write a script/root/bin/sumid.sh calculate the sum of the 10th and 20 user IDs in the/etc/passwd file

dir=/etc/passwd
n=10
M=20
Id_10= ' Cat $dir |head-$n |tail-1|cut-d:-f3 '
Id_20= ' Cat $dir |head-$m |tail-1|cut-d:-f3 '
NUM=$[ID_10+ID_20]


uid1= ' sed-n ' 10p '/etc/passwd |cut-f:-f3 '
Uid2= ' sed-n ' 20p '/etc/passwd |cut-d:-f3 '
Let sumid= $UID 1+ $UID 2


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


file1= ' grep ' ^$ ' $1|wc-l '
File2= ' grep ' ^$ ' $2|wc-l '
Let sumspace= $File 1+ $File 2
echo "The sum of $ + $ spacelines is $Sumspace"
Unset File1
Unset File2
Unset sumspace


Write a script/root/bin/sumfile.sh statistics/etc/var/usr How many sub-directories and files are there

File1= ' ls-a/etc |wc-l '
File2= ' ls-a/var |wc-l '
file3= ' ls-a/usr |wc-l '
Let sumfile= $File 1+ $File $File 3
echo "The sum is $Sumfile"
Unset File1
Unset File2
Unset File3
Unset sumfile


Write a script/root/bin/argsmun.sh accept a file path as a parameter if the parameter is less than 1, prompt the user to "at least one parameter should be given" and exit immediately if the number of parameters is not less than 1 displays the number of blank lines in the file pointed to by the first argument.


Write a script/root/bin/argsnum.sh accept a file IPv4 as a parameter test whether it can be connected if the ping general prompts the user "the IP address can be accessed" if the user is not ping general prompts "The IP address is inaccessible"


Chmod-rw/tmp/file1 script/root/bin/per.sh To determine if the current user is not readable or writable by/tmp/file1


Scripting/root/bin/nologin.sh and LOGIN.SH implementations prohibit and allow normal users to log on to the system


Write a script/root/bin/hostping.sh, accept a host of the IPV4 address as a parameter, first determine whether the qualified 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"


Calculate the value of a 1+2+3+...+100


Calculates 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 prompt for errors, and to exit.


Linux Nineth Day: (August 11) Exercises and assignments

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.