Created
August 12, 2011 16:33
-
-
Save ebot/1142420 to your computer and use it in GitHub Desktop.
Script that downloads file on Mar 1 if Feb only has 28 days
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env ruby -wKU | |
| # Non Leap Year Download Script | |
| # Create By Ed Botzum | |
| # Last Updated 2011-08-12 | |
| # Code maintained at https://gist.github.com/1142420 | |
| # | |
| # This script will download the specified files on March 1 in years when | |
| # February has only twenty eight days, b/c the normal monthly job is scheduled | |
| # to run on the twenty ninth of each month. This custom job will run on the | |
| # first of each month. Yay rediculous waste! | |
| require 'date' | |
| require 'net/sftp' | |
| remote_files = ['BMCstfa', 'BMCstfo', 'FMCstfa', 'FMCstfo', 'MLHstfa', 'MLHstfo'] | |
| remote_dir = '' | |
| local_dir = '' | |
| ftp_server = '' | |
| user_name = '' | |
| password = '' | |
| today = Date.today | |
| puts "If today is March 1 of a non leap year get the #{remote_files.join(',')} files from #{ftp_server}." | |
| puts "Today is #{today}\n\n" | |
| unless today.leap? | |
| puts 'This is not a leap year.' | |
| last_month = today.month - 1 | |
| if last_month == 2 | |
| puts 'We need to get the files b/c last month was February!' | |
| Net::SFTP.start( ftp_server, user_name, :password => password ) do |sftp| | |
| sftp.dir.foreach(remote_dir) do |entry| | |
| puts entry.name | |
| name = entry.name.split '-' | |
| if (remote_files.include?( name[0] ) and name[1].index( '.TVS' ) != nil) | |
| puts " Downloading to #{local_dir}" | |
| sftp.download!( File.join( remote_dir, entry.name ), File.join( local_dir, entry.name ) ) | |
| puts " Deleting remote file" | |
| sftp.remove!( File.join( remote_dir, entry.name ) ) | |
| end | |
| end | |
| end | |
| else | |
| puts 'Last month was not February, so we do not need to do anything.' | |
| end | |
| else | |
| puts 'This is a leap year, so I am not needed - Feb has 29 days this year.' | |
| puts 'Happy Birthday Leap Babies!!' | |
| end | |
| puts "\nFinished custom FTP for Non Leap Year Statements" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment