-
-
Save jsoningram/fc52b3f49c9ec5498cc8 to your computer and use it in GitHub Desktop.
bash script to batch rename via FTP and automate uploads
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
#!/bin/bash | |
# command to rename (move) files on DPG | |
FILES=/Live/*.tif | |
NAME='USERNAME' | |
PASSWORD='PASSWORD' | |
SERVER='SERVER' | |
DIRLIST=dirlist`date +%H%M%j`.txt | |
MOD=mod`date +%H%M%j`.txt | |
UPLOADS='/Volumes/Kerouac/SP/Stage' | |
# log into server and get list of current files, then use awk to skinny the list to just the file names | |
ftp -pin $SERVER <<END_SCRIPT | |
user $NAME $PASSWORD | |
# toggle epsv fixes hang when entering extended passive mode | |
epsv | |
cd Live | |
ls > /tmp/$DIRLIST | |
quit | |
END_SCRIPT | |
awk -F" " 'NR>2 {print $9} ' /tmp/$DIRLIST > /tmp/$MOD | |
# log in again and loop through list to move each file to another dir. Then upload new files and clean up | |
cd $UPLOADS | |
echo "open $SERVER | |
user $NAME $PASSWORD | |
epsv | |
binary | |
cd Live" > /tmp/ftp.$$ | |
cat /tmp/$MOD | while read tif | |
do | |
echo "rename $tif ../Done/$tif" >> /tmp/ftp.$$ | |
done | |
echo "mput *.tif | |
quit" >> /tmp/ftp.$$ | |
ftp -pin < /tmp/ftp.$$ | |
rm /tmp/ftp.$$ | |
rm /tmp/$DIRLIST | |
rm /tmp/$MOD |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment