You can create an "expect" bash script if you have to respond to prompts and stuff from a shell command. You can do this right inside of applescript.
Here's an example. Suppose I wanted to log into a computer via SSH, run a couple commands, and then exit. I know at the command line I must first ssh into the IP address of the machine, then I have to wait for the machine to ask me for a password, then I must enter the password, then I wait again and so on. I can do that with an expect script inside of applescript like the below script. Note that the line:
expect \\\"password:\\\"
is where I wait for the password request by expecting "password:" command line prompt. After I receive that prompt I send the password with:
send \\\"$PASS\\r\\\"
You can see I then issue some other ssh commands and eventually exit the script. So hopefully this will give you an idea of how you can write your code. You can google for more ideas regarding "expect" scripts.
To explain the back slashes... in a bash script we would have \" in the expect command to escape a quote. Since we're in applescript we have to escape each of those things because they have a special meaning to applescript so it becomes \\" which is \ to send a backslash and \" to send a quote.
Good luck.
set shScript to "#!/bin/bash
HOST=192.168.1.xxx
USER=username
PASS=passwrd
PROMPT=#
expect -c \"
spawn ssh $USER@$HOST
expect \\\"password:\\\"
send \\\"$PASS\\r\\\"
expect \\\"$PROMPT\\\"
send \\\"cd /\\r\\\"
expect \\\"$PROMPT\\\"
send \\\"ls -al\\r\\\"
expect \\\"$PROMPT\\\"
send \\\"exit\\r\\\"
\"
"
do shell script "sh -c " & quoted form of shScript