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
Problem In Shell Script satyakide Shell Programming and Scripting 11 09-24-2007 11:00 AM
Help! Problem with Shell Script. pektl Shell Programming and Scripting 7 05-29-2006 06:08 AM
Problem with SU or SSH in shell script sravanp UNIX for Dummies Questions & Answers 2 01-24-2006 12:00 PM
Shell Script problem bnohifi Shell Programming and Scripting 1 07-07-2005 03:02 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 04-09-2002
nattynatty nattynatty is offline
Registered User
  
 

Join Date: Apr 2002
Posts: 31
Unhappy Problem with shell script

Hi,
I am having a problem with a shell script. I am working in a solaris environment.

I am using PGP(Pretty Good Privacy) for encrytping a file. It works on a file(.npgp in this case) and makes an .asc file (ASCII armored file)

The situation is like this. A user logs into a web site and enters his log on information. This process creates a file (.npgp) on the Unix box.The naming convention of the file is USERNAME_DDMMYYHHMISS.npgp

Now my problem is that how can I make sure that when I access the .npgp file, I am accessing the one pertaining to the current user and also that I am not removing some other users .npgp file.

For instance, lets say a user TEST logs at 11:45:51 PM. This process would create a file called TEST_090402114551.npgp
Lets say another user logs at 11:45:52 PM.This process would create a file called TEST_090402114552.npgp

Now I dont want that when the pgp command runs and when I remove the .npgp file the second file also gets removed.

The following shell script keeps on running in the background.

#!/bin/ksh

OUTDIR="/u02/file_out1"
OUTLOG="$OUTDIR/hotspot.log"

export OUTDIR
export OUTLOG

while true

do
#Check for the existence of a *.npgp file.
if [ -e $OUTDIR/*.npgp ]
then
#If it is there, run the following PGP command and remove it.
# Currently it will remove all the .npgp files.
pgp -eat +force *.npgp 2>$OUTLOG
rm -f *.npgp
fi
sleep 1
done

exit 0


What would be good is that if somehow I store the .npgp file name in a variable and remove only that file. Also that if a number of .npgp files in this directory, this command is run one by one for each .npgp file before deleteing that file?

Any help or suggestions would be greatly appreciated?
  #2 (permalink)  
Old 04-09-2002
kristy kristy is offline
Registered User
  
 

Join Date: May 2001
Location: Allentown, PA
Posts: 54
Hi there. If I understand your question correctly, I would use a "for" loop for this.
Check the for man page, but it would go something like this:

for namevariable in *.npgp
do actions # for example, rm $variable
done
  #3 (permalink)  
Old 04-09-2002
nattynatty nattynatty is offline
Registered User
  
 

Join Date: Apr 2002
Posts: 31
Thanx for your answer, kristy.

What would be the best way to store the *.npgp file names in variables and calling them one by one?
  #4 (permalink)  
Old 04-09-2002
Jimbo
Guest
  
 

Posts: n/a
Bits: 0 [Banking]
natty, I believe the for-loop provided by kristy is the answer you seek. It provides all the filenames, one by one, into the specified variable name for processing on each loop:

Code:
for fname in *.npgp
do
   echo "Processing $fname ..."
done

  #5 (permalink)  
Old 04-09-2002
nattynatty nattynatty is offline
Registered User
  
 

Join Date: Apr 2002
Posts: 31
Got it.

Thanx a ton for your help.
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:59 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