I’m working on the following bash script that I need to upload specific files that are over 10 MB:
#!/bin/sh
FTP_HOST=ftp.ftphost.com
FTP_USER=myftpuser
FTP_PASS=securepassword
[[ -n "$1" ]] || { echo "Usage: findlarge [PATHNAME]"; exit 0 ; }
FILES=`find "$1" -type f -size +10000k -printf '%p;'`
OLD_IFS="$IFS"
IFS=";"
FILES_ARRAY=( $FILES )
IFS="$OLD_IFS"
for fl in "${FILES_ARRAY[@]}"
do
INVERSE=`${fl//\/var\/www\/html/\/public_html}`
lftp -u $FTP_USER,$FTP_PASS -e "cd '${INVERSE}'; put '${fl}';quit" $FTP_HOST
done
It’s used for a specific CDN that needs larger files uploaded to their servers what it’s attempting to do and where I don’t know how to continue is the files on the host side are found at /var/www/html/ but the remote server needs them placed at /public_html/. I need the same file structure on the remote server as I do on the host server.
The issue that I’m running into is $INVERSE still includes the actual file name and the path.. I need a way to trim off the filename from the INVERSE variable so I can properly place files in the correct directory.
Does anybody know of a regex statement that can take something like:
/public_html/path/to/file/filename.zip
and change it to
/public_html/path/to/file/
You could use:
Does exactly what you want =)
Also, using regex with sed:
Explaining the regex:
On the replacement, we just make sure to not remove the last slash.