私は最近、chntpw
でWindowsレスキューディスクを自動化するためにbashを使い始めました。私は、特定のchntpw
ダイアログの質問を聞いて、ユーザーの入力なしで正しい答えを入力するためのexpect
コマンドを使用するプログラムを設定しようとしています。何らかの理由で、#!/bin/bash
ではなく#!/usr/bin/expect
を使用するようにbashスクリプトを設定した後、多くの標準端末コマンドは理解されなくなります。単純なコマンドが見つかりませんbash(#!/ usr/bin/expect)
私は、端末にこれを入力して、スクリプトを実行している:
[email protected]:~/Desktop/projects/breezee$ bash breezee1.sh
次のように、端末出力は次のとおりです。ここで
BREEZEE 1.0
Welcome to BREEZEE
breezee1.sh: line 9: fdisk: command not found
[Select] /dev/:
は私のコードです:では
#!/usr/bin/expect
clear
echo "BREEZEE 1.0"
echo "Welcome to BREEZEE"
fdisk -l
#list partitions
echo -n "[Select] /dev/:"
#ask user to choose primary windows partition
read sda
clear
echo /dev/$sda selected
umount /dev/$sda
sudo ntfsfix /dev/$sda
sudo mount -t ntfs-3g -o remove_hiberfile /dev/$sda /mnt/
cd /mnt/Windows/System32/config
clear
chntpw -l SAM #list accounts on windows partition
chntpw -u Administrator SAM
#now supply chntpw with values to run the password clear (this answers the prompts)
expect '> '
send '1\r'
expect '> '
send '2\r'
expect '> '
send '3\r'
expect ': '
send 'y\r'
expect '> '
send 'q\r'
expect ': '
send 'y\r'
clear
echo "Operation Successfull!"
chntpw -l SAM #list accounts on windows partition
つまり、私は標準のbash/terminalコマンドをexpect
コマンドとともに使用しようとしています。私はおそらくこれについてすべて間違っていると思いますので、私は約3日間この問題を解決していて、遠くまでは得られませんでした:(
これは実際にはかなり意味があります。私はちょうど '##/ usr/bin/expect'が期待されるサポートを含む別のbashインタプリタであると仮定しました。明らかに私は間違っていて、それが私の混乱の原因です。どうもありがとう! – pattyd
私はインタプリタを '!#/ bin/bash'に変更しましたが、まだ' fdisk:command not found'の問題が出ていますか? **アップデート:** 'sudo'を追加すると修正されました。 – pattyd
@pattyd:また、スクリプトをたとえば'bash breezee1.sh'は、shebang('#! ')の行に関係なく、bashスクリプトとして実行します。一般に、スクリプトを実行可能にする必要があります(例:'chmod + x breezee1.sh')、'。/ breezee1.sh'のようなもので実行してください。 –