How to extract the day of the year and use that info to copy a file remotely


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to extract the day of the year and use that info to copy a file remotely
# 1  
Old 09-23-2011
How to extract the day of the year and use that info to copy a file remotely

Hello,
Thank you in advance for helping a newbie who is having great trouble with this simple task.

I'm allowed to copy one file remotely each night due to bandwidth restrictions.
A new file gets generated once a day, and I need to copy the previous day's file.

Here is what I'd like to do:
write a program that gets fired off from a listing in the crontab file:
1) detect/calculate the day of the year (example: Feb 28 = day 59).
2) Append the day of year onto a file name (example: big_file_169.data)
3) Do a remote copy using scp or rsync or something.

and that's it.
I'm using a bash shell but can switch to a tshell if that helps.

Thanks again in advance.
Tom
# 2  
Old 09-23-2011
About your first question:
- You can use Python, Ruby, Perl with CPAN DateTime module or GNU date with "%j" specifier - simple.
- Or you can use pure Perl or bash date arithmetic functions (search them in Google) - harder.
- Or you can just use date with "+%d-%m-%Y" specifier - very simple and a standard solution for this kind of problems.
Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Julian day to dates in YEAR-MONTH-DAY

hello, I have many files called day001, day002, day003 and I want to rename them by day20070101, day20070102, etc. I need to do it for several years and leap years as well. What is the best way to do it ? Thank you. (1 Reply)
Discussion started by: Ggg
1 Replies

2. UNIX for Dummies Questions & Answers

Sort file by day of year

Hello, It's a shame to not be able to do what I need, but I am sure you will : Here is what I have in my log file : New File: 95106 Jun 6 48 TAG__KSO__2012092_0.TAB New File: 95106 Mar 26 48 TAG__KSM__2012020_0.TAB New File: 95106 Mar 26 48 TAG__KSO__2012020_0.TAB New File: 95106 May... (3 Replies)
Discussion started by: Aswex
3 Replies

3. UNIX for Advanced & Expert Users

How to extract info from text file between the tags

Hi, I have a text file with member information... B]Name is in H1 tag Title is in H2 tag Email is in <a id="ctl00_ContentPlaceHolder3_repeaterItems_ctl01_lbnEmailMe" href="javascript:__doPostBack('ctl00$ContentPlaceHolder3$repeaterItems$ctl01$lbnEmailMe','')">someone@company.com</a> Location:... (6 Replies)
Discussion started by: igurv
6 Replies

4. Shell Programming and Scripting

how to extract the info in the tag from a xml file

Hi All, Do anyone of you have any idea how to extract each<info> tag to each different file. I have 1000 raw files, which come in every 15 mins.( I am using bash) I have tried my script as below, but it took hours to finish, which is inefficiency. perl -n -e '/^<info>/ and open FH,">file".$n++;... (2 Replies)
Discussion started by: natalie23
2 Replies

5. Shell Programming and Scripting

Get day of year

Hi, I wold like to know the day of year from a date in input. I know to get this from sysate with date +%j But from a date in input? :confused: Thanks (2 Replies)
Discussion started by: pinguc
2 Replies

6. Shell Programming and Scripting

Concatenating Files In A Year/Month/Day File Structure

Hi Im trying to concatenate a specific file from each day in a year/month/day folder structure using Bash or equivalent. The file structure ends up like this: 2009/01/01/products 2009/01/02/products .... 2009/12/31/products The file I need is in products everyday and I need the script to... (3 Replies)
Discussion started by: Grizzly
3 Replies

7. Shell Programming and Scripting

how to extract info from a file using awk

Dear all I have a file call interfaces.txt Filename: interfaces.txt How can I extract the information at below? ABC_DB_001 hostname1 20901 ABC_DB_002 hostname2 20903 ABC_DB_003 hostname3 20905 Currently I am using a very stupid method grep ^ABC interfaces.txt > name.txt grep... (3 Replies)
Discussion started by: on9west
3 Replies
Login or Register to Ask a Question