如何預先輸入? - Linux

By John
at 2009-12-27T18:33
at 2009-12-27T18:33
Table of Contents
※ 引述《feynman511 (noonee)》之銘言:
: 假設我現在做的動作裡面有些動作需要手動輸入
: 例如輸入密碼 請問要怎麼寫?
: sudo apt-get update
: sudo apt=get upgrade
: 可是在輸入第一行後系統會跟我要密碼
: 那我該怎麼寫才能讓密碼自動輸入?
====>
其實換個角度想,也許你要的是如何使用 sudo 不用輸入 passwd
如果你是這樣問的話,那我會回答
# editor /etc/sudoers
feynman ALL=PASSWD: ALL
不過你問的是 -- 如何自動輸入密碼
那我的回答會是
$ ls -l sudo_apt-get_update.exp
-rwxr-xr-x
$ cat sudo_apt-get_update.exp
#!/usr/bin/expect
spawn sudo apt-get update
expect "password"
send "YOUR_PASSWORD\r"
expect "$"
把密碼留在檔案裏真的會比較好嗎?
But The Way: 我特別去翻 sudoers man page,找出每次都會問密碼的設定
# cat /etc/sudoers
Defaults env_reset, timestamp_timeout=0
--
: 假設我現在做的動作裡面有些動作需要手動輸入
: 例如輸入密碼 請問要怎麼寫?
: sudo apt-get update
: sudo apt=get upgrade
: 可是在輸入第一行後系統會跟我要密碼
: 那我該怎麼寫才能讓密碼自動輸入?
====>
其實換個角度想,也許你要的是如何使用 sudo 不用輸入 passwd
如果你是這樣問的話,那我會回答
# editor /etc/sudoers
feynman ALL=PASSWD: ALL
不過你問的是 -- 如何自動輸入密碼
那我的回答會是
$ ls -l sudo_apt-get_update.exp
-rwxr-xr-x
$ cat sudo_apt-get_update.exp
#!/usr/bin/expect
spawn sudo apt-get update
expect "password"
send "YOUR_PASSWORD\r"
expect "$"
把密碼留在檔案裏真的會比較好嗎?
But The Way: 我特別去翻 sudoers man page,找出每次都會問密碼的設定
# cat /etc/sudoers
Defaults env_reset, timestamp_timeout=0
--
Tags:
Linux
All Comments

By Ethan
at 2009-12-29T13:44
at 2009-12-29T13:44

By Linda
at 2010-01-01T23:41
at 2010-01-01T23:41
Related Posts
救命! 中文字型不見

By Lily
at 2009-12-27T13:21
at 2009-12-27T13:21
pm-suspend進S3一睡不醒

By Sandy
at 2009-12-27T12:49
at 2009-12-27T12:49
我的 fmt 指令不正常

By Sierra Rose
at 2009-12-27T07:23
at 2009-12-27T07:23
GPLv3的一個小問題

By Hedwig
at 2009-12-27T03:28
at 2009-12-27T03:28
如何去除每行開頭有 # 的內容

By Emma
at 2009-12-27T00:47
at 2009-12-27T00:47