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
error : pg: 0652-122 Cannot write to the temporary file fara_aris AIX 6 05-28-2008 10:42 PM
Disposable Temporary E-mail 1.4.0 (Default branch) iBot Software Releases - RSS News 0 04-13-2008 01:30 AM
Avoid creating temporary files on editing a file in Ubuntu royalibrahim Ubuntu 7 11-17-2007 05:57 AM
Removing temporary alias veccinho AIX 1 09-04-2007 05:19 AM
solve temporary root password go3mon Shell Programming and Scripting 1 06-23-2005 08:09 AM

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 11-23-2007
varungupta varungupta is offline
Registered User
  
 

Join Date: Feb 2007
Location: Pune, Dehradun (INDIA), Michigan(US)
Posts: 206
Exclamation 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.

  #2 (permalink)  
Old 11-23-2007
chella chella is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 75
Quote:
Originally Posted by varungupta View Post
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.



Hi,

rm temp.txt.*

This will remove the temporary file.

Regards,
Chella
  #3 (permalink)  
Old 11-23-2007
porter porter is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2007
Posts: 2,965
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 (permalink)  
Old 11-23-2007
varungupta varungupta is offline
Registered User
  
 

Join Date: Feb 2007
Location: Pune, Dehradun (INDIA), Michigan(US)
Posts: 206
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.



Thnks porter, I have checked your script too. Thnks !!
  #5 (permalink)  
Old 11-23-2007
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,796
Quote:
Originally Posted by varungupta View Post
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.
Why not

Code:
rm -f "tempdspmq.txt.*" 2> /dev/null
As such, porter's approach is more elegant.
  #6 (permalink)  
Old 11-23-2007
varungupta varungupta is offline
Registered User
  
 

Join Date: Feb 2007
Location: Pune, Dehradun (INDIA), Michigan(US)
Posts: 206
Quote:
Originally Posted by vino View Post
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
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 04:53 PM.


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