Solved

Modified date

Posted on 1997-06-18
8
494 Views
Last Modified: 2013-12-25
I got an modified guestbookscript. In this script I need an routine that print out the date plus a number. The number should increse with +1 per time the guestbook updates per day. ex. first input 970618-1, second input 970618-2 and the next day 970719-1.

                      Need help...
0
Comment
Question by:jonasm
[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
  • 4
  • 4
8 Comments
 
LVL 5

Expert Comment

by:julio011597
ID: 1828293
You should at least state your OS and programming language.

-julio
0
 

Author Comment

by:jonasm
ID: 1828294
Using Linux and Perl
0
 
LVL 5

Accepted Solution

by:
julio011597 earned 250 total points
ID: 1828295
Here it is:

--//--
#!/usr/bin/perl

open(LOG, '+< counter.idx'); #open for update
$count = <LOG> + 1;
seek(LOG, 0, 0); #back to BOF
printf LOG $count;
close(LOG);

$year = (gmtime)[5];
$month = (gmtime)[4] + 1; #month and mday are 0 based
$mday = (gmtime)[3] + 1;

printf "$year%02d%02d-%d\n", $month, $mday, $count;

exit(0);
--//--

A few notes:

1. file 'counter.idx' must already exist, but may be empty, so you may create it with just a: touch counter.idx, then chmod 666 to make it updatable by all;

2. you may want to substitute gmtime() with localtime() to get local time instead that GMT time.

HTH, julio
0
What Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

 

Author Comment

by:jonasm
ID: 1828296
when a new day comes the count must restart at ZZXXYY-1 and count up..

/Jonas
0
 
LVL 5

Expert Comment

by:julio011597
ID: 1828297
Right, sorry...

since your program cannot be aware of a request to be the first of a day, you should set up cron to help it:

an easy way would be to put an empty - say - counter.0 file that cron could use to overwrite the counter.idx each midnight;

or, cron could delete counter.idx and touch it again;

or cron could run a script that writes a 0 in counter.idx (this needs a little modification of my first script).

I'm not on Linux, and the cron facility is quite dependent on the platform; you may want to have a look at man cron and man crontab for details.
If you have any problems, just feel free to ask more.

Rgds, julio
0
 

Author Comment

by:jonasm
ID: 1828298
Ok, thanks on this system I don't have permissions to use crontab (argh!). Is there any way to do It inside the script? use another datafile to save the date in?
I need it, really (increased the points to), I would be very happy if you could help me..

rgds

/Jonas
0
 
LVL 5

Expert Comment

by:julio011597
ID: 1828299
Yes, another way (maybe the best) is to also store the date into counter.idx:

--//--
#!/usr/bin/perl

open(LOG, '+< test.idx');
chop($oday = <LOG>);
$nday = (gmtime)[3];

if($oday ne $nday) {
  $count = "1";
  seek(LOG, 0, 0);
  printf LOG "%2d\n", $nday;
  printf LOG "%5d", $count;
}
else {
  $count = <LOG> + 1;
  seek(LOG, 0, 0);
  printf LOG "%2d\n", $oday;
  printf LOG "%5d", $count;
}
close(LOG);

$year = (gmtime)[5];
$month = (gmtime)[4] + 1;

printf "$year%02d%02d-%d\n", $month, $nday, $count;

exit(0);
--//--

This should work as expected :)
I put those printf() there, with field width specifiers, to be sure that each update completly overwrites the old data.
The count field width is set to 5: change it if you think you'll get more than 99999 requests a day.

Cheers, julio
0
 

Author Comment

by:jonasm
ID: 1828300
Exactly what I needed!,
Thanks for the fast replys!

/Jonas
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

In this tutorial I will show you how to make a simple HTML bar chart with the usage of WhizBase, If you want more information about WhizBase please read my previous articles at http://www.experts-exchange.com/ARTH_5123186.html (http://www.experts-ex…
It is a general practice to get rid of old user profiles on a computer  in a LAN environment. As I have been working with a company in a LAN environment where users move from one place to some other place at times. This will make many user profil…
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

729 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