DO NOT EVER USE TELNET.
Use ssh keys instead of setting a password in the script.
You don't need to use expect to set the PWD to /tmp. You can do
this with basic scripting. Pick up a bash scripting guide and read through it. I see almost nothing in your example that requires expect. This can be done with a simple bash script.
Thank you for your reply. Please be informed that the remote node is a
VxWorks node that currently does not support ssh. Actually I need to telnet to it and issue some commands and capture the output of the commands in a file and then wait for a prescribed time interval and then redo from the start (but I need to append all of the logs in just one file). I want to automate this procedure. Please help me.