exam questions

Exam EX300 All Questions

View all questions & answers for the EX300 exam

Exam EX300 topic 2 question 15 discussion

Actual exam question from RedHat's EX300
Question #: 15
Topic #: 2
[All EX300 Questions]

Create a script to add users -
Create a script named /root/mkusers on the system1, this script can achieve to add local users for the system1, and user names of these users are all from a file which contains the usernames list, and meet the following requirements at the same time:
1. This script is required to provide a parameter; this parameter is the file which contains the usernames list

2. This script need provide the following message: Usage /root/mkusers if it does not provide a parameter, then exit and return the corresponding value
3. This script need provide the following message: Input file not found if it provides a name that does not exist, then exit and return the corresponding value
4. Create a user shell log into /bin/false
5. This script does not need to set password for users
6. You can get the usernames list from the following URL as a test: http://rhgls. domain11.example.com/materials/ userlist

Show Suggested Answer Hide Answer
Suggested Answer: See Explanation
vim mkusers.sh
#! /bin/bash
if [ $# -eq 0 ];then
echo 'Usage:/root/mkusers'
exit 1
fi
if [ ! -f $1 ]; then
echo 'Input file not found'
exit
fi
while read line
do
useradd -s /bin/false $line
done < $1
:wq
chmod +x mkusers.sh
http://rhgls.domain11.example.com/materials/userlist
wget
./mkusers.sh userlist

Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
snota45
5 months, 2 weeks ago
I wrote the script like this #! /bin/bash if [ -z "$1" ];then echo Usage:/root/mkusers elif [ ! -f "$1" ];then echo Input not found else for e in `cat $1`;do useradd $e -s /bin/false;done; fi
upvoted 1 times
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...
exam
Someone Bought Contributor Access for:
SY0-701
London, 1 minute ago