The UNIX and Linux Forums  


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
performing cleanup when a job finishes ChicagoBlues Shell Programming and Scripting 4 03-06-2008 12:41 PM
awk/sed/ksh script to cleanup /etc/group file pdtak Shell Programming and Scripting 6 02-28-2008 03:33 AM
pthread_cleanup_push/pop - cleanup handler problem sonicx High Level Programming 2 12-09-2007 02:15 AM
Login ID cleanup MILLERJ62 AIX 1 05-12-2006 05:20 AM
sendmail cleanup thomi39 UNIX for Dummies Questions & Answers 1 02-23-2006 09:48 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 01-25-2008
whdr02 whdr02 is offline
Registered User
  
 

Join Date: Nov 2006
Posts: 4
Help with cleanup

I am trying to add a unique string to a variable to prevent some name space collisions.

DATAFILE=/u001/app/unica/affinium644/campaign/partitions/limited/tmp/ebf9aaah.t~#
DATETIME=`date +%Y%m%d_%H%M%S`
echo $DATAFILE > tmpnme.txt
sed 's_/_ _g' tmpnme.txt > tmpnme2.txt
DATA=$(cat tmpnme2.txt)
TMPNAME=$(echo $DATA | awk '{print $9}')
TMPNAE2=$(echo ${TMPNAME%.*})
TBLNAME=$(echo ${DATETIME}${TMPNAE2})
rm tmpnme.txt
rm tmpnme2.txt

TBLNAME will be used as the table name and the datafile is unique but I would be just as satisfied to use a random string or something else.

Any help would be appreciated. I am sure this could be done much more efficiently.
  #2 (permalink)  
Old 01-25-2008
KittyWu KittyWu is offline
Registered User
  
 

Join Date: Jan 2008
Posts: 8
Hi,

I think that the 'mktemp' command (which create a temporary
file with a *unic* name) can be usefull here:

# Create ('-c' option) a 0-length file in the tmp area
typeset -i RC
typeset LP_FILE_PATH=$(mktemp -c); RC=$?
if [[ ${RC} -ne 0 ]]; then
echo "ERROR: cannot create a temporary file"
return ${RC}
fi

# Extract the file name (supposed to be unic)
typeset LP_UNIC_NAME=${LP_FILE_PATH##*/}
# ...
# Do your stuff
# ...

# Don't forget to cleanup the temporary area!
# (to be done at the *END*)
rm -f ${LP_FILE_PATH}

Hope it helps,
C.
  #3 (permalink)  
Old 01-25-2008
whdr02 whdr02 is offline
Registered User
  
 

Join Date: Nov 2006
Posts: 4
I don't seem to have mktemp on my server.
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 12:11 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