send special character â~-enterâ in expect script

Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
i need some help please.
i write a little testing script for my daily work.
in that script i will connect to a server console.
here is my expect part:
export TMPEXPECT=$(mktemp /home/user/tmp/expect.XXXXXX)
chmod 700 $TMPEXPECT
echo "Verbinde auf console..."
cat <<< '#!/usr/bin/expect -f
spawn ssh root:ttyS'"$port"'@'"$console"'
expect "*gnore*" send "irr"
expect "n" send "r"
expect "n" send "r"
sleep 2
expect "n" send "r"
expect "n" send "~.r"
expect eof
' > $TMPEXPECT
$TMPEXPECT
the output looks like this:
spawn ssh root:ttyS33@console
A non-empty Data Buffering File was found. Choose which action
should be performed ( (I)gnore, (D)isplay, (E)rase or (S)how and erase ) : I
Welcome to Special Dedicated-Server Linux (x86_64) Version 5.5.1 - Kernel 4.4.77-9.1.x86_64 (ttyS0).
server login:
Welcome to Special Dedicated-Server Linux (x86_64) Version 5.5.1 - Kernel 4.4.77-9.1.x86_64 (ttyS0).
server login:
Welcome to Special Dedicated-Server Linux (x86_64) Version 5.5.1 - Kernel 4.4.77-9.1.x86_64 (ttyS0).
server login: ~.
you can see the connection works.
but i have a problems.
after pressing 3 times enter i want to close the connection.
if i want do this normal i will press "alt gr + . enter" an the connection is close.
server login: Connection to console closed.
but this doesn't work in expect as you can see above :(
do you have any ideas?
linux shell-script expect
 |Â
show 2 more comments
up vote
0
down vote
favorite
i need some help please.
i write a little testing script for my daily work.
in that script i will connect to a server console.
here is my expect part:
export TMPEXPECT=$(mktemp /home/user/tmp/expect.XXXXXX)
chmod 700 $TMPEXPECT
echo "Verbinde auf console..."
cat <<< '#!/usr/bin/expect -f
spawn ssh root:ttyS'"$port"'@'"$console"'
expect "*gnore*" send "irr"
expect "n" send "r"
expect "n" send "r"
sleep 2
expect "n" send "r"
expect "n" send "~.r"
expect eof
' > $TMPEXPECT
$TMPEXPECT
the output looks like this:
spawn ssh root:ttyS33@console
A non-empty Data Buffering File was found. Choose which action
should be performed ( (I)gnore, (D)isplay, (E)rase or (S)how and erase ) : I
Welcome to Special Dedicated-Server Linux (x86_64) Version 5.5.1 - Kernel 4.4.77-9.1.x86_64 (ttyS0).
server login:
Welcome to Special Dedicated-Server Linux (x86_64) Version 5.5.1 - Kernel 4.4.77-9.1.x86_64 (ttyS0).
server login:
Welcome to Special Dedicated-Server Linux (x86_64) Version 5.5.1 - Kernel 4.4.77-9.1.x86_64 (ttyS0).
server login: ~.
you can see the connection works.
but i have a problems.
after pressing 3 times enter i want to close the connection.
if i want do this normal i will press "alt gr + . enter" an the connection is close.
server login: Connection to console closed.
but this doesn't work in expect as you can see above :(
do you have any ideas?
linux shell-script expect
Are you trying to send the~-to SSH or to the console SSH is connect to? Because~sequences are special to SSH, and SSH will grab those by default.
â thrig
Oct 10 '17 at 19:18
trying to send the~-to the SSH connection to the console in the script. i hope you understand what i mean
â Viperdriver2000
Oct 10 '17 at 20:00
What happens if you usespawn ssh -e none root:ttyS'"$port"'@'"$console"'?
â thrig
Oct 10 '17 at 20:25
You could also trysend "~B"to send a break to the remote, or if you dont use-e noneas suggested by thrig then double the tilde character~if you want it to be received by the remote instead of acted on by ssh, as insend "~~B". Also, you might ensure your locale is C, in case the tilde you see is not an ascii tilde but some unicode lookalike.export LC_ALL=C. You can replace the tilde by the hex equivalentx7e, eg send "x7eB"`.
â meuh
Oct 10 '17 at 20:58
@thrig doesn't change anything
â Viperdriver2000
Oct 10 '17 at 23:39
 |Â
show 2 more comments
up vote
0
down vote
favorite
up vote
0
down vote
favorite
i need some help please.
i write a little testing script for my daily work.
in that script i will connect to a server console.
here is my expect part:
export TMPEXPECT=$(mktemp /home/user/tmp/expect.XXXXXX)
chmod 700 $TMPEXPECT
echo "Verbinde auf console..."
cat <<< '#!/usr/bin/expect -f
spawn ssh root:ttyS'"$port"'@'"$console"'
expect "*gnore*" send "irr"
expect "n" send "r"
expect "n" send "r"
sleep 2
expect "n" send "r"
expect "n" send "~.r"
expect eof
' > $TMPEXPECT
$TMPEXPECT
the output looks like this:
spawn ssh root:ttyS33@console
A non-empty Data Buffering File was found. Choose which action
should be performed ( (I)gnore, (D)isplay, (E)rase or (S)how and erase ) : I
Welcome to Special Dedicated-Server Linux (x86_64) Version 5.5.1 - Kernel 4.4.77-9.1.x86_64 (ttyS0).
server login:
Welcome to Special Dedicated-Server Linux (x86_64) Version 5.5.1 - Kernel 4.4.77-9.1.x86_64 (ttyS0).
server login:
Welcome to Special Dedicated-Server Linux (x86_64) Version 5.5.1 - Kernel 4.4.77-9.1.x86_64 (ttyS0).
server login: ~.
you can see the connection works.
but i have a problems.
after pressing 3 times enter i want to close the connection.
if i want do this normal i will press "alt gr + . enter" an the connection is close.
server login: Connection to console closed.
but this doesn't work in expect as you can see above :(
do you have any ideas?
linux shell-script expect
i need some help please.
i write a little testing script for my daily work.
in that script i will connect to a server console.
here is my expect part:
export TMPEXPECT=$(mktemp /home/user/tmp/expect.XXXXXX)
chmod 700 $TMPEXPECT
echo "Verbinde auf console..."
cat <<< '#!/usr/bin/expect -f
spawn ssh root:ttyS'"$port"'@'"$console"'
expect "*gnore*" send "irr"
expect "n" send "r"
expect "n" send "r"
sleep 2
expect "n" send "r"
expect "n" send "~.r"
expect eof
' > $TMPEXPECT
$TMPEXPECT
the output looks like this:
spawn ssh root:ttyS33@console
A non-empty Data Buffering File was found. Choose which action
should be performed ( (I)gnore, (D)isplay, (E)rase or (S)how and erase ) : I
Welcome to Special Dedicated-Server Linux (x86_64) Version 5.5.1 - Kernel 4.4.77-9.1.x86_64 (ttyS0).
server login:
Welcome to Special Dedicated-Server Linux (x86_64) Version 5.5.1 - Kernel 4.4.77-9.1.x86_64 (ttyS0).
server login:
Welcome to Special Dedicated-Server Linux (x86_64) Version 5.5.1 - Kernel 4.4.77-9.1.x86_64 (ttyS0).
server login: ~.
you can see the connection works.
but i have a problems.
after pressing 3 times enter i want to close the connection.
if i want do this normal i will press "alt gr + . enter" an the connection is close.
server login: Connection to console closed.
but this doesn't work in expect as you can see above :(
do you have any ideas?
linux shell-script expect
linux shell-script expect
edited Oct 10 '17 at 23:07
asked Oct 10 '17 at 18:27
Viperdriver2000
112
112
Are you trying to send the~-to SSH or to the console SSH is connect to? Because~sequences are special to SSH, and SSH will grab those by default.
â thrig
Oct 10 '17 at 19:18
trying to send the~-to the SSH connection to the console in the script. i hope you understand what i mean
â Viperdriver2000
Oct 10 '17 at 20:00
What happens if you usespawn ssh -e none root:ttyS'"$port"'@'"$console"'?
â thrig
Oct 10 '17 at 20:25
You could also trysend "~B"to send a break to the remote, or if you dont use-e noneas suggested by thrig then double the tilde character~if you want it to be received by the remote instead of acted on by ssh, as insend "~~B". Also, you might ensure your locale is C, in case the tilde you see is not an ascii tilde but some unicode lookalike.export LC_ALL=C. You can replace the tilde by the hex equivalentx7e, eg send "x7eB"`.
â meuh
Oct 10 '17 at 20:58
@thrig doesn't change anything
â Viperdriver2000
Oct 10 '17 at 23:39
 |Â
show 2 more comments
Are you trying to send the~-to SSH or to the console SSH is connect to? Because~sequences are special to SSH, and SSH will grab those by default.
â thrig
Oct 10 '17 at 19:18
trying to send the~-to the SSH connection to the console in the script. i hope you understand what i mean
â Viperdriver2000
Oct 10 '17 at 20:00
What happens if you usespawn ssh -e none root:ttyS'"$port"'@'"$console"'?
â thrig
Oct 10 '17 at 20:25
You could also trysend "~B"to send a break to the remote, or if you dont use-e noneas suggested by thrig then double the tilde character~if you want it to be received by the remote instead of acted on by ssh, as insend "~~B". Also, you might ensure your locale is C, in case the tilde you see is not an ascii tilde but some unicode lookalike.export LC_ALL=C. You can replace the tilde by the hex equivalentx7e, eg send "x7eB"`.
â meuh
Oct 10 '17 at 20:58
@thrig doesn't change anything
â Viperdriver2000
Oct 10 '17 at 23:39
Are you trying to send the
~- to SSH or to the console SSH is connect to? Because ~ sequences are special to SSH, and SSH will grab those by default.â thrig
Oct 10 '17 at 19:18
Are you trying to send the
~- to SSH or to the console SSH is connect to? Because ~ sequences are special to SSH, and SSH will grab those by default.â thrig
Oct 10 '17 at 19:18
trying to send the
~- to the SSH connection to the console in the script. i hope you understand what i meanâ Viperdriver2000
Oct 10 '17 at 20:00
trying to send the
~- to the SSH connection to the console in the script. i hope you understand what i meanâ Viperdriver2000
Oct 10 '17 at 20:00
What happens if you use
spawn ssh -e none root:ttyS'"$port"'@'"$console"' ?â thrig
Oct 10 '17 at 20:25
What happens if you use
spawn ssh -e none root:ttyS'"$port"'@'"$console"' ?â thrig
Oct 10 '17 at 20:25
You could also try
send "~B" to send a break to the remote, or if you dont use -e none as suggested by thrig then double the tilde character ~ if you want it to be received by the remote instead of acted on by ssh, as in send "~~B". Also, you might ensure your locale is C, in case the tilde you see is not an ascii tilde but some unicode lookalike. export LC_ALL=C. You can replace the tilde by the hex equivalent x7e, eg send "x7eB"`.â meuh
Oct 10 '17 at 20:58
You could also try
send "~B" to send a break to the remote, or if you dont use -e none as suggested by thrig then double the tilde character ~ if you want it to be received by the remote instead of acted on by ssh, as in send "~~B". Also, you might ensure your locale is C, in case the tilde you see is not an ascii tilde but some unicode lookalike. export LC_ALL=C. You can replace the tilde by the hex equivalent x7e, eg send "x7eB"`.â meuh
Oct 10 '17 at 20:58
@thrig doesn't change anything
â Viperdriver2000
Oct 10 '17 at 23:39
@thrig doesn't change anything
â Viperdriver2000
Oct 10 '17 at 23:39
 |Â
show 2 more comments
1 Answer
1
active
oldest
votes
up vote
1
down vote
okay i answer my self because it is better to read.
i tested a little...i have delete the "expect eof" it seem to be better.
cat <<< '#!/usr/bin/expect -f
spawn ssh -e none root:ttyS'"$port"'@'"$console"'
expect
"*regular*" send "1r"
"default" send "ir"
expect
"*gnore*" send "ir"
expect
"*n*" send "r"
sleep 5
expect
"*n*" send "r"
sleep 2
expect
"*n*" send "r"
sleep 2
' > $TMPEXPECT
$TMPEXPECT
echo ""
echo ""
echo "this is a test after the expect and expect eof part"
with this code i get that output:
spawn ssh -e none root:ttyS33@console
A non-empty Data Buffering File was found. Choose which action
should be performed ( (I)gnore, (D)isplay, (E)rase or (S)how and erase ) : I
Welcome to Special Dedicated-Server Linux (x86_64) Version 5.6.0 - Kernel 4.4.89-9.1.x86_64 (ttyS0).
server login:
Welcome to Special Dedicated-Server Linux (x86_64) Version 5.6.0 - Kernel 4.4.89-9.1.x86_64 (ttyS0).
server login:
this is a test after the expect and expect eof part
seems like the connection is closed correctly. i think so.
i have test a normal connect.
and i don't get a message like this:
*
* * * ttyS33 is being used by (root) !!!
*
1 - Initiate a regular session
2 - Initiate a sniff session
3 - Send messages to another user
4 - Kill session(s)
5 - Quit
Enter your option :
this is what i get if a connection is not close correctly.
so i think this case is closed.
thanks for your help
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
okay i answer my self because it is better to read.
i tested a little...i have delete the "expect eof" it seem to be better.
cat <<< '#!/usr/bin/expect -f
spawn ssh -e none root:ttyS'"$port"'@'"$console"'
expect
"*regular*" send "1r"
"default" send "ir"
expect
"*gnore*" send "ir"
expect
"*n*" send "r"
sleep 5
expect
"*n*" send "r"
sleep 2
expect
"*n*" send "r"
sleep 2
' > $TMPEXPECT
$TMPEXPECT
echo ""
echo ""
echo "this is a test after the expect and expect eof part"
with this code i get that output:
spawn ssh -e none root:ttyS33@console
A non-empty Data Buffering File was found. Choose which action
should be performed ( (I)gnore, (D)isplay, (E)rase or (S)how and erase ) : I
Welcome to Special Dedicated-Server Linux (x86_64) Version 5.6.0 - Kernel 4.4.89-9.1.x86_64 (ttyS0).
server login:
Welcome to Special Dedicated-Server Linux (x86_64) Version 5.6.0 - Kernel 4.4.89-9.1.x86_64 (ttyS0).
server login:
this is a test after the expect and expect eof part
seems like the connection is closed correctly. i think so.
i have test a normal connect.
and i don't get a message like this:
*
* * * ttyS33 is being used by (root) !!!
*
1 - Initiate a regular session
2 - Initiate a sniff session
3 - Send messages to another user
4 - Kill session(s)
5 - Quit
Enter your option :
this is what i get if a connection is not close correctly.
so i think this case is closed.
thanks for your help
add a comment |Â
up vote
1
down vote
okay i answer my self because it is better to read.
i tested a little...i have delete the "expect eof" it seem to be better.
cat <<< '#!/usr/bin/expect -f
spawn ssh -e none root:ttyS'"$port"'@'"$console"'
expect
"*regular*" send "1r"
"default" send "ir"
expect
"*gnore*" send "ir"
expect
"*n*" send "r"
sleep 5
expect
"*n*" send "r"
sleep 2
expect
"*n*" send "r"
sleep 2
' > $TMPEXPECT
$TMPEXPECT
echo ""
echo ""
echo "this is a test after the expect and expect eof part"
with this code i get that output:
spawn ssh -e none root:ttyS33@console
A non-empty Data Buffering File was found. Choose which action
should be performed ( (I)gnore, (D)isplay, (E)rase or (S)how and erase ) : I
Welcome to Special Dedicated-Server Linux (x86_64) Version 5.6.0 - Kernel 4.4.89-9.1.x86_64 (ttyS0).
server login:
Welcome to Special Dedicated-Server Linux (x86_64) Version 5.6.0 - Kernel 4.4.89-9.1.x86_64 (ttyS0).
server login:
this is a test after the expect and expect eof part
seems like the connection is closed correctly. i think so.
i have test a normal connect.
and i don't get a message like this:
*
* * * ttyS33 is being used by (root) !!!
*
1 - Initiate a regular session
2 - Initiate a sniff session
3 - Send messages to another user
4 - Kill session(s)
5 - Quit
Enter your option :
this is what i get if a connection is not close correctly.
so i think this case is closed.
thanks for your help
add a comment |Â
up vote
1
down vote
up vote
1
down vote
okay i answer my self because it is better to read.
i tested a little...i have delete the "expect eof" it seem to be better.
cat <<< '#!/usr/bin/expect -f
spawn ssh -e none root:ttyS'"$port"'@'"$console"'
expect
"*regular*" send "1r"
"default" send "ir"
expect
"*gnore*" send "ir"
expect
"*n*" send "r"
sleep 5
expect
"*n*" send "r"
sleep 2
expect
"*n*" send "r"
sleep 2
' > $TMPEXPECT
$TMPEXPECT
echo ""
echo ""
echo "this is a test after the expect and expect eof part"
with this code i get that output:
spawn ssh -e none root:ttyS33@console
A non-empty Data Buffering File was found. Choose which action
should be performed ( (I)gnore, (D)isplay, (E)rase or (S)how and erase ) : I
Welcome to Special Dedicated-Server Linux (x86_64) Version 5.6.0 - Kernel 4.4.89-9.1.x86_64 (ttyS0).
server login:
Welcome to Special Dedicated-Server Linux (x86_64) Version 5.6.0 - Kernel 4.4.89-9.1.x86_64 (ttyS0).
server login:
this is a test after the expect and expect eof part
seems like the connection is closed correctly. i think so.
i have test a normal connect.
and i don't get a message like this:
*
* * * ttyS33 is being used by (root) !!!
*
1 - Initiate a regular session
2 - Initiate a sniff session
3 - Send messages to another user
4 - Kill session(s)
5 - Quit
Enter your option :
this is what i get if a connection is not close correctly.
so i think this case is closed.
thanks for your help
okay i answer my self because it is better to read.
i tested a little...i have delete the "expect eof" it seem to be better.
cat <<< '#!/usr/bin/expect -f
spawn ssh -e none root:ttyS'"$port"'@'"$console"'
expect
"*regular*" send "1r"
"default" send "ir"
expect
"*gnore*" send "ir"
expect
"*n*" send "r"
sleep 5
expect
"*n*" send "r"
sleep 2
expect
"*n*" send "r"
sleep 2
' > $TMPEXPECT
$TMPEXPECT
echo ""
echo ""
echo "this is a test after the expect and expect eof part"
with this code i get that output:
spawn ssh -e none root:ttyS33@console
A non-empty Data Buffering File was found. Choose which action
should be performed ( (I)gnore, (D)isplay, (E)rase or (S)how and erase ) : I
Welcome to Special Dedicated-Server Linux (x86_64) Version 5.6.0 - Kernel 4.4.89-9.1.x86_64 (ttyS0).
server login:
Welcome to Special Dedicated-Server Linux (x86_64) Version 5.6.0 - Kernel 4.4.89-9.1.x86_64 (ttyS0).
server login:
this is a test after the expect and expect eof part
seems like the connection is closed correctly. i think so.
i have test a normal connect.
and i don't get a message like this:
*
* * * ttyS33 is being used by (root) !!!
*
1 - Initiate a regular session
2 - Initiate a sniff session
3 - Send messages to another user
4 - Kill session(s)
5 - Quit
Enter your option :
this is what i get if a connection is not close correctly.
so i think this case is closed.
thanks for your help
answered Oct 11 '17 at 20:00
Viperdriver2000
112
112
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f397281%2fsend-special-character-enter-in-expect-script%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Are you trying to send the
~-to SSH or to the console SSH is connect to? Because~sequences are special to SSH, and SSH will grab those by default.â thrig
Oct 10 '17 at 19:18
trying to send the
~-to the SSH connection to the console in the script. i hope you understand what i meanâ Viperdriver2000
Oct 10 '17 at 20:00
What happens if you use
spawn ssh -e none root:ttyS'"$port"'@'"$console"'?â thrig
Oct 10 '17 at 20:25
You could also try
send "~B"to send a break to the remote, or if you dont use-e noneas suggested by thrig then double the tilde character~if you want it to be received by the remote instead of acted on by ssh, as insend "~~B". Also, you might ensure your locale is C, in case the tilde you see is not an ascii tilde but some unicode lookalike.export LC_ALL=C. You can replace the tilde by the hex equivalentx7e, eg send "x7eB"`.â meuh
Oct 10 '17 at 20:58
@thrig doesn't change anything
â Viperdriver2000
Oct 10 '17 at 23:39