Convert WPA_passphrase output to /etc/network/interface

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
3
down vote

favorite












This is primarily a formatting problem which I haven't been able to solve well.



I want to create a bash function or script which converts output from wpa-passphrase to a format that can be used by /etc/network/interfaces.



Example WPA-Supplicant



wpa_passphrase ssid password


Produces the following output



network=
ssid="MYSSID"
#psk="passphrase"
psk=ccb290fd4fe6b22935cbae31449e050edd02ad44627b16ce0151668f5f53c01b



I need to convert that output to a format which can be used by /etc/network/interfaces



Example of the /etc/network/interface output format:



auto wlan0
iface wlan0 inet dhcp
wpa-ssid MYSSID
wpa-psk ccb290fd4fe6b22935cbae31449e050edd02ad44627b16ce0151668f5f53c01b


My first crude solution was to use:



wpa_passphrase MYSSID PASSWORD |grep -E 'ssid|psk' |grep -v "#psk" |cut -d '=' -f 2


Which gives me:



MYSSID
ccb290fd4fe6b22935cbae31449e050edd02ad44627b16ce0151668f5f53c01b


but I don't know how to get each of those lines into their proper place in the /etc/network/interfaces format



UPDATE: With my current solution



After further attempts I managed to get it to work with this:



while read line
do
echo "auto wlp3s0"
echo "iface wlp3s0 inet dhcp"
echo -e "t wpa-ssid $line"
done < <(sudo wpa_passphrase $1 $2 |grep -E 'ssid' |cut -d '=' -f 2)

while read line
do
echo -e "t wpa-psk $line"
done < <(sudo wpa_passphrase $1 $2 |grep -E 'psk' |grep -v "#psk" |cut -d '=' -f 2)


My solution gives the output I need, but it does not seem efficient and I would still like to see other solutions.










share|improve this question



























    up vote
    3
    down vote

    favorite












    This is primarily a formatting problem which I haven't been able to solve well.



    I want to create a bash function or script which converts output from wpa-passphrase to a format that can be used by /etc/network/interfaces.



    Example WPA-Supplicant



    wpa_passphrase ssid password


    Produces the following output



    network=
    ssid="MYSSID"
    #psk="passphrase"
    psk=ccb290fd4fe6b22935cbae31449e050edd02ad44627b16ce0151668f5f53c01b



    I need to convert that output to a format which can be used by /etc/network/interfaces



    Example of the /etc/network/interface output format:



    auto wlan0
    iface wlan0 inet dhcp
    wpa-ssid MYSSID
    wpa-psk ccb290fd4fe6b22935cbae31449e050edd02ad44627b16ce0151668f5f53c01b


    My first crude solution was to use:



    wpa_passphrase MYSSID PASSWORD |grep -E 'ssid|psk' |grep -v "#psk" |cut -d '=' -f 2


    Which gives me:



    MYSSID
    ccb290fd4fe6b22935cbae31449e050edd02ad44627b16ce0151668f5f53c01b


    but I don't know how to get each of those lines into their proper place in the /etc/network/interfaces format



    UPDATE: With my current solution



    After further attempts I managed to get it to work with this:



    while read line
    do
    echo "auto wlp3s0"
    echo "iface wlp3s0 inet dhcp"
    echo -e "t wpa-ssid $line"
    done < <(sudo wpa_passphrase $1 $2 |grep -E 'ssid' |cut -d '=' -f 2)

    while read line
    do
    echo -e "t wpa-psk $line"
    done < <(sudo wpa_passphrase $1 $2 |grep -E 'psk' |grep -v "#psk" |cut -d '=' -f 2)


    My solution gives the output I need, but it does not seem efficient and I would still like to see other solutions.










    share|improve this question

























      up vote
      3
      down vote

      favorite









      up vote
      3
      down vote

      favorite











      This is primarily a formatting problem which I haven't been able to solve well.



      I want to create a bash function or script which converts output from wpa-passphrase to a format that can be used by /etc/network/interfaces.



      Example WPA-Supplicant



      wpa_passphrase ssid password


      Produces the following output



      network=
      ssid="MYSSID"
      #psk="passphrase"
      psk=ccb290fd4fe6b22935cbae31449e050edd02ad44627b16ce0151668f5f53c01b



      I need to convert that output to a format which can be used by /etc/network/interfaces



      Example of the /etc/network/interface output format:



      auto wlan0
      iface wlan0 inet dhcp
      wpa-ssid MYSSID
      wpa-psk ccb290fd4fe6b22935cbae31449e050edd02ad44627b16ce0151668f5f53c01b


      My first crude solution was to use:



      wpa_passphrase MYSSID PASSWORD |grep -E 'ssid|psk' |grep -v "#psk" |cut -d '=' -f 2


      Which gives me:



      MYSSID
      ccb290fd4fe6b22935cbae31449e050edd02ad44627b16ce0151668f5f53c01b


      but I don't know how to get each of those lines into their proper place in the /etc/network/interfaces format



      UPDATE: With my current solution



      After further attempts I managed to get it to work with this:



      while read line
      do
      echo "auto wlp3s0"
      echo "iface wlp3s0 inet dhcp"
      echo -e "t wpa-ssid $line"
      done < <(sudo wpa_passphrase $1 $2 |grep -E 'ssid' |cut -d '=' -f 2)

      while read line
      do
      echo -e "t wpa-psk $line"
      done < <(sudo wpa_passphrase $1 $2 |grep -E 'psk' |grep -v "#psk" |cut -d '=' -f 2)


      My solution gives the output I need, but it does not seem efficient and I would still like to see other solutions.










      share|improve this question















      This is primarily a formatting problem which I haven't been able to solve well.



      I want to create a bash function or script which converts output from wpa-passphrase to a format that can be used by /etc/network/interfaces.



      Example WPA-Supplicant



      wpa_passphrase ssid password


      Produces the following output



      network=
      ssid="MYSSID"
      #psk="passphrase"
      psk=ccb290fd4fe6b22935cbae31449e050edd02ad44627b16ce0151668f5f53c01b



      I need to convert that output to a format which can be used by /etc/network/interfaces



      Example of the /etc/network/interface output format:



      auto wlan0
      iface wlan0 inet dhcp
      wpa-ssid MYSSID
      wpa-psk ccb290fd4fe6b22935cbae31449e050edd02ad44627b16ce0151668f5f53c01b


      My first crude solution was to use:



      wpa_passphrase MYSSID PASSWORD |grep -E 'ssid|psk' |grep -v "#psk" |cut -d '=' -f 2


      Which gives me:



      MYSSID
      ccb290fd4fe6b22935cbae31449e050edd02ad44627b16ce0151668f5f53c01b


      but I don't know how to get each of those lines into their proper place in the /etc/network/interfaces format



      UPDATE: With my current solution



      After further attempts I managed to get it to work with this:



      while read line
      do
      echo "auto wlp3s0"
      echo "iface wlp3s0 inet dhcp"
      echo -e "t wpa-ssid $line"
      done < <(sudo wpa_passphrase $1 $2 |grep -E 'ssid' |cut -d '=' -f 2)

      while read line
      do
      echo -e "t wpa-psk $line"
      done < <(sudo wpa_passphrase $1 $2 |grep -E 'psk' |grep -v "#psk" |cut -d '=' -f 2)


      My solution gives the output I need, but it does not seem efficient and I would still like to see other solutions.







      shell-script awk text-formatting






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Aug 30 at 23:06









      jww

      1,45732155




      1,45732155










      asked Aug 29 at 0:49









      Jay Hawk

      285




      285




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          3
          down vote



          accepted










          You can make a function as below and use awk to format the output as you want:



          generate() 
          sudo wpa_passphrase "$1" "$2"


          Then call generate "my SSID" "PASSWORD".



          Output would be:



          auto wlan0
          iface wlan0 inet dhcp
          wpa-ssid "my SSID"
          wpa-psk ccb290fd4fe6b22935cbae31449e050edd02ad44627b16ce0151668f5f53c01b





          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%2f465405%2fconvert-wpa-passphrase-output-to-etc-network-interface%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
            3
            down vote



            accepted










            You can make a function as below and use awk to format the output as you want:



            generate() 
            sudo wpa_passphrase "$1" "$2"


            Then call generate "my SSID" "PASSWORD".



            Output would be:



            auto wlan0
            iface wlan0 inet dhcp
            wpa-ssid "my SSID"
            wpa-psk ccb290fd4fe6b22935cbae31449e050edd02ad44627b16ce0151668f5f53c01b





            share|improve this answer


























              up vote
              3
              down vote



              accepted










              You can make a function as below and use awk to format the output as you want:



              generate() 
              sudo wpa_passphrase "$1" "$2"


              Then call generate "my SSID" "PASSWORD".



              Output would be:



              auto wlan0
              iface wlan0 inet dhcp
              wpa-ssid "my SSID"
              wpa-psk ccb290fd4fe6b22935cbae31449e050edd02ad44627b16ce0151668f5f53c01b





              share|improve this answer
























                up vote
                3
                down vote



                accepted







                up vote
                3
                down vote



                accepted






                You can make a function as below and use awk to format the output as you want:



                generate() 
                sudo wpa_passphrase "$1" "$2"


                Then call generate "my SSID" "PASSWORD".



                Output would be:



                auto wlan0
                iface wlan0 inet dhcp
                wpa-ssid "my SSID"
                wpa-psk ccb290fd4fe6b22935cbae31449e050edd02ad44627b16ce0151668f5f53c01b





                share|improve this answer














                You can make a function as below and use awk to format the output as you want:



                generate() 
                sudo wpa_passphrase "$1" "$2"


                Then call generate "my SSID" "PASSWORD".



                Output would be:



                auto wlan0
                iface wlan0 inet dhcp
                wpa-ssid "my SSID"
                wpa-psk ccb290fd4fe6b22935cbae31449e050edd02ad44627b16ce0151668f5f53c01b






                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Aug 31 at 3:06

























                answered Aug 29 at 4:55









                αғsнιη

                15.9k92563




                15.9k92563



























                     

                    draft saved


                    draft discarded















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f465405%2fconvert-wpa-passphrase-output-to-etc-network-interface%23new-answer', 'question_page');

                    );

                    Post as a guest













































































                    Popular posts from this blog

                    How to check contact read email or not when send email to Individual?

                    Displaying single band from multi-band raster using QGIS

                    How many registers does an x86_64 CPU actually have?