Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

shell script

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I have a folder contains all the images.
> > > > R:\Image\batch
> > > >
> > > > and i have a file history.txt
> > > > in R:\Image
> > > >
> > > > In the frame when i press batchattach button it
> > will
> > > > insert all the files in
> > > > batch folder(R:\Image\batch)
> > > > Here it will append all the file names into
> > > > history.txt file.
> > > >
> > > > I need a shell script,every saturday it will
> > > > delete the files from the
> > > > folder that have the names in history.txt,and
> > clean
> > > > the history file.
 
Sorry, we don't do "Windows" here... IBM Certified Confused - MQSeries
IBM Certified Flabbergasted - AIX 5 pSeries System Administration
 
Hi

I think you got confused ..i need a sheel script to run in unix.

 
assuming that <RDRIVE> is defined to be the same location as 'R:' in windows

Code:
#!/bin/sh
RDRIVE=<RDRIVE>;
cd ${RDRIVE}/Image/batch
rm `cat ../history.txt`
cat /dev/null > ../history.txt
put above text in a file called '<something>.sh' and chmod +x <something.sh>
then add an entry in your crontab to run it every saturday.
 
I have a folder contains all the images.
> > > > R:\Image\batch
------------
sorry jad, too easy!

#!/bin/sh
RDRIVE=<RDRIVE>; # i agree
cd ${RDRIVE}/Image/batch # [{}] are not needed
rm `cat ../history.txt` # get problems with metachar
cat /dev/null > ../history.txt # will destroy ../history.txt
------------
assuming the '>' are (stupid) tabs and '\' are what unix '/' means, you can do:
------------

cd what-ever-you-want

list the-folder >>history.txt

for element in 'sort -u history.txt'
do
[ -f $element ] || continue # no files found called $element
rm -f $element
sed -e &quot;/$element/d&quot; history.txt >xxx
[ -f xxx ] || exit 1 # error encontered xxx does not exists
mv xxx history.txt
done
------------
no idea what with '\' appens, you have my be to mask it using tr|sed|or-what-you-want
:(




------------ jamisar
Einfachheit ist das Resultat der Reife. (Friedrich Schiller)
Simplicity is the fruit of maturity.
 
If the file does not exist, the previous code (sorry jamisar) will not remove the name from the history file, so the first line does not meet your requirements, try the following if you dont want to completely clear out the history file:

for element in 'sort -u history.txt'
do
rm -f $element
sed -e &quot;/$element/d&quot; history.txt > history.tmp
[ -f xxx ] || exit 1
mv history.tmp history.txt
done

If you actually want to throw the history file away each time this script is run, try this:

for element in `cat history.txt`
do
rm -f $element
done
rm history.txt

If you want the history file to be empty but still exist, then replace the last line with:

cat /dev/null > history.txt



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top