The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Calling a script from any directory ketanr Shell Programming and Scripting 1 10-17-2007 01:16 PM
find full directory and delete old dated file? xramm Shell Programming and Scripting 2 07-07-2007 06:56 AM
Hep with script to monitor directory cmf00186 UNIX for Dummies Questions & Answers 2 10-25-2006 11:42 AM
Suns newest windows workstation replacement Optimus_P News, Links, Events and Announcements 0 04-23-2004 02:02 PM
Using ls in a script for another directory jagannatha UNIX for Dummies Questions & Answers 17 06-05-2003 03:52 PM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-11-2006
Registered User
 

Join Date: Jan 2006
Posts: 1
Stumble this Post!
Script to cd into newest (dated) FTP directory

I have written the following simple bash script. It logs onto an FTP site and then CDs into a directory that corresponds to the last business day. So for example the directory I would access today is 20060110 (2006 jan 10).

I am currently taking today's date and subtracting 1, putting this into a variable and then entering ftp mode, cd'ing to the directory (in the variable) and downloading the file (always same filename). This obviously does not work for weekends and holidays, as subtracing 1 on monday would give sunday. There are no directories created on weekends and holidays.

My two ideas to rectify this are 1) do something complex to figure out the last business day before entering ftp mode or 2) figure out how to CD into the newest directory, regardless of its name (the newest directory will always be the previous day).

Any ideas are appreciated here. Maybe there is a much easier way to do this that I am not considering?

Thanks in advance for any help, this is my first post.

Steve D.
Chicago, Illinois

mydate=$(date +%F | tr -d [:punct:])
let prevdate=$mydate-1
user='xxxxxxx'
pass='xxxxx'

ftp -n ftp.xxxxxxx.com << ENDEND
passive
user xxxxx xxxxx
hash
cd $prevdate
get POA_133_Position.csv
quit
ENDEND
echo "Done."
exit 0
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 01-11-2006
Registered User
 

Join Date: Dec 2005
Location: London
Posts: 222
Stumble this Post!
you can use the datecalc function posted in the following link...

http://www.unix.com/unix-dummies-questions-answers/4870-days-elapsed-between-2-dates.html#post16559

if it is monday you can subtract -2 from current day so that you will get friday's date..

But for holidays, you can maintain a config file with holiday list, deduct -1 from current day and check whether this date is in config file, if it is there, then again deduct -1 from the previously arrived date ( current day - 1 ), again check in the config file... till it is not their in the config file. I don't think this will be too complex to do..
Reply With Quote
  #3 (permalink)  
Old 01-11-2006
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,444
Stumble this Post!
Suppose this was Feb 1. You get 20060201. If you now subtract 1, you have 20060200, but there is no Feb 0. Go to our FAQ section and read the article on date arithemetic. Then switch to datecalc.
Reply With Quote
  #4 (permalink)  
Old 01-16-2006
Junior Member
 

Join Date: May 2005
Posts: 12
Stumble this Post!
According to me the best method to date calculations is taking epcoh time but for that you need a c program i dont know if there is any unix function is there
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 11:38 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0