Better to Delete or Overwrite


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Better to Delete or Overwrite
# 1  
Old 03-01-2013
Better to Delete or Overwrite

Hello All,

I had just a question about my Bash Script I'm currently writing.

The script I have writes some text to a output file. After I write to the output file I send the file to another server to do
some stuff with it.

After the file sends in the script, I don't need the output/txt File anymore. So is it better to, after I send the file of course, delete
the file or should I just leave it and overwrite it the next time I run the script?

The script will be run automatically using cron or automatically using remote means from another server. But basically
it will be executed a couple times an hour (*maybe 2 or 3 times)...

So is it "bad" to delete the file from within the script when it has finished executing? I just didn't want the file to be appended
to somehow and then I'd get incorrect data, if ya know what I mean..?


Any thoughts would be much appreciated..!


Thanks in Advance,
Matt
# 2  
Old 03-01-2013
If you have confirmed that the file was transferred successfully to the remote host, there is no need to continue consuming the disk space occupied by the file. It is just good practice to remove temporary files when they're no longer needed.

But, if there is a chance that you'll need to resend the file or look at the data that was sent to the remote host before cron kicks off the next job, keep it.
This User Gave Thanks to Don Cragun For This Post:
# 3  
Old 03-01-2013
Hey Don, thanks for the reply!

Cool, that's kinda what I was thinking, but i wasn't sure if removing the file a few times an hour would be better or worse
then to just overwrite it each time...

But, that should be fine. I'll set something up at the very end of my script to remove the file after I confirm it was sent.

Thanks Again Don for the reply!


Thanks,
Matt
# 4  
Old 03-01-2013
Creating a guessable tmp file in a public area like /tmp is a security risk.
It is safer to leave such a file, so the next time it is overwritten not created.
There a methods for a safer tmp file, see
Code:
man mktemp

Most safe is to avoid a tmp file. E.g. by using | and (sub shell).
# 5  
Old 03-01-2013
Hey MadeInGermany, thanks for the reply.

The file won't be in a public place. It is being saved in it's OWN directory, and no one has access to the directory except for root...

Don't know if that makes a difference in your eyes, but that's how its setup at the moment.


Thanks Again for the reply,
Matt
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Overwrite file every day

Hi Friends, I have written a script to capture system performance every hour and redirected to output file. How to overwrite the file every next day? Thanks Suresh (4 Replies)
Discussion started by: suresh3566
4 Replies

2. Shell Programming and Scripting

overwrite only if both files are the same size

Dear users, I've been looking for a way to overwrite files only if both have the same size, how could I do this? any help is very appreciated. Best regards, Gery (5 Replies)
Discussion started by: Gery
5 Replies

3. UNIX for Advanced & Expert Users

linux overwrite directory

How do you overwrite a directory with another directory? I know you can delete your directory then copy your directory over, but I would think there would be a way to do this in one step. (5 Replies)
Discussion started by: cokedude
5 Replies

4. UNIX for Dummies Questions & Answers

overwrite problem

my script is: awk '...mycode...' file1.txt > file2.txt and i want to overwrite file2.txt eachtime I run this script. but it says:File exists! :( I have tried awk '...mycode...' file1.txt >| file2.txt but it again says:Missing name for redirect! :confused::confused: what is this? (2 Replies)
Discussion started by: gc_sw
2 Replies

5. Shell Programming and Scripting

Unable to overwrite but can delete file

I'm debugging a ksh script written by someone else that does the following: It runs a command and redirects stdout to a file called dberror that already exists using ">". This command fails with the following error: The file access permissions do not allow the specified action. dberror:... (1 Reply)
Discussion started by: savage66
1 Replies

6. Shell Programming and Scripting

Files overwrite in awk

Hi guys, I checked the knowledge base before posting this question. is there any way by which you can ALWAYS ALLOW file overwrite in AWK?. i.e. an option similar to noclobber in Korn shell. I don't to check for files existence and remove them. (1 Reply)
Discussion started by: Moon Noon
1 Replies

7. Shell Programming and Scripting

Overwrite & Delete in Text File

Dear All, I have text file like this: Header Record 1 Record 2 ....... Record n Tail This line of code : awk '{ if ( NR == 1 ) { head=substr($0,1,300);} else { last = substr($0,1,300);}END{printf "Header is : %-300s Trailer is : %-300s\n", head, last}' filename converted Header... (11 Replies)
Discussion started by: 33junaid
11 Replies

8. UNIX for Dummies Questions & Answers

overwrite problem

Hi im using the following to copy a file to a directory, the user being prompted to overwrite if the file already exists in that directory, cp -i myfile /home/brief/bin2 but this reveals the path of the directory when being prompted to overwrite (below) cp: overwrite... (2 Replies)
Discussion started by: ali999
2 Replies

9. UNIX for Dummies Questions & Answers

Overwrite

if i want to pipe output to a file, say, cat abc.dat > abc.txt, how do i make it replace the existing file? (9 Replies)
Discussion started by: Duckman
9 Replies
Login or Register to Ask a Question