未找到简单命令 bash (#!/usr/bin/expect)

Simple commands not found bash (#!/usr/bin/expect)

我最近开始使用 bash 通过 chntpw 自动化 windows 救援磁盘。我正在尝试将程序设置为使用 expect 命令来收听某些 chntpw 对话问题并在没有任何用户输入的情况下输入正确的答案。出于某种原因,在将 bash 脚本设置为使用 #!/usr/bin/expect 而不是 #!/bin/bash 之后,许多标准终端命令不再被理解。

我是 运行 脚本,在终端中输入:

user@kali:~/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 命令一起使用。我可能把这一切都弄错了,所以请纠正我,因为我已经对此进行了大约三天的故障排除并且还没有走得太远:(

当您指定应 运行 您的脚本的应用程序时,您只能使用该应用程序能够理解的脚本语言。

显然,Expect 不是 bash,不理解 bash 命令。

我建议您将这两个脚本分开。为 !#/bin/bash 写第一部分,为 Expect 写第二部分。让第一个脚本调用第二个脚本并将其重定向到 chntpw。

expect 使用 而不是 bash。因此,当您使用 #!/usr/bin/expect.

时,您可以在 TCL 中编写脚本

例如echo "BREEZEE 1.0"应该写成:

puts "BREEZEE 1.0"

你应该使用 exp_send 而不是 send

来自expect manual

exp_send is an alias for send. If you are using Expectk or some other variant of Expect in the Tk environment, send is defined by Tk for an entirely different purpose. exp_send is provided for compatibility between environments. Similar aliases are provided for other Expect's other send commands.