-1

I would like to write a automated script to open telnet session and run some commands. The thing is, that this will be some kind of "logging", so i have to open pipe, and send some commands, and store outputs. I know, how to do this in a while loop like:

(while true
do
echo ${user}
    sleep 1
echo ${pass}
    sleep 1
echo ${something}
    .
    .
done)|telnet ${IP}

The problem here is that the telnet pipe is opened/closed in every loop and i want to achieve to open it at the beginning, and then send commands in a loop until some conditions are true.

NOTE: i am limited with commands as i am working with emb.system (such as spawn, expect, etc...)

Thanks for your help ! :)

BR.

  • 2
    Possible duplicate of [automating telnet session using bash scripts](http://stackoverflow.com/questions/7013137/automating-telnet-session-using-bash-scripts) – coda Nov 19 '15 at 09:07
  • Sry. Not at all. My case is different. I need to open it once, and keep sending commands, not to open session everytime want to send something. Thanks – user2855621 Nov 19 '15 at 14:39

2 Answers2

0

Does this work for you?

(echo ${user}
    sleep 1
 echo ${pass}
    sleep 1
 while true; do
    echo ${something} | tee -a /tmp/logfile.txt
    .
    .
 done
 echo "exit") | telnet ${IP} | tee -a /tmp/logfile.txt
coda
  • 622
  • 1
  • 7
  • 14
-1

you can use sshpass soft. http://sourceforge.net/projects/sshpass/

tar -zxvf sshpass-1.05.tar.gz
cd sshpass-1.05
./configure
make && make install

.............

Knight-Zhou
  • 49
  • 1
  • 7
  • Hi Knight. Unfortunately, no make/make install command on my system. I dont even have gcc or cc. And due limited memory i dont want to install hundred dependecies. Thanks anyway – user2855621 Nov 19 '15 at 10:12