I have an expect script that is logging into a pfSense/BSD box over SSH, it’s called by a Perl script and passes the output back to the Perl script (a RANCID plugin).
Currently I am getting the following output;
+ spawn ssh -2 -x -l rancid my-pfsense-device.fqdn.com
+ Password:
+ Last login: Wed Dec 19 10:28:47 2012 from 89.21.224.35
+ Copyright (c) 1980, 1983, 1986, 1988, 1990, 1991, 1993, 1994
+ The Regents of the University of California. All rights reserved.
+
+
+ [0;1;33m[ [0;1;37m2.0.1-RELEASE [0;1;33m] [0;1;33m[ [0;1;37mrancid [0;1;31m@ [0;1;37mmy-pfsense-device.fqdn.com [0;1;33m] [0;1;32m/home/rancid [0;1;33m( [0;1;37m1 [0;1;33m) [0;1;36m [0;1;31m: [0;40;37m
uname -a
+ FreeBSD my-pfsense-device.fqdn.com 8.1-RELEASE-p6 FreeBSD
8.1-RELEASE-p6 #0: Mon Dec 12 18:59:41 EST 2011
root@FreeBSD_8.0_pfSense_2.0-snaps.pfsense.org:/usr/obj./usr/pfSensesrc/src/sys/pfSense_wrap.8.i386
i386
+ [0;1;33m[ [0;1;37m2.0.1-RELEASE [0;1;33m] [0;1;33m[ [0;1;37mrancid [0;1;31m@ [0;1;37mmy-pfsense-device.fqdn.com [0;1;33m] [0;1;32m/home/rancid [0;1;33m( [0;1;37m2 [0;1;33m) [0;1;36m [0;1;31m: [0;40;37m
cat /cf/conf/config.xml
+ <?xml version="1.0"?>
+ <pfsense>
The problem here is that the login prompt looks like this when logged in via SSH from my desktop;
[2.0.1-RELEASE][username@my-pfsense-device.fqdn.com]/home/username(1):
But this is in a variety of colours. As you can see in the output above, SSH is being passed all the colouring information, which then gets output to my expect script. The same line looks like this in the above output;
[0;1;33m[ [0;1;37m2.0.1-RELEASE [0;1;33m] [0;1;33m[ [0;1;37musername [0;1;31m@ [0;1;37mmy-pfsense-device.fqdn.com [0;1;33m] [0;1;32m/home/username [0;1;33m( [0;1;37m1 [0;1;33m) [0;1;36m [0;1;31m: [0;40;37m
Is there a way I can script this off? Is it a standard colour format that and be regex’ed out, or perhaps I need to change an option on my SSH client to ignore colouring info?
Whether or not a terminal can display colors is determined by the
TERMenvironment variable. It’s usually set to something likexterm,linuxorscreen(maybe with a-256colorpostfix for even more goodness). Hopefully the shell (and more importantly: the shell initialization scripts) on the other side pay attention toTERMand only try to use color if the terminal on the caller’s side actually supports colors.You can try setting that variable right before your call to
ssh. The usual value to set it to for “terminal with no interactive and no color capabilities” isdumb.