Sending shell script command keystrokes to a remote shell












0















Is it possible to make the script run when it shifts from normal mode to the interactive mode.



#/bash/bin  
sudo gatttool -b 80:EA:CA:00:00:03 -I
# All these commands are typed in interactive mode
connect
while [ 1 ]; do
char_read_hnd 0x0030 > a.txt
done
exit 1









share|improve this question





























    0















    Is it possible to make the script run when it shifts from normal mode to the interactive mode.



    #/bash/bin  
    sudo gatttool -b 80:EA:CA:00:00:03 -I
    # All these commands are typed in interactive mode
    connect
    while [ 1 ]; do
    char_read_hnd 0x0030 > a.txt
    done
    exit 1









    share|improve this question



























      0












      0








      0








      Is it possible to make the script run when it shifts from normal mode to the interactive mode.



      #/bash/bin  
      sudo gatttool -b 80:EA:CA:00:00:03 -I
      # All these commands are typed in interactive mode
      connect
      while [ 1 ]; do
      char_read_hnd 0x0030 > a.txt
      done
      exit 1









      share|improve this question
















      Is it possible to make the script run when it shifts from normal mode to the interactive mode.



      #/bash/bin  
      sudo gatttool -b 80:EA:CA:00:00:03 -I
      # All these commands are typed in interactive mode
      connect
      while [ 1 ]; do
      char_read_hnd 0x0030 > a.txt
      done
      exit 1






      linux shell-script expect






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Oct 28 '15 at 13:41









      Arthur2e5

      922519




      922519










      asked Oct 28 '15 at 9:09









      Ank KhandelwalAnk Khandelwal

      1




      1






















          3 Answers
          3






          active

          oldest

          votes


















          1














          are you looking for



           sudo gatttool -b 80:EA:CA:00:00:03 -I  <<EOF
          # All these commands are entered in interactive mode
          connect
          while [ 1 ]; do
          char_read_hnd 0x0030 > a.txt
          done
          exit 1
          EOF


          the syntax cmd <<EOF (lines ) EOF (on a line of its onw) is called a here doc.






          share|improve this answer
























          • more complicated tasks involving e.g. waiting for a prompt or a particular response from the remote host should be done with the expect scripting language, or perl's Expect.pm module or python's pexpect. Other languages also have similar expect-like libraries.

            – cas
            Oct 28 '15 at 9:34













          • @cas Yes <<EOF does the trick, but I have to wait for a particular message from remote host to execute the other commands. As I am new to scripting language, I will have to look into other scripting language.

            – Ank Khandelwal
            Oct 28 '15 at 9:53





















          1














          If you need just write or read you can use one string command like this:



          gatttool -i hci0 -b device=MAC --char-write-req -a handle=0x0001 -n value=0x0001

          gatttool -i hci0 -b device=MAC --char-read -a handle=0x0001


          I found it here: http://www.mathieupassenaud.fr/control-your-plugs-with-bluetooth-and-bash-scripts/.



          To find more options see gatttool --help-all.






          share|improve this answer































            0














            You can use expect for shell or pexpect for python.



            I think you're searching for something like this:
            https://www.torsten-traenkner.de/wissen/smarthome/heizung.php






            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',
              autoActivateHeartbeat: false,
              convertImagesToLinks: false,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: null,
              bindNavPrevention: true,
              postfix: "",
              imageUploader: {
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              },
              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%2f239164%2fsending-shell-script-command-keystrokes-to-a-remote-shell%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              3 Answers
              3






              active

              oldest

              votes








              3 Answers
              3






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              1














              are you looking for



               sudo gatttool -b 80:EA:CA:00:00:03 -I  <<EOF
              # All these commands are entered in interactive mode
              connect
              while [ 1 ]; do
              char_read_hnd 0x0030 > a.txt
              done
              exit 1
              EOF


              the syntax cmd <<EOF (lines ) EOF (on a line of its onw) is called a here doc.






              share|improve this answer
























              • more complicated tasks involving e.g. waiting for a prompt or a particular response from the remote host should be done with the expect scripting language, or perl's Expect.pm module or python's pexpect. Other languages also have similar expect-like libraries.

                – cas
                Oct 28 '15 at 9:34













              • @cas Yes <<EOF does the trick, but I have to wait for a particular message from remote host to execute the other commands. As I am new to scripting language, I will have to look into other scripting language.

                – Ank Khandelwal
                Oct 28 '15 at 9:53


















              1














              are you looking for



               sudo gatttool -b 80:EA:CA:00:00:03 -I  <<EOF
              # All these commands are entered in interactive mode
              connect
              while [ 1 ]; do
              char_read_hnd 0x0030 > a.txt
              done
              exit 1
              EOF


              the syntax cmd <<EOF (lines ) EOF (on a line of its onw) is called a here doc.






              share|improve this answer
























              • more complicated tasks involving e.g. waiting for a prompt or a particular response from the remote host should be done with the expect scripting language, or perl's Expect.pm module or python's pexpect. Other languages also have similar expect-like libraries.

                – cas
                Oct 28 '15 at 9:34













              • @cas Yes <<EOF does the trick, but I have to wait for a particular message from remote host to execute the other commands. As I am new to scripting language, I will have to look into other scripting language.

                – Ank Khandelwal
                Oct 28 '15 at 9:53
















              1












              1








              1







              are you looking for



               sudo gatttool -b 80:EA:CA:00:00:03 -I  <<EOF
              # All these commands are entered in interactive mode
              connect
              while [ 1 ]; do
              char_read_hnd 0x0030 > a.txt
              done
              exit 1
              EOF


              the syntax cmd <<EOF (lines ) EOF (on a line of its onw) is called a here doc.






              share|improve this answer













              are you looking for



               sudo gatttool -b 80:EA:CA:00:00:03 -I  <<EOF
              # All these commands are entered in interactive mode
              connect
              while [ 1 ]; do
              char_read_hnd 0x0030 > a.txt
              done
              exit 1
              EOF


              the syntax cmd <<EOF (lines ) EOF (on a line of its onw) is called a here doc.







              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Oct 28 '15 at 9:12









              ArchemarArchemar

              20.2k93773




              20.2k93773













              • more complicated tasks involving e.g. waiting for a prompt or a particular response from the remote host should be done with the expect scripting language, or perl's Expect.pm module or python's pexpect. Other languages also have similar expect-like libraries.

                – cas
                Oct 28 '15 at 9:34













              • @cas Yes <<EOF does the trick, but I have to wait for a particular message from remote host to execute the other commands. As I am new to scripting language, I will have to look into other scripting language.

                – Ank Khandelwal
                Oct 28 '15 at 9:53





















              • more complicated tasks involving e.g. waiting for a prompt or a particular response from the remote host should be done with the expect scripting language, or perl's Expect.pm module or python's pexpect. Other languages also have similar expect-like libraries.

                – cas
                Oct 28 '15 at 9:34













              • @cas Yes <<EOF does the trick, but I have to wait for a particular message from remote host to execute the other commands. As I am new to scripting language, I will have to look into other scripting language.

                – Ank Khandelwal
                Oct 28 '15 at 9:53



















              more complicated tasks involving e.g. waiting for a prompt or a particular response from the remote host should be done with the expect scripting language, or perl's Expect.pm module or python's pexpect. Other languages also have similar expect-like libraries.

              – cas
              Oct 28 '15 at 9:34







              more complicated tasks involving e.g. waiting for a prompt or a particular response from the remote host should be done with the expect scripting language, or perl's Expect.pm module or python's pexpect. Other languages also have similar expect-like libraries.

              – cas
              Oct 28 '15 at 9:34















              @cas Yes <<EOF does the trick, but I have to wait for a particular message from remote host to execute the other commands. As I am new to scripting language, I will have to look into other scripting language.

              – Ank Khandelwal
              Oct 28 '15 at 9:53







              @cas Yes <<EOF does the trick, but I have to wait for a particular message from remote host to execute the other commands. As I am new to scripting language, I will have to look into other scripting language.

              – Ank Khandelwal
              Oct 28 '15 at 9:53















              1














              If you need just write or read you can use one string command like this:



              gatttool -i hci0 -b device=MAC --char-write-req -a handle=0x0001 -n value=0x0001

              gatttool -i hci0 -b device=MAC --char-read -a handle=0x0001


              I found it here: http://www.mathieupassenaud.fr/control-your-plugs-with-bluetooth-and-bash-scripts/.



              To find more options see gatttool --help-all.






              share|improve this answer




























                1














                If you need just write or read you can use one string command like this:



                gatttool -i hci0 -b device=MAC --char-write-req -a handle=0x0001 -n value=0x0001

                gatttool -i hci0 -b device=MAC --char-read -a handle=0x0001


                I found it here: http://www.mathieupassenaud.fr/control-your-plugs-with-bluetooth-and-bash-scripts/.



                To find more options see gatttool --help-all.






                share|improve this answer


























                  1












                  1








                  1







                  If you need just write or read you can use one string command like this:



                  gatttool -i hci0 -b device=MAC --char-write-req -a handle=0x0001 -n value=0x0001

                  gatttool -i hci0 -b device=MAC --char-read -a handle=0x0001


                  I found it here: http://www.mathieupassenaud.fr/control-your-plugs-with-bluetooth-and-bash-scripts/.



                  To find more options see gatttool --help-all.






                  share|improve this answer













                  If you need just write or read you can use one string command like this:



                  gatttool -i hci0 -b device=MAC --char-write-req -a handle=0x0001 -n value=0x0001

                  gatttool -i hci0 -b device=MAC --char-read -a handle=0x0001


                  I found it here: http://www.mathieupassenaud.fr/control-your-plugs-with-bluetooth-and-bash-scripts/.



                  To find more options see gatttool --help-all.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Feb 17 '17 at 13:08









                  Herman Y.Herman Y.

                  113




                  113























                      0














                      You can use expect for shell or pexpect for python.



                      I think you're searching for something like this:
                      https://www.torsten-traenkner.de/wissen/smarthome/heizung.php






                      share|improve this answer




























                        0














                        You can use expect for shell or pexpect for python.



                        I think you're searching for something like this:
                        https://www.torsten-traenkner.de/wissen/smarthome/heizung.php






                        share|improve this answer


























                          0












                          0








                          0







                          You can use expect for shell or pexpect for python.



                          I think you're searching for something like this:
                          https://www.torsten-traenkner.de/wissen/smarthome/heizung.php






                          share|improve this answer













                          You can use expect for shell or pexpect for python.



                          I think you're searching for something like this:
                          https://www.torsten-traenkner.de/wissen/smarthome/heizung.php







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Feb 22 at 7:17









                          rundekugelrundekugel

                          1012




                          1012






























                              draft saved

                              draft discarded




















































                              Thanks for contributing an answer to Unix & Linux Stack Exchange!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid



                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.


                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function () {
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f239164%2fsending-shell-script-command-keystrokes-to-a-remote-shell%23new-answer', 'question_page');
                              }
                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              How to make a Squid Proxy server?

                              第一次世界大戦

                              Touch on Surface Book