LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-18-2011, 08:07 AM   #1
Soji Antony
Member
 
Registered: Jul 2010
Posts: 54

Rep: Reputation: 1
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.

Last edited by Soji Antony; 11-18-2011 at 08:08 AM.
 
Old 11-18-2011, 09:56 AM   #2
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,043
Blog Entries: 14

Rep: Reputation: 1212Reputation: 1212Reputation: 1212Reputation: 1212Reputation: 1212Reputation: 1212Reputation: 1212Reputation: 1212Reputation: 1212
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?
 
1 members found this post helpful.
Old 11-23-2011, 07:50 AM   #3
Soji Antony
Member
 
Registered: Jul 2010
Posts: 54

Original Poster
Rep: Reputation: 1
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""
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Expect script, scp and find command unihiekka Programming 1 10-17-2008 04:11 PM
exec the expect command in a shell script wanghao Linux - Networking 6 11-24-2007 12:06 AM
Disable Echo Mode in Expect Script gjagadish Programming 2 04-25-2007 04:28 PM
Bash Script, no new line for echo command jorisb Linux - General 5 11-05-2005 01:08 AM
CGI script problem: Send/Expect command echo on webpage rajatgarg Programming 2 07-11-2004 05:38 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:40 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration