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 email@example.com:/etc/test/
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
So together you get something like
wget -O- "$Select_Release_Version_ARTIFACT_URL" | ssh firstname.lastname@example.org 'cat > /etc/test/some_file'
Note that will only download and transfer a single file/webpage. Also note that user
192.168.94.137 needs rights to create and write to
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.
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" email@example.com:/etc/test/
This works as following:
wget downloads the file and IF SUCCESSFUL, it will initiate
NOTE: Since you are using
sudo, this will ask the password
test user every time this command will run.