Sometimes you like to copy files from A to B and you have sudo rights on A and B and you do a lot of “cp” to /tmp and chmod and chown’s. This is annoying…
Firstly, I dislike tempfiles.
- they use space
- they generate bugs when run in parallel
- they often are prone to code injection
- they remain on disk for years
Secondly, unix guys like pipes. While would one do
p <a >b
q <b >c
when you can
p <a |q >c
Lastly, I like to type less. So I wrote a small shell script that copies and uses sudo
combine #scp with #sudo?
ssh srv1 "cd /foo;sudo tar cf – bar"|ssh srv2 "cd /foo;sudo tar xf -"
— laurentsch (@laurentsch) December 7, 2020
at the end, I can
scp++ srv1:/dir/file srv2:/dir
see comments for the script
ssh $SRCSRV "cd $SRCDIR;tar cf - $SRCFILE"|
ssh $DSTSRV "cd $DSTDIR;sudo tar xf -"
ssh $DSTSRV "ls -l $DSTDIR/$SRCFILE"