Script for telnet and run one command kill it and run another command using while loop

 ( sleep 3
 echo ${LOGIN}
 sleep 2
 echo ${PSWD}
 sleep 2
 while read line
 do
 echo "$line"
 PID=$?
  sleep 2
  kill -9 $PID
done < temp
 sleep 5
 echo "exit" ) | telnet ${HOST}

while is executing only command and exits.

Let's look at just three commands in this script:

 PID=$?
  sleep 2
  kill -9 $PID

The first command in this list sets the variable PID to the exit status of the previous command ( echo "$line" ) which is almost always going to be 0. The second command causes the script to wait for about 2 seconds. Then the third command (after parameter expansion) is:

kill -9 0

This is a request to terminate all processes in the current process group. On most systems, killing all processes in the current process group includes killing the shell that is running this script.

What process were you trying to kill?

I just want kill the running command and execute the next command.

what do you mean by running command here??? :confused: :confused:

Run the command for certain time and kill it and execute next command from the
file temp

Can you show the contents of the file "temp"???

How long are you planning to run a command from the above file??