pattyd pattyd - 2 months ago 14
Linux Question

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

I've recently started using bash to automate a windows rescue disk with

chntpw
. I'm trying to set up the program to use the
expect
command to listen for certain
chntpw
dialog questions and input the right answers without any user input. For some reason after setting up the bash script to use
#!/usr/bin/expect
rather than
#!/bin/bash
then many standard terminal commands are no longer understood.

I'm running the script by typing this into terminal:

user@kali:~/Desktop/projects/breezee$ bash breezee1.sh


The terminal output is as follows:

BREEZEE 1.0
Welcome to BREEZEE
breezee1.sh: line 9: fdisk: command not found
[Select] /dev/:


Here is my code:

#!/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


In short, I'm trying to use standard bash/terminal commands alongside the
expect
commands. I'm probably going about this all wrong, so please correct me as I've been troubleshooting this for about three days and haven't gotten far :(

Answer

When you specify the application that should run your script, you can only use the scripting language that application will understand.

Clearly, Expect is not bash, and does not understand bash commands.

i suggest you separate those two scripts. Write the first part for !#/bin/bash, the second for Expect. Make the first script invoke the second script and redirect it to chntpw.