Solved

Modified date

Posted on 1997-06-18
8
493 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
MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

 

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

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
PS call executable Files in Order 4 31
VBS script  to map network printers to all users. 3 22
PowerShell and cisco ios 3 48
add if statement powershell 8 25
In this tutorial I will show you how to provide a dynamic RTF document on your website generated with data from your database. For this tutorial you will need Microsoft Word or WordPad, WhizBase and Microsoft Access. In this tutorial I will show …
Batch, VBS, and scripts in general are incredibly useful for repetitive tasks.  Some tasks can take a while to complete and it can be annoying to check back only to discover that your script finished 5 minutes ago.  Some scripts may complete nearly …
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 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…

696 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