Chinaunix

标题: 请教一个交互式的shell怎么写? [打印本页]

作者: davie5201314    时间: 2012-06-05 15:31
标题: 请教一个交互式的shell怎么写?
请教一个交互式的shell怎么写?
例如我要写一个添加用户shell,其他人只要执行这个脚本,就能根据自己需要,输入用户名和密码,完成操作!怎么写呢
作者: davie5201314    时间: 2012-06-05 17:09
人呢,版主呢,救命呢
作者: chenyx    时间: 2012-06-05 18:46
楼主去shell版提问下吧
作者: hanling1111    时间: 2012-06-27 15:05
shell不支持。用python吧。
作者: sai9924    时间: 2012-06-28 10:20
read -p "enter username & password:" user passwd
作者: SPringYu    时间: 2012-07-03 10:18
用expect 这个可以写!具体的,自己可以去找下资料!
作者: king_819    时间: 2012-07-03 16:33
回复 1# davie5201314


    使用expect 来交互

    #!/usr/bin/expect
    set user {YOUR_USER_NAME}
    set password {YOUPASSWOD}

作者: linux曾    时间: 2012-07-04 00:16
#!/bin/bash
read -p "input user name :" username
read -p "input user password :" userpwd
useradd $username
echo $userpwd | passwd --stdin $username

作者: davie5201314    时间: 2012-07-05 10:58
回复 8# linux曾


    这个不错,谢谢了
作者: ulovko    时间: 2012-07-26 09:51
本帖最后由 ulovko 于 2012-07-26 09:52 编辑
linux曾 发表于 2012-07-04 00:16
#!/bin/bash
read -p "input user name :" username
read -p "input user password :" userpwd
  1. #!/bin/bash
  2. read -p "input user name :" username
  3. read -p "input user password :" userpwd
  4. useradd $username
  5. echo $userpwd | passwd --stdin $username

  6. 建议密码部分改为:
  7. read -s -p "input user password :" userpwd
复制代码

作者: 昔日无知    时间: 2012-07-26 16:41
楼主去shell版提问下吧
作者: PKkingSon    时间: 2012-08-01 18:00
楼上对路,用其他语言和方法是炫耀和用牛刀杀鸡
作者: bun    时间: 2012-08-01 22:50
提示: 作者被禁止或删除 内容自动屏蔽
作者: happylsg_2000    时间: 2012-08-08 10:08
用python或perl完成吧,看看python的模块pexpect.py
作者: a314131070    时间: 2012-08-08 10:15
交互式shell与普通的shell差别不大,只是多了些交互的逻辑。
作者: venux    时间: 2012-08-09 09:17
http://www.love27.com/archives-276.html  看看是否对您有帮助
作者: zhlin0054    时间: 2012-08-10 13:16
挣点币,可以在站内发信息,谢谢
作者: gouxiongmao    时间: 2012-08-20 17:30
添加用户。。。。useradd   user1------这个就是交互的。
作者: berlin493    时间: 2012-08-25 13:36
非常不错,顶一个




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2