I am still a newbie to shell scripting and would like to make some backups of billing files I receive and then upload these to an FTP server directory, and upon completion archive the file into a new directory called archive. Here is what is tripping me up:
The billing files are sent with a random sub string included (ex. 020001.030002.XXXXX.01.2 where XXXXXX is changed daily). What I need to do is use something like awk to find the substring in the filename, copy it to a variable so I can use it to push the filename to the FTP server, and then archive the file. I then need to place the variable in something that resembles FILE=020001.030002.($VARIABLE).01.2.
I located this post on stackoverflow which is similar in nature, however since I have a random input file each time I am having difficulty figuring out how to accomplish this task. If this is not something which can be done through shell scripting is there another way (Python, etc) to accomplish this task?
Sample filenames - again they are randomly created by my billing server: (note there is not an extension on the end of these files)
- 020001.030002.00320.01.2
- 020001.030002.07243.01.2
- 020001.030002.12048.01.2
Required format should leave this file name intact to be placed in a FTP script for upload such as:
#/bin/bash
FTPU="user" # ftp login name
FTPP="passwd" # ftp password
FTPS="ftp.server.com" # remote ftp server
FTPF="/home/backup/" # remote ftp server directory for $FTPU & $FTPP
LOCALFILE="020001.030002.($INSERT_VARIABLE_HERE).01.2"
ncftpput -m -u $FTPU -p $FTPP $FTPS $FTPF $LOCALFILE