Redhat Shell Scripting Exercises

Source: Internet
Author: User

Create a script

Create a script named/root/foo.sh on SYSTEM1 to provide the following features:

1. When running/root/foo.sh Redhat, the output is Fedora

2. When running/root/foo.sh fedora, output is Redhat

3. When no parameters or parameters are not redhat or fedora, the error output produces the following information:/root/foo.sh Redhat:fedora


Vim foo.sh

#!/bin/bash

Case $ in

Redhat

echo Fedora

;;

Fedora

Echo Redhat

;;

*)

Echo ' root/foo.sh Redhat:fedora '

;;

Esac

chmod +x foo.sh

./foo.sh Redhat

./foo.sh Fedora

./foo.sh 1


17. Create a script to add users

Create a script on system1, called/root/mkusers, that enables the creation of local Users for system SYSTEM1, and the user names of those users come from a file that contains a list of user names, while meeting the following requirements:

1. This script requires a parameter that is the file containing the list of user names

2. If no parameters are provided, this script should give the following message Usage:/root/mkusers then exit and return the corresponding value

3. If a nonexistent file name is provided, this script should give the following hint, input file not found and then exit and return the corresponding value

4. Created user login shell for/bin/false

5. This script does not need to set a password for the user

6. You can get the user name list as a test Http://rhgls from the URL below. Domain11.example.com/materials/userlist


Vim mkusers.sh

#! /bin/bash

If [$#-eq 0];then

Echo ' Usage:/root/mkusers '

Exit 1

Fi

if [!-F $]; Then

Echo ' Input file not found '

Exit 2

Fi

While Read line

Do

Useradd-s/bin/false $line

Done < $

chmod +x mkusers.sh

Create a userlist on your own, one user test on a single line

This article is from "Satan Daily" blog, please make sure to keep this source http://satantiantian.blog.51cto.com/6159537/1847331

Redhat Shell Scripting Exercises

Related Article

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.