このページの2つのバージョン間の差分を表示します。
bash:script:19_expect [2016/04/14 02:27] – 作成 matsui | bash:script:19_expect [2016/04/14 04:55] (現在) – matsui | ||
---|---|---|---|
行 1: | 行 1: | ||
+ | ====== 19 expectで自動su ====== | ||
+ | 対話を自動化するコマンド | ||
+ | ログイン後よく実行するコマンドを自動で実行できるようしてみる。 | ||
+ | |||
+ | ===== 1.シェルを用意 ===== | ||
+ | |||
+ | <code |~/ | ||
+ | #!/bin/sh | ||
+ | PW=" | ||
+ | expect -c " | ||
+ | spawn sudo su - | ||
+ | expect matsui: | ||
+ | send -- ${PW}\n | ||
+ | interact | ||
+ | " | ||
+ | </ | ||
+ | |||
+ | ==== 実行権追加 ==== | ||
+ | |||
+ | < | ||
+ | $ chmod 755 ~/bin/su.sh | ||
+ | </ | ||
+ | |||
+ | ===== 2.bashrcに追加 ===== | ||
+ | |||
+ | <code |~/ | ||
+ | if [ -f ./bin/su.sh ]; then | ||
+ | ./ | ||
+ | fi | ||
+ | </ | ||
+ | |||
+ | |||
+ | {{tag> |