The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Capture Shell Script Output To A File rajan_san Shell Programming and Scripting 4 01-13-2009 01:30 PM
Script to capture new lines in a file and copy it to new file fara_aris Shell Programming and Scripting 0 05-27-2008 10:11 PM
shell script to search content of file with timestamps in the directory psychobeauty Shell Programming and Scripting 10 04-21-2008 05:37 AM
shell script to edit the content of a file tiger99 Shell Programming and Scripting 3 01-31-2008 04:43 AM
file content to standard output from a script bryan Shell Programming and Scripting 4 06-30-2006 12:48 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 02-11-2009
bjawasa bjawasa is offline
Registered User
  
 

Join Date: Feb 2009
Posts: 3
script to capture content of deleted file

I need to capture the content of a file before its being deleted. This file gets deleted immediately after it is created.

I use the below shell command in the command prompt, but I'm not getting the desired result.

bash-3.00# while true; do cat file* > tempfile; done;

What I'm trying here is to capture the content of "file*" and output it to tempfile. The content of "file*" gets overwritten in the process and I need to see the latest content.

If I don't try to output it in 'tempfile' I could see the content of the file in the command line -> bash-3.00# while true; do cat file*; done;

Any idea if this can be done in a better way?
  #2 (permalink)  
Old 02-11-2009
hari_anj hari_anj is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 6
Please try the following command

while true; do cat file* >> tempfile 2>/dev/null; done;
  #3 (permalink)  
Old 02-11-2009
bjawasa bjawasa is offline
Registered User
  
 

Join Date: Feb 2009
Posts: 3
Thanks Hari for your quick reply. But the command that you suggested appended the tempfile. As I mentioned "file*" is being overwritten and what I need to capture is the latest content of 'file*' before it is deleted, without being appended to tempfile.

The command that I used earlier -> while true; do cat file* > tempfile; done; or
while true; do cat file* > tempfile 2>/dev/null; done;
doesn't write anything into tempfile.
  #4 (permalink)  
Old 02-11-2009
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,293
For what I'm understanding you have 1 file, why do you use "file*" in your command?
What is the name of the file and why don't you use cp instead of cat?

Regards
  #5 (permalink)  
Old 02-11-2009
bjawasa bjawasa is offline
Registered User
  
 

Join Date: Feb 2009
Posts: 3
This file (file*) is being created by an application, and the last part of the filename is generated by the application with a random name.

The main intention is to capture the last written data in this file (file*). This file is FTPed to a remote server and immediately after it is FTPed, it is deleted in the Host Server, and I need to capture what data is written just before it got deleted.
  #6 (permalink)  
Old 02-11-2009
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,293
If you have just one file you don't have to use a loop, cat file* > tempfile should be sufficient assuming you want to copy the whole contents of your file.

Regards
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 06:49 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0