Shell Exercises (vi)

Source: Internet
Author: User

Exercise 1:Enter a number to execute the corresponding command

Requirements: Enter a number and then run one of the corresponding commands. The commands shown are as follows: *cmd meau* 1-date 2–ls 3–who 4–pwd; when input 1 o'clock, run date, enter 2 o'clock to run LS, and so on.

Reference Answer:

#!/bin/bash# date:2018 February 23 echo "*cmd menu* 1-date 2-ls 3-who 4-pwd" read-p "Please input a choice 1-4:" Choicecase $ch   Oice in 1) date;;   2) LS;   3) who;;   4) pwd;; *) echo "Choose in 1-4" Esac


Exercise 2: create a user and set a password in bulk

requirements: add user_00–user_09 10 users, and give them a random password, the password requires 10 bits containing uppercase and lowercase letters and numbers, note that each user's password needs to be recorded in a log file

Hint: 1. Random password use command mkpasswd
2. In the script to set the user password, you can use the echo and then pipe passwd command

Reference Answer:

#!/bin/bash# date:2018 February 23 for I in ' seq-w ' do useradd user_$i pass= ' mkpasswd-s 0-l ' echo ' user_$i: $pa SS ">>/tmp/user0_9.pass Echo $pass |passwd user_$i--stdindone


Shell Exercises (vi)

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.