分页: 1 / 1
写一个很简脚本的,问题出在哪里,各位来看看吧
发表于 : 2006-12-08 9:58
由 always.zhang
我是写一个自动重启网卡的脚本
#!/bin/bash
sudo ifdown eth0
12345678>stdin //想让它自动输入密码,我的密码是12345678
sudo ifup eth0
但是执行的时候,它却要让我输入密码。这个怎么回事呢?
发表于 : 2006-12-18 20:57
由 sigma
这样肯定是不对的
应该要用到一个叫expect的东西
用这个脚本试试 :
代码: 全选
#!/usr/bin/expect -f
spawn sudo ifdown eth0
expect {
Password: { send "12345678\r";exp_continue }
}
exit
发表于 : 2006-12-20 11:23
由 always.zhang
还是出错
netrestart2: 2: spawn: not found
netrestart2: 3: expect: not found
netrestart2: 4: Password:: not found
netrestart2: 4: exp_continue: not found
netrestart2: 5: Syntax error: "}" unexpected
恩,还是谢谢前辈啦。继续研究中
发表于 : 2006-12-20 15:32
由 moonchild
这个用here文档行么?
你试试
发表于 : 2007-05-06 22:39
由 iamdxlwh
echo 12345678 | sudo ifdown eth0
发表于 : 2007-05-06 23:46
由 5451vs5451
代码: 全选
man sudo
...
-S The -S (stdin) option causes sudo to read the password from the
standard input instead of the terminal device.
...
代码: 全选
echo 12345678 | sudo -S ifdown eth0
发表于 : 2007-05-07 0:53
由 eexpress
man
学习。
没用过。
发表于 : 2007-05-12 8:41
由 Robinho
还是出错
netrestart2: 2: spawn: not found
netrestart2: 3: expect: not found
netrestart2: 4: Password:: not found
netrestart2: 4: exp_continue: not found
netrestart2: 5: Syntax error: "}" unexpected
lz要先安装expect包[/quote]