Ubuntu – SSH shell launched using “expect” doesn’t have full width. How to make fix it

command linegnome-terminalsshunitywindow-management

I am using expect to auto login on SSH from an Unity launcher, the command looks something like this:

gnome-terminal -t SSH1 -e "expect -c 'spawn ssh root@111.222.333.255 ; expect assword ; send \\"password123\\n\\" ; interact'"

That works fine for logging in automatically, but if I maximize the gnome-terminal window, the ssh shell contents remain smaller as if the window had the default size, like this:

screenshot

At first I thought it was because the gnome-terminal was being launched with the default size and when maximized for some reason the ssh stuff didn't resize, but then I added gnome-terminal --window --maximize to the command, and the same problem remains, the window starts maximized but the ssh shell text still is the size of the default terminal.

Also if I just open a terminal and type that command on the top, I have the same problem as if I start it from the Unity launcher.

Any ideas what could cause this and how to fix it?

Best Answer

Use following on the top of your expect script:

#trap sigwinch and pass it to the child we spawned
trap {
 set rows [stty rows]
 set cols [stty columns]
 stty rows $rows columns $cols < $spawn_out(slave,name)
} WINCH
Related Question