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
Table of contents 1. Preparation 2. Define the gl...
Copy code The code is as follows: <html> &l...
First of all, we need to know what a state manage...
Linux environment variable configuration When cus...
Create a project directory mkdir php Create the f...
Recently, when I was using the Linux operating sy...
Database MySQL version 8.0.18 Download a DBeaver....
In the process of team development, it is essenti...
DNS (Domain Name Server) is a server that convert...
Table of contents Error demonstration By computed...
CSS naming rules header: header Content: content/c...
This article uses examples to explain the concept...
The latest Insider version of Visual Studio Code ...
As a front-end developer, I can’t avoid IE’s pitf...
1. Use Centos image to build local yum source Sin...