The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
Google UNIX.COM


High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
change wc -l francis_tom Shell Programming and Scripting 1 04-14-2008 10:02 AM
change 43% to 43.5 nortypig Shell Programming and Scripting 2 08-20-2006 12:55 AM
Want to change my Name Awadhesh Post Here to Contact Site Administrators and Moderators 2 10-04-2005 05:54 AM
UID Change mcateriny AIX 4 10-06-2003 09:02 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1  
Old 07-08-2008
Registered User
 

Join Date: Jul 2008
Posts: 2
Change FileHandle

Hello,

I currently have a system that is running and writing to a log file. Every month I run a rollLogs script that moves this file to a different location and creates a new file in the original location. The service that is writing to this log is running when i run this script and it still has its FileHandle pointing to the old file. The program continues to write to the moved file instead of the new file.

Is there a way to redirect the output of a file to the newly created log file without having to restart the program?

Thanks for the help
Andy
Reply With Quote
Forum Sponsor
  #2  
Old 07-08-2008
Registered User
 

Join Date: Oct 2007
Location: USA
Posts: 567
dup2()

See the dup2() manpage...assuming it's a C program

Code:
dup2(fd_of_new_file, fd_of_old_file);
Reply With Quote
  #3  
Old 07-08-2008
Registered User
 

Join Date: Jul 2008
Posts: 2
Thanks for the response shamrock. I looked into it but was still unable to get this working. Im using PERL and the POSIX module has a dup2() that is suppose to mimic the c function.

Is there any easy way to determine the File Desc of the old log file? I was hoping i could just enter the path of the oldfile and the path of the new and the function would take care of the rest.

Thanks again for the help
Reply With Quote
  #4  
Old 07-09-2008
Registered User
 

Join Date: Sep 2006
Posts: 7
I think you can do your job in another way.
Copy old file to a new location, after that empty the original file.
But there are chances of data loss, if the service writes log between copying and emptying.

Last edited by mika; 07-09-2008 at 07:15 AM.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 03:15 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0