Where does it come from?

I am trying to get around a situation where I need to log into the server system without being able to use ssh keys. As a result, I wording "this is bad practice" -expect script:

#!/usr/bin/expect
set arg1 [lindex $argv 0]
spawn ssh $arg1 -l user "hostname; env x='() { :;}; echo vulnerable' bash -c \"echo this is a test\"; echo"
expect " password:"
send "my_supersecret_password\n"
interact

The launch works fine:

$ ./ssh.expect server
spawn ssh server -l user hostname; env x='() { :;}; echo vulnerable' bash -c "echo this is a test"; echo
user@server password:
server
this is a test

$

But I need a better formatted list when working on multiple systems, so I'm trying to reformat perl data:

$ ./ssh.expect server | perl -e '$dump = <>; $dump = <>; chomp($line1 = <>); chomp($line2 = <>); $dump = <>; print "$line1:$line2\n";'
:this is a test

The server name is printed as if it ends with the \ r character. I do not think that it should be so. Do you agree? How can I make the system not return to column 0 after printing the server name?

I can verify that both variables contain data by adding a new line to my print:

$ ./ssh.expect server | perl -e '$dump = <>; $dump = <>; chomp($line1 = <>); chomp($line2 = <>); $dump = <>; print "$line1\n:$line2\n";'
server
:this is a test

EDIT:

As commented, the following works.

./ssh.expect server | tr -d '\r' | perl -e '$dump = <>; $dump = <>; chomp($line1 = <>); chomp($line2 = <>); $dump = <>; print "$line1:$line2\n";'
server:this is a test

Should tr be redundant?

+4
2

-TTY , , ssh. TTY PTY \n \r\n (LF CRLF) . , script CRLF, CR. , expect :

$ expect -c 'spawn echo foo; interact' | od -a
0000000    s   p   a   w   n  sp   e   c   h   o  sp   f   o   o  cr  nl
0000020    f   o   o  cr  nl                                            
0000025               ^^--^^--note

TTY LF- > CRLF TTY "onlcr". script, .

Perl chomp perl ( $/), \n Unix-. , \r chomp unix . $/ perl script, chomp , . script tr, .

+2

\r ; Enter \r, ​​Linux \n; \r\n - , , ​​Linux \n . , " ", (. http://www.linusakesson.net/programming/tty/). , vi, nethack ..

, ssh ( ), ​​ \n\r\n . vi ssh, , ssh , \r EOL \r\n EOL .

0

Source: https://habr.com/ru/post/1568026/


All Articles