Created
May 31, 2019 19:52
-
-
Save ronsims2/ba404c24dfc0736f61840224deccdfed to your computer and use it in GitHub Desktop.
Move files using Bash and SFTP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# create a heredoc of the command you want to run, run and assign outout to a variable | |
getfiles=`sftp [email protected] <<GETF | |
ls | |
bye | |
GETF` | |
# Execute command and filter output, quote output to preserve new lines, this assumes all files desired are prefixed foobar_ | |
filelist=`echo "$getfiles"|grep 'foobar_'` | |
( | |
for file in $filelist; do | |
echo rename $file old/$file | |
done | |
echo bye | |
) | sftp [email protected] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment