473,382 Members | 1,290 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Saving a log without deleting the previous logs?

Thekid
145 100+
Hi, how can I get this Perl script to save the log without automatically deleting the previous logs? It only saves the new one:

Expand|Select|Wrap|Line Numbers
  1. print '> Hello Kid ' . $ENV{'USER'} . '.' . "\n";
  2. open(PLANNERLOG, '>/var/log/planner');
  3. print '> Please enter your log data here, end with a "." on a single
  4. line.' . "\n";
  5. my $LogText;
  6. print '> ';
  7. while () {
  8.        unless ($_ ne '.' . "\n") {
  9.                last;
  10.        }
  11.        $LogText .= $_;
  12.        print '> ';
  13. }
  14.  
  15. print '> Log is being saved to /var/log/planner' . "\n";
  16. $DateTime = localtime();
  17. print PLANNERLOG ' -- START OF LOG -- ' . "\n";
  18. print PLANNERLOG 'Date/Time: ' . $DateTime . "\n";
  19. print PLANNERLOG 'Log      : ' . $LogText;
  20. print PLANNERLOG ' -- END OF LOG -- ' . "\n";
  21. die('> Log saved! Now exiting.' . "\n");
  22.  
  23.  
Aug 26 '08 #1
4 1271
eWish
971 Expert 512MB
Are you wanting to append the file?

perlfaq5 - "How come when I open a file read-write it wipes it out?"

--Kevin
Aug 26 '08 #2
KevinADC
4,059 Expert 2GB
Read the link eWish posted. What you want is to open the file in append /create mode:

Expand|Select|Wrap|Line Numbers
  1. open(PLANNERLOG, '>>', '/var/log/planner');
note the double >> instead of single > like you had it.
Aug 26 '08 #3
Thekid
145 100+
Ahh.....thanks! It was the double '>>' that I needed!
Aug 26 '08 #4
numberwhun
3,509 Expert Mod 2GB
Ahh.....thanks! It was the double '>>' that I needed!
My personal suggestion would be to add a date/time stamp on to the file, or even just a date stamp (for one file per day). You can do a check to see if the date matches and if not, create a new log for that day. Its a little more coding, sure, but in my opinion, worth it.

Regards,

Jeff
Aug 26 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: marfi95 | last post by:
I'm automating a piece of my app to allow my customers to send me a copy of their event logs (for diagnostics) on demand just through the click of a button. I know I can use the...
7
by: ehendrikd | last post by:
hi all i need some clarification on how the php session work in relation to cookies. we have a web site where users need to log in. a few of our users were having troubles with their browser...
3
by: vb | last post by:
I need to delete records from several large tables - 1 million plus rows. Some of these tables have nested foreign key relationships. When I perform the delete statements, it can take forever as...
8
by: shandra | last post by:
I have a file I need to delete or truncate. I tried using the KILL command in VB6. I tried using the file.delete command in VB.net. I tried manually deleting, renaming, and copying over the...
1
by: marfi95 | last post by:
I'm automating a piece of my app to allow my customers to send me a copy of their event logs (for diagnostics) on demand just through the click of a button. I know I can use the...
8
by: Joey Chömpff | last post by:
L.S., Hello is there a way to implement 2-way databinding without using the datasources from dotnet 2.0. Why would you ask? Now that's simple. I've created an object model with BusinessObjects...
1
by: Jim Andersen | last post by:
Hi, I want to make a backup of some data from an SQL server. The backup should be saved as an Excell file (or similar, csv or xml...) So I create a datatable and select the data from SQL server...
14
by: Simon | last post by:
I'm trying to write a little function to save data. Basically I have a large 2d array of structs, so I'm going to have to call the save function once per struct in the array. I'd like to save the...
3
by: Andy_Khosravi | last post by:
I'm having a problem with an entry form on one of my applications. It would appear that the save action is sometimes not working, and is generating no error when it fails. I'm hoping one of you may...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.