Linux Nineth Week

Source: Internet
Author: User

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/bash


Awk-f: ' $NF ~ '/sbin/nologin ' {shell++} $NF!~ "/sbin/nologin" {noshell++} end{printf "Shell:%d \ t Noshell:%d \ n", Shell,nos Hell} '/etc/passwd


2. 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;

3, 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;

4, 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;

5, 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;

6. Write a script that accepts 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;

7, write a script, get the host name of the current host, judge

(1) If the hostname is empty or localhost, or "(none)", it is named mail.magedu.com;

(2) Otherwise, display the existing host name can be;

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;

10, write a script, pass a user name parameter to the script;

(1) If the user's ID number is greater than or equal to 500, and its default shell is a string ending in sh, the "a user can log system" is displayed. The string of the class;

(2) Otherwise, the display can not log on the system;

11. Write a script to complete the following tasks:

(1) Sequentially copy each direct file or subdirectory in the/var/log directory to the/TMP/TEST1-TESTN directory, respectively;

(2) The Cp-r command is used only when copying the directory;

(3) use CP command when copying files;

(4) Use the cp-d command when copying a linked file;

(5) All remaining types, using the CP-A command;


This article is from the "Chase Dream" blog, please be sure to keep this source http://sihua.blog.51cto.com/377227/1844086

Linux Nineth Week

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.