- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: HP-UNIX 11.0 - 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
01-31-2003 07:44 AM
01-31-2003 07:44 AM
I am wondering could anyone help me on my first script which has to delete files which have certain information in them??
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-31-2003 07:48 AM
01-31-2003 07:48 AM
Re: HP-UNIX 11.0 - script
You've come to the right place. Tell us about the files and what kind of information they have that you would be looking for.
JP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-31-2003 07:49 AM
01-31-2003 07:49 AM
Re: HP-UNIX 11.0 - script
for x in `grep -l "string" /path/* `
do
echo "removeing file $x" > logfile
rm $x
done
make sure the string is very specific as you do not want to delete files by mistake
also add anything you want between the do and done
such as moving the files instead of deleteing them ect.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-31-2003 07:50 AM
01-31-2003 07:50 AM
Re: HP-UNIX 11.0 - script
for i in $(grep -l "TEXT" [FILE TEMPLATE])
do
rm $i
done
I recommend you try this with an 'echo $i' first instead of an 'rm $i'.
Share and Enjoy! Ian
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-31-2003 07:51 AM
01-31-2003 07:51 AM
Re: HP-UNIX 11.0 - script
For example, to delete files under a folder that are older than 7 days, you would-
find /the/folder -mtime +7 -exec rm {} \;
If you wanted to delete specific files that contain a certain text you would-
cd /the/folder
grep -l "yourtext" * | xargs rm
You must be careful when removing files though. It is easy to remove files you didn't mean to remove.
I like to run my scripts with any remove commands replaced with "echo". That way I can test the command and see the list of files it WOULD delete before I actually delete them.
HTH
-- Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-31-2003 07:51 AM
01-31-2003 07:51 AM
Re: HP-UNIX 11.0 - script
You never know the text hello might be found in a binary file!
Later,
Bill
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-31-2003 08:07 AM
01-31-2003 08:07 AM
Re: HP-UNIX 11.0 - script
cd /the/cadapp/log
find . -mtime +14 -exec rm -f {} \;
Well, for many months this job ran quietly doing its task without much notice.
Then, one day, all of a sudden hundreds of files started disappearing!
It didn't take long to determine that that small cleanup job was the culprit.
It turned out that the folder "/the/cadapp/log" did not exist any more. The "cd" failed but the "find" didn't and went on it merry way starting at "/" and proceeding to delete everything over 14 days old.
Moral of the Story-
In a script, never assume that each statement was successful.
The correct job should have been-
if cd /the/cadapp/log ; then
find . -mtime +14 -exec rm -f {} \;
else
echo "/the/cadapp/log is missing" | mail me@here.com
fi
HTH
-- Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-31-2003 08:20 AM
01-31-2003 08:20 AM
Re: HP-UNIX 11.0 - script
that is why i fully path everything i script
i would of done this
find /the/cadapp/log -mtime +14 -exec rm -f {} \;
Jim
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-31-2003 10:07 AM
01-31-2003 10:07 AM
Re: HP-UNIX 11.0 - script
Thanks for the replys here is my script, however it is deleting all files beginning with tpsmppmux, and not those files with the specific line detailed.
Any ideas?
#!/bin/sh
cd /maint/debug
for x in 'grep -l "[ipm_disconnect call failed.]" tpsmppmux*'
do
rm $x
done
the following is outputted when i run the script -
./delete_tpsmpp.sh
rm: grep non-existent
rm: -l non-existent
rm: "[ipm_disconnect non-existent
rm: call non-existent
rm: failed.]" non-existent
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-31-2003 10:50 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-31-2003 11:56 AM
01-31-2003 11:56 AM
Re: HP-UNIX 11.0 - script
First locate files that contain a specific string:
find
So, you can assign this find result to a variable to recycle it and then remove these files, i.e:
FILES_TO_REMOVE=`find
for FILE in $FILES_TO_REMOVE
do
rm $FILE
done
Be careful with **rm** command, pls try with other inoffensive command (i.e: cat, ls, etc) to check that obtains the expected results, once confirmed it uses the **rm** command.
Rgds.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-31-2003 12:50 PM
01-31-2003 12:50 PM
Re: HP-UNIX 11.0 - script
as Rodney Hill pointed out, you have to back-qoute the grep for the text string. However, you also have to get rid of the brackets; that is if you want to find the files containing the full string - the bracket mean "any character mentioned", i.e. if a file contains just a single of the chars mentionend in the brackets, it will be included (probably not what you want).
You could make your script like this:
#!/bin/sh
cd /maint/debug
for x in `grep -l "ipm_disconnect call failed." tpsmppmux*`
do
#rm $x
ls -l $x
done
As Jose pointed out: please try first with something less offensive than the rm command.
regards,
John K.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-31-2003 01:22 PM
01-31-2003 01:22 PM
Re: HP-UNIX 11.0 - script
I'm sorry - In my previos mail I could not imagine that the brackets could be part of the text string to search for. It just happens that the brackets are special characters to the shell, having the regular expression function in connection with certain commands as e.g. grep, as described in the previous mail. If the brackets are to be taken literally, you need to put a backslash in front of each of them, e.g.:
"\[ipm_disconnect call failed.\]"
regards,
John K.