[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

PERL Time problem

Posted on 2004-10-25
9
Medium Priority
?
189 Views
Last Modified: 2010-03-05
Hi All,

I have a website where the time is displayed, and it works just fine.  We have a server in our office, where we do our updates via a web interface.  When we are happy with what every thing looks like, we click a button on the interface, it runs a perl script, and ftp's files over to the server at our isp/web host, to our main website.  This all works fine.  The server in our office is getting very old, so I moved all of the files from it to a newer server, corrected the addressing inthe perl scripts, installed everything (i Think!) that is necessary, etc.  When I try to do the same process on the newer server, it ftp's all of the files it should, however that date on our website will revert back to January 1, 1970.  I'm familiar with how PERL figures out date and time, counting non leap seconds from 1970 etc.  My question is why is this all of the sudden changing the dates?  All we are doing is ftping (using Net::ftp) text files.  Has anyone ever encountered this problem?

Thanks

Brian
0
Comment
Question by:wxman1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
9 Comments
 
LVL 16

Expert Comment

by:manav_mathur
ID: 12411829
Brian,
One thing that you have not mentioned is how are you displaying time on your website.
Are you using CGI scripting or some other method......

Manav
0
 

Author Comment

by:wxman1
ID: 12411897
Manav,

It is perl scripting using CGI.

Brian
0
 
LVL 16

Accepted Solution

by:
manav_mathur earned 400 total points
ID: 12412060
okay!!

And you are using localtime to get the updated time.
Two of the stupidest suggestions that I can come with are

1) Have you by mistake tweaked with the actual code while moving servers.
2) Does the server have the time set??

Can you tell me what version of PERL you are using??

Manav
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:wxman1
ID: 12412130
Manav,

1)  No I haven't touched the code, except for changing the addressing as the directory structure on the new server is slightly different.

2)  The older server is set for the current time.  The new server is set at GMT time, as most of our work is done in GMT.  The webserver, where are actual website resides, I am not sure.

There is a difference between the versions of PERL, the older server is running 5.22, and the newer one is running 5.8 (Active States version).  I'm not sure about the webserver hosted at our isp.

Brian
0
 
LVL 16

Expert Comment

by:manav_mathur
ID: 12412256
If possible, can I see the PERL script which you run to ftp the files.

One thing that seems is that there's a version conflict somewhere. Your webserver has no role to play in this error, because Im assuming that the PERL script used to FTP files also inserts the last updated date somewhere in the webpage. SO I guess having a look at it might solve the problem

one more thing, you can go thru the docs for localtime. Even I have Active state 5.6.

Manav
0
 

Author Comment

by:wxman1
ID: 12412469
Script is below:
###################
use CGI;
use Net::FTP;

require "c:/Inetpub/wwwroot/oldweb/www.weather.bm/cgi-bin/weather-util.pl";

$LOCATION="REMOTE";

chdir("$HOMEDIR/cgi-bin");

$in=new CGI;

# Make sure that data was posted (ie. CGI was started properly for an update).
if ($in->param("u") eq "1") {

   # The following actions always take place, whether CGI run on main server or remotely (at BWS)...
   print "Location: /update/complete.html\n\n";

   if (opendir(DIR,".")) {
      @files=readdir(DIR);
      closedir(DIR);

      # Mark "old" files for deletion - try to be a bit cleaner. :^)
      foreach $file(@files) {
         if ($file=~/^cur-[^\.]+\.txt$/) { $Delete{$file}=1; }
         print $file."\n";
      }

      # Copy new files to new names.
      foreach $file(@files) {
         if ($file=~/^tmp-([^\.]+)\.txt$/) {
            $name=$1;
            system("copy $file cur-$name.txt");
            $Delete{"cur-$name.txt"}=0;
            print "Copied $file to cur-$name.txt\n";

            # Make a record of files to keep (and where to put on main server), if FTPing them later is needed.
            $Keep{"cur-$name.txt"}="";
         }
      }

      # Delete unneeded files.
      foreach $file(keys %Delete) {
         if ($Delete{$file}) {
            unlink($file);
            print "Deleted $file.\n";
         }
      }
}

if ($LOCATION eq "REMOTE") {

      # Remote machine must also FTP all the updated, current TXT files it has to the server.
      # (all files that have a cur-xxx.txt and tmp-xxx.txt versions)
      SendFTP("i.p.address","username","password",%Keep);
   }

else {
   print "Content-type: text/html\n\n";
   print <<ENDTEXT;
<HTML>
<HEAD>
<TITLE>Weather Page Update</TITLE>
</HEAD>
<BODY bgcolor=#e3fff2 text=#000000 link=#0a50a1 vlink=#0a50a1 background="/back/coral-thin.gif">
<FONT face="Arial, Geneva, Helvetica, San-serif">
<TABLE border=0>
<TR><TD valign=top width=220><IMG src="/blank.gif" width=220 height=1></TD>
    <TD>
    <B>Update Weather Page.</B><P>

    The weather pages have <B>not</B> been updated with the files from the preview site - please do not bookmark this page.
   
    <P><A href="/">Go to main weather page</A><BR>
    <A href="/update/">Go to preview area</A></P>
    </TD>
</TR>
</TABLE>
</FONT>
</BODY>
</HTML>
ENDTEXT
}
exit(0);

sub SendFTP {
# Performs FTP Upload functions.

   my($host,$user,$pass,%files)=@_;
   my($dir,$file,$ext,$mode,$ftp);

   my(%ASCII)=("TXT"=>1,"HTML"=>1,"SHTML"=>1,"HTM"=>1,"PL"=>1,"PM"=>1);

   $mode="UNKNOWN";
   if ($ftp = Net::FTP->new($host)) {
      if ($ftp->login($user,$pass)) {
         
         foreach $file(sort keys %files) {

            # Change to appropriate directory.
            $dir=$files{$file};
            if ($dir ne "") { $ftp->cwd($dir); }

            # Change mode if necessary.
            if ($file=~/\.(.+)$/) { $ext=uc($1); } else { $ext="none"; }
            if (($ASCII{$ext})&&($mode ne "ASCII")) { $ftp->ascii(); $mode="ASCII"; }
            elsif ((!($ASCII{$ext}))&&($mode ne "BINARY")) { $ftp->binary(); $mode="BINARY"; }

            # Send file.
            $ftp->put($file);
         }
      }
      $ftp->quit;
      return 1;
   }
   return 0;
}
0
 

Author Comment

by:wxman1
ID: 12412704
sorry, forgot a line of code

After :
if ($LOCATION eq "REMOTE") {

      # Remote machine must also FTP all the updated, current TXT files it has to the server.
      # (all files that have a cur-xxx.txt and tmp-xxx.txt versions)
      SendFTP("i.p.address","username","password",%Keep);
   }


should be:

 # Machines should also FTP graphics and HTML for tracking maps if needed.
   %Keep=();
   foreach $file(@files) {
      if (($file=~/^map-\d+-\d+.png$/)||($file=~/^map-\d+-bg.png$/)||($file=~/^map-\d+-plot.html$/)) { $Keep{$file}=""; }
   }
0
 

Author Comment

by:wxman1
ID: 12413882
Manav,

Well I figured out what my problem was, the Net::ftp was not using passive mode!  I don't know why that was causing the problems, but I have corrected it and it now works.  Since you were kind enough to try and help, the points are yours.

Cheers,

Brian
0
 
LVL 16

Expert Comment

by:manav_mathur
ID: 12419149
Great!!

Sorry couldnt help you more last time. It was 10 in the night and I had to leave my office.

Manav
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question