remove temporary file ?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting remove temporary file ?
# 1  
Old 11-23-2007
Error remove temporary file ?

Hi all,

In the script I am creating a temporary file with process id as temp.txt.$$

I want to remove this tomporary file first from the current directory when i'll run the same script next time.
Note: Every time when the script executes then it has unique process id and it'll create a unique temporary file. $$ shows the process id.

How to do that please let me know.

Thnks in advance.

Smilie
# 2  
Old 11-23-2007
Quote:
Originally Posted by varungupta
Hi all,

In the script I am creating a temporary file with process id as temp.txt.$$

I want to remove this tomporary file first from the current directory when i'll run the same script next time.
Note: Every time when the script executes then it has unique process id and it'll create a unique temporary file. $$ shows the process id.

How to do that please let me know.

Thnks in advance.

Smilie


Hi,

rm temp.txt.*

This will remove the temporary file.

Regards,
Chella
# 3  
Old 11-23-2007
If the file is truely a temporary file then delete it when your script finishes....

Code:
#!/bin/sh

cleanup()
{
    for d in $LAUNDRY_LIST
    do
        if test -f "$d"
        then
            rm "$d"
        fi
    done
}

trap cleanup 0

blah >my.tmp.$$

LAUNDRY_LIST="$LAUNDRY_LIST my.tmp.$$"

dostuff

do more stuff

# 4  
Old 11-23-2007
Thanks buddy...

Can i put this in Conditional statement ?

As i used following :
if [ -f tempdspmq.txt.* ] then
rm tempdspmq.txt.* ;
fi

But its not working...Please let me know, any solution to this.
Smilie


Thnks porter, I have checked your script too. Thnks !!
Smilie
# 5  
Old 11-23-2007
Quote:
Originally Posted by varungupta
Thanks buddy...

Can i put this in Conditional statement ?

As i used following :
if [ -f tempdspmq.txt.* ] then
rm tempdspmq.txt.* ;
fi

But its not working...Please let me know, any solution to this.
Smilie
Why not

Code:
rm -f "tempdspmq.txt.*" 2> /dev/null

As such, porter's approach is more elegant.
# 6  
Old 11-23-2007
Quote:
Originally Posted by vino
Why not

Code:
rm -f "tempdspmq.txt.*" 2> /dev/null

As such, porter's approach is more elegant.
Thanks Vino.

I liked this Optimized approach !! Thanks Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Storing a Temporary File Using C

How would someone save a file such as /etc/vpnc/test.conf locally into a temp file, so it can be queried? So for example if I used rsync to copy this file locally, how would I add that to a temp_file variable and discard it using unlink? #include <stdio.h> #include "error.h" ... (15 Replies)
Discussion started by: metallica1973
15 Replies

2. UNIX for Dummies Questions & Answers

Mailx - temporary mail message file: No such file or directory

How would I go about resolving this error temporary mail message file: No such file or directory Can anybody tell me where the default location is for the temporary mail message file is for mailx? It appears that it doesn't exist. Thanks (1 Reply)
Discussion started by: joen
1 Replies

3. Shell Programming and Scripting

How to remove a temporary file inside gawk

Hi- How can I make the temporary file 0 byte , created inside gawk. I am using system("rm -f temp_orders"); It seems system command is deleting file permanently and I am not able to execute below statement. print ORD_HEAD_FULL >> cFILE; (cFile is temp_orders) (2 Replies)
Discussion started by: ashish_kaithi
2 Replies

4. Shell Programming and Scripting

How to remove the first line of a file without using any temporary file

I want remove first line of the file without using any temporary file. Everything should be done in the original file itself since I don't any file creation access whereas I have modify access. It would be great if somebody help in this regard ASAP . Thanks in Advance. Kishore:mad: (1 Reply)
Discussion started by: tvbhkishore
1 Replies

5. UNIX for Dummies Questions & Answers

mailx command - Temporary mail file: permission denied

Hi , I am facing a problem with respect to mailx command in unix . Earlier it was working fine and I am facing this issue only from last week . I used mailx command and I am getting a error message as follows : temporary mail file: Permission denied If I run mailx command from... (2 Replies)
Discussion started by: deepav1985
2 Replies

6. Shell Programming and Scripting

temporary file to file then move to directory

Ok in my bash script i have 5 options to create a simple html script. I need to create a temporary file and whatever the user types will be stored in that file using html codes. And then I have another option in which that temporary file will be moved to the public_html directory in which the user... (19 Replies)
Discussion started by: gangsta
19 Replies

7. Shell Programming and Scripting

Perl : how to modify a file without generate a temporary file

Hi All, I have a file like below, how can i insert one line after line 1 without using a temporary file in perl? line 1 line 2 line 3 expected result line 1 new line <---insert here line 2 line 3 (2 Replies)
Discussion started by: summer_cherry
2 Replies

8. UNIX for Dummies Questions & Answers

Ping temporary off and down

We have a sun server which when pinged temporarily responds and sometimes dont respond. Which problems may it is facing? (1 Reply)
Discussion started by: eelinker
1 Replies

9. AIX

error : pg: 0652-122 Cannot write to the temporary file

Hi All, I'm getting this error when I use "pg". /tmp is not full and the permission is correct. root@axappk01::/home> hostname|pg pg: 0652-122 Cannot write to the temporary file. Please advise. (6 Replies)
Discussion started by: fara_aris
6 Replies

10. Ubuntu

Avoid creating temporary files on editing a file in Ubuntu

Hi, My ubuntu flavor always create temporary files having filename followed by ~ on editing. For eg: if I am editing a file called "sip.c", automatically a temporary (bkup) file is getting created with the name "sip.c~". How to avoid this file creation? (7 Replies)
Discussion started by: royalibrahim
7 Replies
Login or Register to Ask a Question