- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Removing files within a script.
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-17-2002 06:51 AM
09-17-2002 06:51 AM
I am trying to figure out within a particular script that I am writing how to remove files that are written to 2 different log files. The files are found using the following find statements:
find / -type f -name core -exec ls > $BASEDIR/$CORELOG {} \;
find /var/adm/sa -name "sa[0-3]*" -mtime +10 -exec ls > $BASEDIR/$SARLOG {} \;
As you can see there are 2 log files here, $CORELOG and $SARLOG. So what I would like to do is write a WHILE READ statement after each of the find commands that takes each logfile and reads it's contents, then removes each of the files listed.
BTW: I know that I can accomplish this by simply adding the following to the end of each find command: -exec rm -f {} \;
But I am trying to get an idea how the WHILE READ commands would work with this.
Thank you all.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-17-2002 07:02 AM
09-17-2002 07:02 AM
SolutionSomething like this:
find /var/adm/sa -name 'sa[0-3]*' -mtime +10 | while read FNAME
do
echo "Filename: ${FNAME}"
# if you want to read the file contents put a 2nd loop here
cat ${FNAME} | while read X
do
echo "${X}"
done
rm ${FNAME}
done
Note that I also replaced your double quotes with single quotes.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-17-2002 07:02 AM
09-17-2002 07:02 AM
Re: Removing files within a script.
I would try something like this:
find / -type f -name core | tee $BASEDIR/$CORELOG | xargs rm
If you simply want to remove the files contained in the logfiles after the find command:
rm `cat $BASEDIR/$CORELOG`
or if you want to use while read:
cat $BASEDIR/$CORELOG | while read file ; do
rm $file
done
Rgds, Robin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-17-2002 07:21 AM
09-17-2002 07:21 AM
Re: Removing files within a script.
Instead of this:
cat $BASEDIR/$CORELOG | while read file
do
rm $file
done
...use:
while read file
do
rm $file
done < $BASEDIR/$CORELOG
...you eliminate the 'cat' process...
Regards!
...JRF...
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-17-2002 07:39 AM
09-17-2002 07:39 AM
Re: Removing files within a script.
Sure there is many ways to do this.
Below is a example how to redirect input inside a script.
# create a list of files
find ...... >$BASEDIR/$SARLOG
# Redirect input from the file.
exec <$BASEDIR/$SARLOG
while read a
do
# DO SOMETHING
done
# Redirect input from stdin.
exec <&1
rm $BASEDIR/$SARLOG
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-17-2002 07:48 AM
09-17-2002 07:48 AM
Re: Removing files within a script.
( find / -type f -name core; find /var/adm/sa -name 'sa[0-3]*' -mtime +10; ) | xargs rm -f
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-17-2002 10:13 AM
09-17-2002 10:13 AM
Re: Removing files within a script.
Thanks to all of you, this is truly the greatest users group/forum I have ever been a part of.
Fg.