0

I'm new in shell coding and hopefully I'm in the right place to ask this question. I'm working with a shell script which collect daily file and send them via ftp. In the filename there are both date and time and type of files is text(.txt). Files are in a directory in which there are many other files that are created daily at different time. Those files that I'm trying to send are created at 08 am but with different minute and seconds. for example:

team1_mnpg_ef_part_2018-02-26_080005.txt
team1_abc_part_2018-02-26_080031.txt

Time is different in the filename but all of them have 08 for hour and I want to send all files that has for example today date and 08 as hour with whatever minute and seconds(it doesn't matter which minute and second). Here is my code:

#!/bin/ksh
#
#

DATE=`date "+%Y-%m-%d"`

HOST='abcd.dmn.com'
USER='*****'
PASSWD='******'
LOCALPATH='/opt/abc/Output'
LOGPATH='/opt/abc/logs'


ftp -n -v $HOST <<END_SCRIPT>>$LOGPATH/ftp_abc_$DATE_log.txt
quote USER $USER
quote PASS $PASSWD
lcd $LOCALPATH
put team1_abc_part_$DATE_(I do not know what should I write here).txt
put team1_mnpg_ef_part_$DATE_.txt
put team1_fdop_part_$DATE_.txt

quit
END_SCRIPT
exit 0

Files are in the directory and when I write the timestamp,for example put team1_abc_part_$DATE_080031.txt in the above script, it works fine and I can see the sent file on destination server.

What should I write for time part in the filename so that script sends the files that has been created at 08 with whatever minute and second?

0
#!/bin/ksh
#
#

DATE=`date "+%Y-%m-%d"`
HOUR=`date "+%H"`
.....
mput team1_abc_part_$DATE_$HOUR*txt
.......

You should use "mput" instead of "put" https://stackoverflow.com/questions/6692799/how-to-ftp-multiple-file-using-shell-script

also could be usefull:

# get timestamp
date +%s
# from timestamp to Date
date "+%Y-%m-%d" -d @1519661267
# date 2 minuts ago
date "+%Y-%m-%d" -d "-2 min"
  • Sorry if I forgot to mention that I need to run the shell code at 16:00 pm. I tested with running the code with your suggested solution at the time after 10 am and it shows the current hour for example team1_abc_part_12*.txt in the filename and getting error that the file could not be found. There is something strang that the date is not showed in file name but when I add a '' in front of $DATE($DATE) , the date will be showed like this: team1_abc_part_2018-02-27*_12*.txt – Florentina Feb 27 '18 at 12:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.