Timestamp in shell code script

shell-scriptingunix

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?

Best Answer

#!/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"