Solved

Modified date

Posted on 1997-06-18
8
491 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Need to learn promise API 2 51
Disk Ram Peak 1 43
ICACL switch help. How to include current folder 2 44
Quickest way to query Windows Event ID from a Linux Device 3 34
If you get a (Blue Screen of Death), your system writes a small file called a minidump. Your first step is to make certain your computer is setup to record memory dumps. Right click My Computer, choose properties. Click on the advanced tab, an…
Recently I have been answering a lot of questions like this in IT forums that I frequent. The question posed is usually something along the lines of "We have software X installed and need to uninstall it for reason Y" or some other variant of the sa…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

809 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