send special character “~-enter” in expect script

The name of the pictureThe name of the pictureThe name of the pictureClash 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?










share|improve this question























  • 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 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














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?










share|improve this question























  • 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 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












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?










share|improve this question















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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 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










  • @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










  • 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 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















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










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






share|improve this answer




















    Your Answer







    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "106"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    convertImagesToLinks: false,
    noModals: false,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













     

    draft saved


    draft discarded


















    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






























    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






    share|improve this answer
























      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






      share|improve this answer






















        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






        share|improve this answer












        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







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Oct 11 '17 at 20:00









        Viperdriver2000

        112




        112



























             

            draft saved


            draft discarded















































             


            draft saved


            draft discarded














            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













































































            Popular posts from this blog

            Peggy Mitchell

            Palaiologos

            The Forum (Inglewood, California)