Training, Open Source computer languages
PerlPHPPythonMySQLApache / TomcatTclRubyJavaC and C++LinuxCSS 
Search for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
 
For 2023 (and 2024 ...) - we are now fully retired from IT training.
We have made many, many friends over 25 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Linux and Solaris/SunOS too. Our training notes are now very much out of date, but due to upward compatability most of our examples remain operational and even relevant ad you are welcome to make us if them "as seen" and at your own risk.

Lisa and I (Graham) now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We are far from inactive - rather, enjoying the times that we are retired but still healthy enough in mind and body to be active!

I am also active in many other area and still look after a lot of web sites - you can find an index ((here))
Output is not clear

Posted by sanpraka (sanpraka), 1 April 2006
hi experts,

i am new to expect.when i logged into the remote device and executed the command in ls -l.the output is captured in a file but there are some special characters in between the lines.can u please help me out in eliminating these characters from this ouput.

This is my script:
#!/usr/bin/expect -f
set filename "/tmp/logfile.txt"
set fileid [open $filename "w"]
set force_conservative 1
set match_max 100000
exp_internal 1
set timeout -1
set TASK "$argv\r"
set USER  [lindex $TASK 1]
set SERVER [lindex $TASK 0]
set PASSWD [lindex $TASK 2]
spawn ssh $SERVER -l $USER
expect "root@127.0.0.1's password:"
send "$PASSWD\r"
sleep 5
expect "#"
send "ls -l\r"
expect "#"
set tempvar $expect_out(buffer)
puts $fileid $tempvar;
send "exit\r"
close $fileid

Here is the Sample output:

ls -l^M
^[[00mtotal 120^M
-rw-------  1 root root   798 Mar 17 17:05 ^[[00manaconda-ks.cfg^[[00m^M
-rw-r--r--  1 root root    37 Mar 17 17:12 ^[[00mbirthdate^[[00m^M
drwxr-xr-x  2 root root  4096 Mar 20 16:36 ^[[00;34mDesktop^[[00m^M
-rw-r--r--  1 root root 71590 Mar 17 17:05 ^[[00minstall.log^[[00m^M
-rw-r--r--  1 root root  9737 Mar 17 17:05 ^[[00minstall.log.syslog^[[00m^M^[[m^[]0;root@localhost:~^G[root@localhost ~]#

Please help me out by gving a fast reply.i will be very much thankful.

Regards,
Sanjeev

Posted by admin (Graham Ellis), 1 April 2006
The extra characters are a terminal control sequence that's sent out by your remote host to provide formatting.  If you set the terminal type for your session to DUMB, you should be able to prevent the problem. Do so via the login's .bashrc file or via an export command that's a part of your sequence if you're using the bash shell ... the commands / files vary a bit for other shells.

Sanjeev, welcome to Opentalk. You write "Please help me out by gving a fast reply" I have a target of making technical comment (at least) on 90% of questions within 24 hours, and I always get back quicker if I can. I prioritise questions raised by people who give (i.e. help answering questions) as well as take, and questions raised by people I have trained (for whom the service was created in the first place). If you are not in one of these groups and require a faster support service, you can buy it; have a look here for example - "Entry P4" lists a contract at $2500 per annum with 24 hour emergency support available on an additional time and materials basis. However, that is not something I can provide.



This page is a thread posted to the opentalk forum at www.opentalk.org.uk and archived here for reference. To jump to the archive index please follow this link.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2024: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho