Renombre de archivos con BASH linux por FTP
#!/bin/bash
HOST='sftp://myhost'
USER='user'
PASSWORD='pass'
LFTP=/usr/bin/lftp
folders=(
/logs/caching/2017/06/29/
/logs/caching/2017/07/03/
/logs/caching/2017/07/04/
)
for f in "${folders[@]}"
do
echo "############ folder $f "
$LFTP -u "$USER","$PASSWORD" $HOST -e "ls $f; exit" > subfolders.tmp
tail -n +3 subfolders.tmp > subfolders.txt
while IFS= read subfolder
do
SUBFOLDER_TMP=$f$(echo $subfolder | awk '{print $9}')
echo "######## subfolder $SUBFOLDER_TMP "
$LFTP -u "$USER","$PASSWORD" $HOST -e "ls $SUBFOLDER_TMP; exit" > list.txt.tmp
tail -n +3 list.txt.tmp > list.txt
while IFS= read var
do
FILE=$(echo $var | awk '{print $9}')
if echo $FILE | grep -e 'OK_'; then
NAME_FILE=$(echo $FILE | sed 's/OK_//')
echo $FILE "->" $NAME_FILE
$LFTP -u "$USER","$PASSWORD" $HOST <<EOF
set sftp:auto-confirm yes
set ftp:ssl-allow no
cd $SUBFOLDER_TMP
mv $FILE $NAME_FILE
exit
EOF
fi
done < list.txt
done < subfolders.txt
done
rm -f list.txt.tmp
rm -f list.txt
rm -f subfolders.txt
rm -f subfolders.tmp
HOST='sftp://myhost'
USER='user'
PASSWORD='pass'
LFTP=/usr/bin/lftp
folders=(
/logs/caching/2017/06/29/
/logs/caching/2017/07/03/
/logs/caching/2017/07/04/
)
for f in "${folders[@]}"
do
echo "############ folder $f "
$LFTP -u "$USER","$PASSWORD" $HOST -e "ls $f; exit" > subfolders.tmp
tail -n +3 subfolders.tmp > subfolders.txt
while IFS= read subfolder
do
SUBFOLDER_TMP=$f$(echo $subfolder | awk '{print $9}')
echo "######## subfolder $SUBFOLDER_TMP "
$LFTP -u "$USER","$PASSWORD" $HOST -e "ls $SUBFOLDER_TMP; exit" > list.txt.tmp
tail -n +3 list.txt.tmp > list.txt
while IFS= read var
do
FILE=$(echo $var | awk '{print $9}')
if echo $FILE | grep -e 'OK_'; then
NAME_FILE=$(echo $FILE | sed 's/OK_//')
echo $FILE "->" $NAME_FILE
$LFTP -u "$USER","$PASSWORD" $HOST <<EOF
set sftp:auto-confirm yes
set ftp:ssl-allow no
cd $SUBFOLDER_TMP
mv $FILE $NAME_FILE
exit
EOF
fi
done < list.txt
done < subfolders.txt
done
rm -f list.txt.tmp
rm -f list.txt
rm -f subfolders.txt
rm -f subfolders.tmp
Comentarios
Publicar un comentario