![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| 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 |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
|||
|
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 |
| Forum Sponsor | ||
|
|
|
|||
|
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.. |