LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   echo command inside expect script (https://www.linuxquestions.org/questions/linux-newbie-8/echo-command-inside-expect-script-914230/)

Soji Antony 11-18-2011 07:07 AM

echo command inside expect script
 
Hi

I am trying to use echo command inside a expect script

Code:

#/usr/bin/expect
spawn ssh root@192.168.0.1
expect "*?assword:*"
send "password\n"
expect "%"
send "echo -en "\e]0;Title\a"\n"
interact

I would like to use the echo command to set title for the shell after logging into the remote machine. But this does not works for me, possibly due to the double quotes " "" ".

Can anybody tell me how to use echo command with quotes inside a expect script.

Code:

#./1.txt
spawn ssh root@192.168.0.1
root@192.168.0.1's password:
Last login: Thu Nov 17 06:04:38 2011 from 117.196.172.66
extra characters after close-quote
    while executing
"send "echo -en "\e]0;Title\a\n"
interact

"
    (file "./1.txt" line 6)

Thanks in advance.

MensaWater 11-18-2011 08:56 AM

That seems to be doing it the hard way and insecurely since your expect script will contain your password in clear text.

Why not:
1) Set an ssh trust to the remote machine user from the one where you're running the expect script so it logs in without a password?
2) Set the .bashrc or .bashprofile for the target user to set the title whenever you login?

Soji Antony 11-23-2011 06:50 AM

Hi Mensa,

Thanks for your suggestion about using ssh keys. I just wanted to set the Title temporarily, for that session only. I have managed to set the title using the gnome-terminal option "--title=Title".

I have called the expect script from a bash script.

Code:

# cat 1.txt

#/usr/bin/expect
spawn ssh root@192.168.0.1
expect "*?assword:*"
send "password\n"
interact

Code:

# cat 2.txt

#!/bin/bash
gnome-terminal --tab --geometry 168x36+100+250 --title=Serv1 -e "bash -c "./1.txt; exec bash""



All times are GMT -5. The time now is 10:26 PM.