1. User created script(1) Design file judgment module (2) Design user establishment (3) File content Script content #!/bin/bash USERADD(){ #User created function RN=$(sed -n '$=' $1) for ((I=1;I<=$RN;I++)) do user=`sed -n "$I"p $1` password=`sed -n "$I"p $2` id $user &>/dev/null # Check if the user exists [ $? -eq 0 ] && { echo "$user already exists" }||{ useradd $user #Create a new user in $user echo "$password" | passwd --stdin $user &> /dev/null [ $? -eq 0 ] && { echo "$user user created successfully" } } done } # Judgment module [ $# -lt 2 ] && { #Judge whether the file is less than two echo "ERROR: Insufficient number of files!!" }||{ [ -e $1 -a -e $2 ]&& { #Judge whether the file exists #Judge whether the number of lines of two files are equal [ `sed -n '$=' $1` -eq `sed -n '$=' $2` ] &&{ USERADD $1 $2 #Call user created function}||{ echo "ERROR: The number of lines in the file is inconsistent!!" } }||{ echo "ERROR: The file does not exist!!" } } 2. Word Guessing Game#!/bin/bash Number=7 while true do read -p "Please enter a number: " NUM if [ $NUM = $Number ] then echo "Congratulations, you guessed it right!!!" exit elif [ $NUM -lt $Number ] then echo -n "The number is too small!" elif [ $NUM -gt $Number ] then echo -n "The number is too large!" else echo -n "error" fi done 3. Network card traffic monitoring(1) Judgment module (2) Display module Use the clear command to clear the screen The same line of output shows (3) Script content #!/bin/bash [ -z $* ] && { echo "ERROR: Not input net device!" }||{ Device=`ifconfig $* 2> /dev/null`&&{ while true do RXpre=$(cat /proc/net/dev | grep $1 | tr : " " | awk '{print $2}') TXpre=$(cat /proc/net/dev | grep $1 | tr : " " | awk '{print $10}') # Get the traffic received and sent by the network port after 1 second sleep 1 RXnext=$(cat /proc/net/dev | grep $1 | tr : " " | awk '{print $2}') TXnext=$(cat /proc/net/dev | grep $1 | tr : " " | awk '{print $10}') # Get the actual inbound and outbound traffic in this 1 second RX=$((${RXnext}-${RXpre})) TX=$((${TXnext}-${TXpre})) TX=$(echo $TX | awk '{print $1/1024 " KB/s "}') RX=$(echo $RX | awk '{print $1/1024 " KB/s "}') #Refresh the monitoring display on the same line #echo -ne "input: $RX \t\toutput: $TX " #echo -ne "\r" clear # Use clear to clear the screen and then display echo -ne "input: $RX \noutput: $TX " done }||{ echo "$1 is not exist" } } This is the end of this article about Linux user script creation/word guessing game/network card traffic monitoring. For more relevant Linux script guessing game monitoring content, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future! |
<<: Vue encapsulation component tool $attrs, $listeners usage
>>: Detailed basic operations on data tables in MySQL database
1. Overview Users expect the web applications the...
Achieve results step 1. Initial index.html To bui...
Disadvantages of Tables 1. Table takes up more byt...
XHTML defines three document type declarations. T...
Table of contents 1. Variables Use meaningful nam...
Asynchronous replication MySQL replication is asy...
Simple use of Vue bus Scenario description: Compo...
1. HTML tags with attributes XML/HTML CodeCopy co...
1. Introduction to Distributed Storage System Wit...
Table of contents 1 Test Cases 2 JS array dedupli...
This article records the installation tutorial of...
I used Vue.js to make a nine-grid image display m...
I encountered a very unusual parameter garbled pro...
The following is a picture mouse hover zoom effec...
/******************** * Character device driver**...