Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> General/Other Stuff
Author Message
Dawg
RavenNuke(tm) Development Team


Joined: Nov 07, 2003
Posts: 910

PostPosted: Fri Jan 06, 2006 7:35 am Reply with quote

Greetings,
I have a shell script that outputs a date (amoung other things) to retrive some files from a remote server. When the new year rolled over it stopped working.

I found out the output from the script is giving me a date of 5 instead of 005. Here is the date portion of the script...

year=`date +%Y`
today=`date +%j`
day=$((today-1))

I do not know a thing about shell scripting....but I do know that the date must be in this format for the output.

001, 002, 003, 114, 365

It must have all three digits to work right.

Could someone "In the KNOW" either point me in the right direction or show me the error of my ways.

Thank You for the help!!

Dawg
 
View user's profile Send private message
Raven
Site Admin/Owner


Joined: Aug 27, 2002
Posts: 17077

PostPosted: Fri Jan 06, 2006 3:51 pm Reply with quote

The rollover of the year would not have altered the $day variable. That would have been the same. If you run this in a shell you get this:

[~]# year=`date +%Y`; today=`date +%j`; day=$((today-1))
[~]# echo $year
2006

[~]# echo $today
006

[~]# echo $day
5

$day is a calculation for yesterday and would have been formatted like this for 2005 also. I doubt that is your problem.
 
View user's profile Send private message
Dawg
PostPosted: Fri Jan 06, 2006 4:08 pm Reply with quote

Raven,
The output was coming out as a single digit like today would have been 6 and it needed to be 006 because of the name of the remote file.

I just looked at what you put more closely....I will go look at it some more...

Thank You for your time!!

Dawg
 
Raven
PostPosted: Fri Jan 06, 2006 4:12 pm Reply with quote

As you can see from the previous post, it definitely is 006 because of the %j option. I don't know.
 
Dawg
PostPosted: Fri Jan 06, 2006 7:42 pm Reply with quote

Ok...I went looking...

This is the script as written...
Code:


#!/bin/bash

year=`date +%Y`
today=`date +%j`
day=$((today-1))
archive="/maps/mysite/data"
scriptdir="/maps/mysite/scripts"

cd ${archive}/workspace

wget -r -np -nd -A file.name http://site.name/level3/husf/site/${year}/${day}/1km/pass/intermediate/

wget -r -np -nd -A file.name http://site.name/level3/husf/site/${year}/${day}/1km/pass/intermediate/


This is the script after I changed it...
Code:


#!/bin/bash

year=`date +%Y`
today=`date +%j`
day=$((today-1))
archive="/maps/mysite/data"
scriptdir="/maps/mysite/scripts"

cd ${archive}/workspace

wget -r -np -nd -A file.name http://site.name/level3/husf/site/${year}/00${day}/1km/pass/intermediate/

wget -r -np -nd -A file.name http://site.name/level3/husf/site/${year}/00${day}/1km/pass/intermediate/



Notice the 00 between year and day.

Before I changed it the resulting url would come out like this...
Code:


http://site.name/level3/husf/site/2006/6/1km/pass/intermediate/


Instead of like this....
Code:


http://site.name/level3/husf/site/2006/006/1km/pass/intermediate/


Would this be a correct fix for this?
Code:


#!/usr/bin/ksh
year=`date +%Y`
today=`date +%j`
day=`printf "%003d" $((today-1))`
wget -r -np -nd -A file.name http://site.name/level3/husf/site/${year}/${day}/1km/pass/intermediate/



As usual THANK YOU for your time!!

Dawg

PS....
IS there a good referance for this stuff some where....I can not find anything like a Manual....Just a couple sites with a little of this and a little of that?

I Like to SAVE YOU for the really hard stuff....Cause Raven Rocks Da Code!

Wink
 
Raven
PostPosted: Fri Jan 06, 2006 7:59 pm Reply with quote

But it would have been like that for any year. The %j prefixes the day with as many zeroes as it needs to be 3 long. With your code, when the day is 10 then you will have 0010. When the day is 100 then you will have 00100. Is that what you want?
 
Dawg
PostPosted: Fri Jan 06, 2006 8:34 pm Reply with quote

Yes....and that is what has me scratching my head going huh?

I would have thought so too....but it did not. The last image updates I had were for day 365.....then they stopped. One of members caught it and PMed me....I went looking....found that the output from the script called the day 5 instead of 005.

For the time being I have it fixed by simply adding 2, 0's in front of it. That will work through day 10 then I will have to kill 1 of the 0's.....then on day 100 I will have to kill the second. I would much rather just fix it....

The post above is accurate....I was careful about cut and pasting into this thread.....If you have any suggestions...I would love to hear them!

Thank You for your time!

Dawg
 
Raven
PostPosted: Fri Jan 06, 2006 10:55 pm Reply with quote

Try this instead.
Code:


#!/bin/bash

year=`date +%Y`
today=`date +%j`
day=$((today-1))

if [ "$day -lt 10" ]
then {
day=00$day
}
elif [ "$day -lt 100" ]
then {
day=0$day
}
fi

archive="/maps/mysite/data"
scriptdir="/maps/mysite/scripts"

cd ${archive}/workspace

wget -r -np -nd -A file.name http://site.name/level3/husf/site/${year}/${day}/1km/pass/intermediate/

wget -r -np -nd -A file.name http://site.name/level3/husf/site/${year}/${day}/1km/pass/intermediate/
exit 0
 
Raven
PostPosted: Mon Jan 09, 2006 8:49 pm Reply with quote

Hey Dawg! Did you ever try this?
 
Dawg
PostPosted: Mon Jan 09, 2006 9:30 pm Reply with quote

LOL.....As bad as I hate to admit....No I have not. I will be on it tomorrow though. My...ah..."Patch" will only work till Jan 9.

Too much other stuff going on in the world...I am going to send you a link vie PM.

Dawg
 
Dawg
PostPosted: Thu Jan 12, 2006 8:00 pm Reply with quote

OK....Raven.....I got it to work with a few adjustments. We had too many 0's in it...

Still have another bug I can not figure out. It started with the year rollover as well. IT is calling by default....2 days earlier instead of 1. (Instead of 011 for yesterday....it was returning 009)

I ran a date test and it returned correct....I checked the hardware time and the system time on the server and they are correct.

Sooo...I added a day to it...and it works as intended....but still makes no sence. Is there any place else I should check the time at?


#!/bin/bash
year=`date +%Y`
today=`date +%j`
day=$((today+1))
if [ "$day -lt 10" ]
then {
day=0$day
}
elif [ "$day -lt 100" ]
then {
day=$day
}
fi
archive="/maps/mysite/data"
scriptdir="/maps/mysite/scripts"

cd ${archive}/workspace

wget -r -np -nd -A theremotesite.sst.hdf Only registered users can see links on this board! Get registered or login!

wget -r -np -nd -A theremotesite.chl.hdf Only registered users can see links on this board! Get registered or login!

Here is some of the output....
Output from command /maps/xxxxxxxx/scripts/get_modis.sh 1> /dev/null ..

--20:52:14-- Only registered users can see links on this board! Get registered or login!
=> `index.html'
Resolving xxxxxxxx.edu... xxxxxxxxxx
Connecting to xxxxxxxxxx.edu[xxxxxxxxxx]:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 7,872 [text/html]
 
Display posts from previous:       
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> General/Other Stuff

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2007 phpBB Group
All times are GMT - 6 Hours
 
Forums ©