I have a requirement where in i need to read the file from while loop as shown in the code below
while read line
do
command $line
done < list.txt
But after every command it asks if i want to really go ahead with the execution since there are several other lines in the list.txt i cannot answer manually, can i automate the same using Unix's Expect Utility, i tried using the command but no luck.
#!/usr/bin/expect
#use correct prompt
while read line
do
eval spawn command $line
set prompt ":|#|\\\$"
interact -o -nobuffer -re $prompt return
send "y\r"
done < list.txt
That depends. Do the commands read from stdin? Are those commands' user prompts always in the same order, and always of the same length? If none of these, it might become difficult, unless a command offers e.g. an option like "always assume 'yes' as an answer".
Providing a decent sample situation including commands and possible answers / interactive input might have helped here.
For simple cases, you could provide the answers on a different file descriptor. Try
while read line
do <&3 command $line
done <cmdfile 3<answfile
or, in case all commands can be satisfied with identical answers, e.g. (needs a recent shell like bash for the "here string")
while read line
do command $line <<< $'y\ny\ny\n'
done <cmdfile