1. Write a script to determine whether the shell of all users on the current system is a login shell (that is, the user's shell is not/sbin/nologin), the number of these two types of users, and the string comparison;
#!/bin/bashlogin= ' grep-v '/sbin/nologin$ '/etc/passwd | Wc-l ' nologin= ' grep '/sbin/nologin$ '/etc/passwd | Wc-l ' echo ' can be logged in user $login "echo" non-logged in user total $nologin "
Second, write a script
(1) Obtain the host name of the current host and save it in the hostname variable;
(2) Determine if the value of this variable is localhost, and if so, modify the current hostname to www.magedu.com;
(3) Otherwise, the current host name is displayed;
#!/bin/bashhn= ' hostname ' if [[$hn = = ' localhost ']];then hostname wwww.magedu.comelse echo $hnfi
Three, write a script to complete the following functions
(1) Pass a disk device file path to the script to determine whether the device exists;
(2) If present, displays all the partition information on this device;
[[email protected] shell]# cat disk.sh #!/bin/bashdisk= ' fdisk -l | grep -o "^ disk /dev/sd[a-z]" | awk ' {print $2} ' for i in $ diskdoecho "Disk device $i" partition= ' fdisk -l | egrep -o "^${i}[1-9" df -h $partition echodone [[email protected] shell]# ./ disk.sh Disk device/DEV/SDA file system capacity used available used% mount point/dev/sda1 477m 94m 354m 21% /boot/dev/sda2 75g 1.6g 69G 3% /devtmpfs 1.9g 0 1.9g 0% /dev Disk device/DEV/SDC file system capacity used available used% mount point/dev/sdc1 9.8G 37M 9.2G 1% /data2/dev/sdc2 9.8g 37m 9.2g 1% / data3 Disk device/dev/sdb file system capacity used available used% mount point/dev/sdb1 9.8g 37m 9.2g 1% /data1
Four, write a script to complete the following functions
The script can accept a parameter;
(1) If the parameter 1 is quit, the exit script is displayed, and the normal exit is performed;
(2) If the parameter 1 is yes, the execution script is displayed;
(3) Otherwise, the parameter 1 is any other value, performs an abnormal exit;
#!/bin/bashread-p "Please input option:" Optioncase $option Inquit) echo "quit" exit 0;; YES) echo "continue";; *) echo "error" exit 1;; Esac
Five, write a script to complete the following functions
Pass a parameter to the script, this parameter is one of gzip, bzip2 or XZ;
(1) If the value of parameter 1 is gzip, use the TAR and gzip archive to compress/etc directories into the/backups directory and name/backups/etc-20160613.tar.gz;
(2) If the value of parameter 1 is bzip2, use tar and bzip2 archive to compress/etc directory to/backups directory, and named/backups/etc-20160613.tar.bz2;
(3) If the value of parameter 1 is XZ, then the tar and XZ archives are used to compress/etc directories into the/backups directory and named/backups/etc-20160613.tar.xz;
(4) Any other value, the error compression tool is displayed, and an abnormal exit is performed;
#!/bin/bashread -p "please select the compression format in (GZIP|BZIP2|XZ) " optioncase $option ingzip) tar -zcf /backups/etc-' date "+%Y%m%d" '. tar.gz /etc &> /dev/null ;; bzip2) tar -jcf /backups/etc-' date "+%Y%m%d" '. tar.bz2 /etc &> /dev/null ;; XZ) tar -jcf /backups/etc-tar -' date ' +%Y%m %d "' .tar.xz /etc &> /dev/null ;; *) echo "error!" exit 1 ;; Esac
Six, write a script, accept a path parameter:
(1) If it is an ordinary document, it can be accessed normally;
(2) If it is a catalog file, then the CD command is available for it;
(3) If the file is a symbolic link, the description is a access path;
(4) Other is impossible to judge;
#!/bin/bashread-p "Please enter a path:" Pathif [-F $path];then echo "Files Accessible" elif [-D $path];then echo "Directory accessible" elif [-H $path];then echo "This is path" else echo "something Error" fi
Seven, write a script, get the host name of the current host, judge
(1) If the host name is empty or localhost, or "(none)", it is named mail.magedu.com;
(2) Otherwise, display the existing host name can be;
#!/bin/bashhn= ' hostname ' IF [-Z $hn-o $hn = = "localhost"-o $hn = = "(none)"]];then hostname mail.magedu.com Echo "Modify host Name: mail.magedu.com" Else echo "current hostname: $HN"
8, write a script, accept a user name as a parameter;
(1) If the user's ID number is 0, it is displayed as an administrator;
(2) If the user's ID number is greater than 0 and less than 500, it is displayed as a system user;
(3) Otherwise, it is displayed as a normal user;
#!/bin/bashwhile truedoread-p "Please enter a username:" Usernameif! ID $username &>/dev/null;thenecho "no This user" elsebreakfidoneuserid=$ (id-u $username) if [[$userid-eq 0]];then echo "$username is admin" elif [[$userid-lt]];then Echo ' $username is the system user "else echo" $username is a normal user "fi
Seventh week job "Linux Micro Jobs"