script to capture content of deleted file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting script to capture content of deleted file
# 1  
Old 02-11-2009
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  
Old 02-11-2009
Please try the following command

while true; do cat file* >> tempfile 2>/dev/null; done;
# 3  
Old 02-11-2009
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  
Old 02-11-2009
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  
Old 02-11-2009
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  
Old 02-11-2009
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
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help on script to capture info on log file for a particular time frame

Hi I have a system running uname -a Linux cmovel-db01 2.6.32-38-server #83-Ubuntu SMP Wed Jan 4 11:26:59 UTC 2012 x86_64 GNU/Linux I would like to capture the contents of /var/log/syslog from 11:00AM to 11:30AM and sent to this info via email. I was thinking in set a cron entry at that... (2 Replies)
Discussion started by: fretagi
2 Replies

2. Shell Programming and Scripting

Script to capture string in a log file

Dear all, I have a log file to be analysed. this log file contains vaiours lines of code starting with date timestamp. if my search string is exception then that resepective log statement starting from the date is required. example: 2014/10/01 16:14:44.459|>=|E|X|19202496|2832|... (5 Replies)
Discussion started by: shravee
5 Replies

3. Shell Programming and Scripting

Shell Script to Dynamically Extract file content based on Parameters from a pdf file

Hi Guru's, I am new to shell scripting. I have a unique requirement: The system generates a single pdf(/tmp/ABC.pdf) file with Invoices for Multiple Customers, the format is something like this: Page1 >> Customer 1 >>Invoice1 + invoice 2 >> Page1 end Page2 >> Customer 2 >>Invoice 3 + Invoice 4... (3 Replies)
Discussion started by: DIps
3 Replies

4. Shell Programming and Scripting

Shell script to monitor new file in a directory and mail the file content

Hi I am looking for a help in designing a bash script on linux which can do below:- 1) Look in a specific directory for any new files 2) Mail the content of the new file Appreciate any help Regards Neha (5 Replies)
Discussion started by: neha0785
5 Replies

5. Shell Programming and Scripting

set -x within script and capture as a file

Okay, I've been working on a script for providing information on the progress of a backgrounded ditto command. Thanks to google and a lot of searching I've resolved all but one very odd error. At this point, I want to use xtrace (set -x) to try to uncover the issue. I have found several examples... (2 Replies)
Discussion started by: reid
2 Replies

6. Shell Programming and Scripting

AWK Script to Capture Each Line of File As Variable

Hi All, I'm working on creating a parts database. I currently have access to a manufacturer database in HTML and am working on moving all of the data into a MySQL db. I have created a sed script that strips out the HTML and unnecessary info and separates the script into one line for each field.... (3 Replies)
Discussion started by: dkr
3 Replies

7. Shell Programming and Scripting

looking for help on script to capture file permission.

Hi Guys, I'm a DBA and need help on shell scripting. My Oracle Database is sitting on HP-UX machine. Anyone has a script that can spool out permission of all oracle binary files in the below directory: /opt/ora10g/oracle/ Format to be spooled out : chmod <exisiting permission> filename... (10 Replies)
Discussion started by: ciaciachew
10 Replies

8. Shell Programming and Scripting

shl script capture a file

need to be able to capture a file with the following conditions: The filenames are, for example, 3526_332840.dat, where 3526 is constant, and 332840 is a sequential number which is always a couple hundred greater than the previous day's file. I want to be able to change this script to acoomplish... (1 Reply)
Discussion started by: rechever
1 Replies

9. Shell Programming and Scripting

Capture Shell Script Output To A File

Hi, I am running a shell script called dbProcess.sh which performs shutdown and startup of various Oracle instances we have.At the time of execution the script produces the following output to the command line window $./dbProcess.sh stop #### Run Details ###### Hostname : server-hop-1... (4 Replies)
Discussion started by: rajan_san
4 Replies

10. Shell Programming and Scripting

Script to capture new lines in a file and copy it to new file

Hi All, I have a file that gives me new line/output every 5 minutes. I need to create a script that capture new line/output besides "IN CRON_STATUS", in this case the new output is "begin ------ cron_status.sh - -----------". I want this script to capture the line starting from "begin ------... (0 Replies)
Discussion started by: fara_aris
0 Replies
Login or Register to Ask a Question