0

Good Morning,

I have a burning question regarding a particular bash script that I am trying to run. This script is downloading a file, then saving it to another folder. The script will not be running on a cron every single day, and I was curious if there is a way to write it so if I miss say 10 days, it will know to download a textfile from the directory that corresponds with each specific day I missed. I currently am saving a text file of the last current runtime. Here's an example of what I have so far!

#!/bin/bash

    YMDa=$(date +%Y%m%d)
    echo "${runtime}"

    echo "${YMDa}"


    wget --username --password  http://somewebsite.com

        mv nbcufs_master_10day_tmaxs master_10day_tmaxs_${YMDa}
        mv master_10day_tmaxs_${YMDa} 'C:\Users\Wiggles\Documents\Microsoft Excel\SubDirectory1\SubDirectory2\SubDirectory3'

    echo "${YMDa}" > latest_runtime


exit 0
E. Weglarz
  • 37
  • 1
  • 7

1 Answers1

-1

You may want to look at this link: Bash: Looping through dates

Because you mention "missing a few dates", you could gather the name/timestamp/ect of the last dated file you've retrieved to set as the "start date" and then implement a cursor from that date onward via responses on the link above. I think Wintermute's response should help you get where you need.

I agree with cpburnz... give this snippet a whirl (input_start would be your last date ran)

#!/bin/bash
input_start=20160101
input_end=$(date +%Y%m%d)

startdate=$(date -d "$input_start" +%Y%m%d) || exit -1
enddate=$(date -d "$input_end" +%Y%m%d) || exit -1

d="$startdate"
while [ "$d" != "$enddate" ]; do
  directory="`pwd`/folder/$d"

  if [ -d $directory ]; then
    echo "No action for $d."
  else
    echo "Files not found for date $d"
    mkdir $directory
    # Do more actions...
  fi

  d=$(date -d "$d + 1 day" +%Y%m%d)
done
Community
  • 1
  • 1
Jeremy
  • 24
  • 5
  • Agreed, updated post accordingly. Meh, first effort on stackexchange after long time lurking. – Jeremy Jul 06 '16 at 21:32
  • Thank you all so much, Ill post again if I continue to hit a roadblock, but this material looks like it will help me over the hurdle! – E. Weglarz Jul 07 '16 at 01:25