# Automating interactive scripts

**URL:** <https://community.unix.com/t/automating-interactive-scripts/143317>\
**Category:** Shell Programming and Scripting\
**Created:** [July 12, 2002, 5:06pm UTC](https://community.unix.com/t/automating-interactive-scripts/143317 "2002-07-12T17:06:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![bookoo](https://community.unix.com/letter_avatar/bookoo/32/6_22734026db12803ebb3e059622ac3534.png) [@bookoo](https://community.unix.com/u/bookoo)\
**Post date:** [July 12, 2002, 5:06pm UTC](https://community.unix.com/t/automating-interactive-scripts/143317/1 "2002-07-12T17:06:39Z")

</div>

Hi all,  
I am trying to write a program that will automate interactive scripts that use 'pkgadd'. Easily enough I can use 'pkgask' and a response file for most of what I want to do, but unfortunately there are parts of some pkg installations that are configured to only take input from /dev/tty!! Does anyone have any ideas on how I can get around the /dev/tty problem so I can automate it?

---

<div class="post-metadata">

**Author:** ![peter.herlihy](https://community.unix.com/letter_avatar/peter.herlihy/32/6_22734026db12803ebb3e059622ac3534.png) [@peter.herlihy](https://community.unix.com/u/peter.herlihy)\
**Post date:** [July 14, 2002, 6:54pm UTC](https://community.unix.com/t/automating-interactive-scripts/143317/2 "2002-07-14T18:54:50Z")

</div>

You can automate input to terminal by using a series of echo and sleep commands.....(sleep commands are important if some of the commands take time to complete).

Here is an exerpt from a telnet script I wrote that requires terminal input....

(  
sleep 2  
echo ${FTPid}  
sleep 2  
echo ${FTPpwd}  
sleep 2  
echo ${FINDstatement}  
sleep 5  
exit  
) | telnet ${FTPserver}

The cariables are obviously all defined earlier..... so effectively my script is compelting the following commands to terminal

telnet \<server\>  
user\_id  
password  
command (i.e rm \*.log)  
exit

And there is sleeping between commands to allow the commands to execute before I type type the next. This should allow you to complete what you need.

---

<div class="post-metadata">

**Author:** ![mslightn](https://community.unix.com/letter_avatar/mslightn/32/6_22734026db12803ebb3e059622ac3534.png) [@mslightn](https://community.unix.com/u/mslightn)\
**Post date:** [July 17, 2002, 12:08pm UTC](https://community.unix.com/t/automating-interactive-scripts/143317/3 "2002-07-17T12:08:41Z")

</div>

These have always worked for me...

1) Simple version (singe answer)

echo y | pkgadd SOMEpkg

2) Complex version (one answer per line)

pkgadd SOMEpkg \<\< ANSWERS  
y  
n  
/usr/sbin  
whatever...  
ANSWERS

\*replace SOMEpkg w/ your package name  
\*\*replace y, n, /usr/sbin, whatever... w/ your answers
