【问题标题】:How to start with shell script with .info file?如何从带有 .info 文件的 shell 脚本开始?
【发布时间】:2020-07-19 11:21:00
【问题描述】:

我的一个朋友已经开始学习 shell 脚本并完成了一项小任务,但他不知道如何开始以及从哪里开始。

Problem statement is:

a. Create a file 'user_UserID.info' file under /tmp. Populate the file 'user_UserID.info' with the following data:
Username,Password,PrimaryGroup,Comment,HomeDir

b. Create a Shell script to add user accounts and set the password for the users listed in 'user_UserID.info' file. All other 
dependent activities like group creation, directory creation etc. also should be done through this script.

c. Display the content of /home directory on console. Redirect the newly created 3 user’s information to userdetails_UserID.txt

这里,如何创建.info文件,它的目的是什么?

请提出建议。任何建议或好的资源都会有所帮助。

谢谢。

【问题讨论】:

    标签: linux shell unix command-line


    【解决方案1】:

    简单的脚本,你可以在网上找到上百万个这样的脚本,只需要搜索。

    #!/bin/bash 
    
    while read line
    do
                    USERNAME=$(echo $line | awk -F ',' '{print $1}')
                    PASSWORD=$(echo $line | awk -F ',' '{print $2}')
                    PRIMARY_GROUP=$(echo $line | awk -F ',' '{print $3}')
                    COMMENT=$(echo $line | awk -F ',' '{print $4}')
                    HOME_DIR=$(echo $line | awk -F ',' '{print $5}') 
    
                    groupadd $PRIMARY_GROUP
                    useradd -mc $COMMENT -s /bin/bash -d $HOME_DIR $USERNAME -g $PRIMARY_GROUP
                    yes "$PASSWORD" | passwd $USERNAME
    done < ./user_UserID.info
    

    【讨论】:

    • 谢谢。您能否分享一些参考链接以进一步了解 shell 脚本。
    • @User_1191 如果解决了您的问题,请确认答案,谢谢。
    猜你喜欢
    • 2013-06-29
    • 2015-09-07
    • 1970-01-01
    • 2017-06-16
    • 1970-01-01
    • 1970-01-01
    • 2013-05-18
    • 2011-03-28
    • 2022-01-12
    相关资源
    最近更新 更多