Solved

Modified date

Posted on 1997-06-18
8
489 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
  • 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
 

Author Comment

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

/Jonas
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Introduction This tutorial will give you a fast look what you can do with WhizBase. I expect you already know how to work with HTML at least, and that you understand the basics of the internet and how the internet works. WhizBase is a server-s…
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

762 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now