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