wget and scp as a pipeline

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











up vote
0
down vote

favorite












Can we use wget and scp as a pipeline. I want to wget a file from a server and copy to another server. I used below command but it is not working.



wget "$Select_Release_Version_ARTIFACT_URL" | sudo scp test@192.168.94.137:/etc/test/









share|improve this question



























    up vote
    0
    down vote

    favorite












    Can we use wget and scp as a pipeline. I want to wget a file from a server and copy to another server. I used below command but it is not working.



    wget "$Select_Release_Version_ARTIFACT_URL" | sudo scp test@192.168.94.137:/etc/test/









    share|improve this question

























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      Can we use wget and scp as a pipeline. I want to wget a file from a server and copy to another server. I used below command but it is not working.



      wget "$Select_Release_Version_ARTIFACT_URL" | sudo scp test@192.168.94.137:/etc/test/









      share|improve this question















      Can we use wget and scp as a pipeline. I want to wget a file from a server and copy to another server. I used below command but it is not working.



      wget "$Select_Release_Version_ARTIFACT_URL" | sudo scp test@192.168.94.137:/etc/test/






      linux shell pipe wget scp






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited yesterday









      Jeff Schaller

      35.9k952119




      35.9k952119










      asked yesterday









      Janith

      52




      52




















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          1
          down vote













          To use wget in a pipe, you must make sure it writes to stdout instead to a file, so use wget -O- ....



          AFAIK, you can't use scp to copy from stdin. However, you can use ssh instead, and have it execute a command like cat, which reads from stdin.



          So together you get something like



          wget -O- "$Select_Release_Version_ARTIFACT_URL" | ssh test@192.168.94.137 'cat > /etc/test/some_file'


          Note that will only download and transfer a single file/webpage. Also note that user test on 192.168.94.137 needs rights to create and write to /etc/test/some_file. Using sudo before ssh won't give the remote user test any additional rights. It will allow to access ssh keys of root on the local machine, so if that was the intention, keep it.



          While this demonstrates how to use a pipe over ssh, it would have been easier to just execute wget on the remote machine, unless there are reasons why this is not possible.






          share|improve this answer



























            up vote
            0
            down vote













            Instead of pipe, you can use &&. This will make sure that when scp runs if wget has exit status of 0 (finished successfully).




            wget "$Select_Release_Version_ARTIFACT_URL" && sudo scp "$Select_Release_Version_ARTIFACT_URL" test@192.168.94.137:/etc/test/




            This works as following:



            wget downloads the file and IF SUCCESSFUL, it will initiate scp.



            NOTE: Since you are using sudo, this will ask the password test user every time this command will run.






            share|improve this answer




















            • I used passwordless authentication, I think no need of providing password.
              – Janith
              yesterday










            • When I using above command I am getting error. wget is working but scp is not working.
              – Janith
              yesterday











            • Note that if the named file already exists, wget will download into filename.1, filename.2, etc.
              – Ulrich Schwarz
              yesterday










            • Yes can I write a scrip to download and copy to remote machine same time?
              – Janith
              yesterday










            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: 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%2f481849%2fwget-and-scp-as-a-pipeline%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            1
            down vote













            To use wget in a pipe, you must make sure it writes to stdout instead to a file, so use wget -O- ....



            AFAIK, you can't use scp to copy from stdin. However, you can use ssh instead, and have it execute a command like cat, which reads from stdin.



            So together you get something like



            wget -O- "$Select_Release_Version_ARTIFACT_URL" | ssh test@192.168.94.137 'cat > /etc/test/some_file'


            Note that will only download and transfer a single file/webpage. Also note that user test on 192.168.94.137 needs rights to create and write to /etc/test/some_file. Using sudo before ssh won't give the remote user test any additional rights. It will allow to access ssh keys of root on the local machine, so if that was the intention, keep it.



            While this demonstrates how to use a pipe over ssh, it would have been easier to just execute wget on the remote machine, unless there are reasons why this is not possible.






            share|improve this answer
























              up vote
              1
              down vote













              To use wget in a pipe, you must make sure it writes to stdout instead to a file, so use wget -O- ....



              AFAIK, you can't use scp to copy from stdin. However, you can use ssh instead, and have it execute a command like cat, which reads from stdin.



              So together you get something like



              wget -O- "$Select_Release_Version_ARTIFACT_URL" | ssh test@192.168.94.137 'cat > /etc/test/some_file'


              Note that will only download and transfer a single file/webpage. Also note that user test on 192.168.94.137 needs rights to create and write to /etc/test/some_file. Using sudo before ssh won't give the remote user test any additional rights. It will allow to access ssh keys of root on the local machine, so if that was the intention, keep it.



              While this demonstrates how to use a pipe over ssh, it would have been easier to just execute wget on the remote machine, unless there are reasons why this is not possible.






              share|improve this answer






















                up vote
                1
                down vote










                up vote
                1
                down vote









                To use wget in a pipe, you must make sure it writes to stdout instead to a file, so use wget -O- ....



                AFAIK, you can't use scp to copy from stdin. However, you can use ssh instead, and have it execute a command like cat, which reads from stdin.



                So together you get something like



                wget -O- "$Select_Release_Version_ARTIFACT_URL" | ssh test@192.168.94.137 'cat > /etc/test/some_file'


                Note that will only download and transfer a single file/webpage. Also note that user test on 192.168.94.137 needs rights to create and write to /etc/test/some_file. Using sudo before ssh won't give the remote user test any additional rights. It will allow to access ssh keys of root on the local machine, so if that was the intention, keep it.



                While this demonstrates how to use a pipe over ssh, it would have been easier to just execute wget on the remote machine, unless there are reasons why this is not possible.






                share|improve this answer












                To use wget in a pipe, you must make sure it writes to stdout instead to a file, so use wget -O- ....



                AFAIK, you can't use scp to copy from stdin. However, you can use ssh instead, and have it execute a command like cat, which reads from stdin.



                So together you get something like



                wget -O- "$Select_Release_Version_ARTIFACT_URL" | ssh test@192.168.94.137 'cat > /etc/test/some_file'


                Note that will only download and transfer a single file/webpage. Also note that user test on 192.168.94.137 needs rights to create and write to /etc/test/some_file. Using sudo before ssh won't give the remote user test any additional rights. It will allow to access ssh keys of root on the local machine, so if that was the intention, keep it.



                While this demonstrates how to use a pipe over ssh, it would have been easier to just execute wget on the remote machine, unless there are reasons why this is not possible.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered yesterday









                dirkt

                16k21234




                16k21234






















                    up vote
                    0
                    down vote













                    Instead of pipe, you can use &&. This will make sure that when scp runs if wget has exit status of 0 (finished successfully).




                    wget "$Select_Release_Version_ARTIFACT_URL" && sudo scp "$Select_Release_Version_ARTIFACT_URL" test@192.168.94.137:/etc/test/




                    This works as following:



                    wget downloads the file and IF SUCCESSFUL, it will initiate scp.



                    NOTE: Since you are using sudo, this will ask the password test user every time this command will run.






                    share|improve this answer




















                    • I used passwordless authentication, I think no need of providing password.
                      – Janith
                      yesterday










                    • When I using above command I am getting error. wget is working but scp is not working.
                      – Janith
                      yesterday











                    • Note that if the named file already exists, wget will download into filename.1, filename.2, etc.
                      – Ulrich Schwarz
                      yesterday










                    • Yes can I write a scrip to download and copy to remote machine same time?
                      – Janith
                      yesterday














                    up vote
                    0
                    down vote













                    Instead of pipe, you can use &&. This will make sure that when scp runs if wget has exit status of 0 (finished successfully).




                    wget "$Select_Release_Version_ARTIFACT_URL" && sudo scp "$Select_Release_Version_ARTIFACT_URL" test@192.168.94.137:/etc/test/




                    This works as following:



                    wget downloads the file and IF SUCCESSFUL, it will initiate scp.



                    NOTE: Since you are using sudo, this will ask the password test user every time this command will run.






                    share|improve this answer




















                    • I used passwordless authentication, I think no need of providing password.
                      – Janith
                      yesterday










                    • When I using above command I am getting error. wget is working but scp is not working.
                      – Janith
                      yesterday











                    • Note that if the named file already exists, wget will download into filename.1, filename.2, etc.
                      – Ulrich Schwarz
                      yesterday










                    • Yes can I write a scrip to download and copy to remote machine same time?
                      – Janith
                      yesterday












                    up vote
                    0
                    down vote










                    up vote
                    0
                    down vote









                    Instead of pipe, you can use &&. This will make sure that when scp runs if wget has exit status of 0 (finished successfully).




                    wget "$Select_Release_Version_ARTIFACT_URL" && sudo scp "$Select_Release_Version_ARTIFACT_URL" test@192.168.94.137:/etc/test/




                    This works as following:



                    wget downloads the file and IF SUCCESSFUL, it will initiate scp.



                    NOTE: Since you are using sudo, this will ask the password test user every time this command will run.






                    share|improve this answer












                    Instead of pipe, you can use &&. This will make sure that when scp runs if wget has exit status of 0 (finished successfully).




                    wget "$Select_Release_Version_ARTIFACT_URL" && sudo scp "$Select_Release_Version_ARTIFACT_URL" test@192.168.94.137:/etc/test/




                    This works as following:



                    wget downloads the file and IF SUCCESSFUL, it will initiate scp.



                    NOTE: Since you are using sudo, this will ask the password test user every time this command will run.







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered yesterday









                    sla3k

                    3134




                    3134











                    • I used passwordless authentication, I think no need of providing password.
                      – Janith
                      yesterday










                    • When I using above command I am getting error. wget is working but scp is not working.
                      – Janith
                      yesterday











                    • Note that if the named file already exists, wget will download into filename.1, filename.2, etc.
                      – Ulrich Schwarz
                      yesterday










                    • Yes can I write a scrip to download and copy to remote machine same time?
                      – Janith
                      yesterday
















                    • I used passwordless authentication, I think no need of providing password.
                      – Janith
                      yesterday










                    • When I using above command I am getting error. wget is working but scp is not working.
                      – Janith
                      yesterday











                    • Note that if the named file already exists, wget will download into filename.1, filename.2, etc.
                      – Ulrich Schwarz
                      yesterday










                    • Yes can I write a scrip to download and copy to remote machine same time?
                      – Janith
                      yesterday















                    I used passwordless authentication, I think no need of providing password.
                    – Janith
                    yesterday




                    I used passwordless authentication, I think no need of providing password.
                    – Janith
                    yesterday












                    When I using above command I am getting error. wget is working but scp is not working.
                    – Janith
                    yesterday





                    When I using above command I am getting error. wget is working but scp is not working.
                    – Janith
                    yesterday













                    Note that if the named file already exists, wget will download into filename.1, filename.2, etc.
                    – Ulrich Schwarz
                    yesterday




                    Note that if the named file already exists, wget will download into filename.1, filename.2, etc.
                    – Ulrich Schwarz
                    yesterday












                    Yes can I write a scrip to download and copy to remote machine same time?
                    – Janith
                    yesterday




                    Yes can I write a scrip to download and copy to remote machine same time?
                    – Janith
                    yesterday

















                     

                    draft saved


                    draft discarded















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f481849%2fwget-and-scp-as-a-pipeline%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 check contact read email or not when send email to Individual?

                    Bahrain

                    Postfix configuration issue with fips on centos 7; mailgun relay