shell脚本,用于将新用户添加到系统中,从.txt文件中获取信息 [英] shell script to add new users to the system taking the information from a .txt file

查看:177
本文介绍了shell脚本,用于将新用户添加到系统中,从.txt文件中获取信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,大家好

首先,我想感谢大家对论坛(管理员,用户......),这是一个非常有价值的资源一个人,包括我。

我不知道这是不是在哪里问这个问题,我的问题是关于我的功课。如果不是,请,管理员可以把它移到正确的地方吗?...我对练习有点困惑,所以如果有人能指出我正确的方向(或者给我答案)我会成为非常感激:



给出一个名为 users.tx t的文本文件,其中包含以下信息:



Adam:2299:/ home / store;



John:8855:/ home / accounts;



Lisa:7744:/ home / secondstore;



Mary:6677:/ home / address;



脚本应使用每行的第一个单词创建用户,每行的第二个单词将用作密码,第三个单词用作主目录。内部字段分隔符为:



我只能使用 awk shellscripting 进行练习。老师指出其中一个可行的解决方案包括AWK内部使用的SYSTEM命令......但还有其他只使用shellcripting的解决方案。



我正在尝试( as root)

Hello, everybody
First of all, I'd like to say thank you to all of you for the forum (admins, users...), it's a really valuable resource for a lot a people, including me.
I don't know if this is the right place where to ask this, my question is about my homework. If it's not, please, could an admin move it to its right place?... I'm a bit confused with an exercise, so if anybody can point me in the right direction (Or give me the answer) I'll be really gratefull:

Given a text file called users.txt with this info inside:

Adam:2299:/home/store ;

John:8855:/home/accounts ;

Lisa:7744:/home/secondstore ;

Mary:6677:/home/address ;

The script should create an user using the first word of each line, the second word of each line will be used as password, and the third one as the home directory. The internal field separator is :

I can only use awk or shellscripting for the exercise. The teacher pointed that one of the posible solutions includes the SYSTEM command used inside AWK...but there are other solutions using only shellscripting.

I'm trying with (as root)

$ awk -F ':| ' '{ print("adduser --home", $3, $1"; echo", $2 " | passwd", $1) | "/bin/bash" }' users.txt



我不知道为什么它不起作用



任何提示,任何其他方式的建议或任何帮助将是非常贬值的

谢谢


I don't know why it doesn't work

Any hint, any suggestion of other way of doing this or any help will be very apreciated
thanks

推荐答案

awk -F ' : ' ' {print(adduser --home,
awk -F ':| ' '{ print("adduser --home",


3,


1; echo,


这篇关于shell脚本,用于将新用户添加到系统中,从.txt文件中获取信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆