HPE GreenLake Administration
- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: need help with writing a script to do the foll...
Operating System - HP-UX
1835116
Members
4414
Online
110076
Solutions
Forums
Categories
Company
Local Language
back
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
back
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
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Topic Options
- 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
03-05-2003 03:01 PM
03-05-2003 03:01 PM
need help with writing a script to do the following cleanup tasks
Hello my fellow sysadmins and gurus,
I have not written scripts in a while and would greatly appreciate your help on creating a unix shellscript to do the following on our hp9000 hpux 11.00 server:
File selection criteria:
1) File location: /ifas/admin/datagc (remove only files from this directory)
2) Because IFAS still has roots from its MPE days, each file has an MPE header record which tells us what program created the file. The files we want to remove were created by the IFAS Ad-Hoc report writer.
Example:
The first record for /ifas/admin/datagc/BACTBSG is:
MPE 1028 196 64 50000 0 -1 0 0 -1 0
The string from the above that we need to select on is : " 0 0 -1 0" (there is a space before the first 0). This is the file code for the output from the Ad-Hoc Report Writer.
3) The third criteria is to remove only those files with a last modified date of ?? number of days or more (probably 30 days).
Process
1) The selected files should be moved (mv) from /ifas/admin/datagc to /ifas/admin/trash (new directory). The file should be appended with the directory name that the file came from. Example: /ifas/admin/datagc/BACTBSG is moved to /ifas/admin/trash/BACTBSG.datagc. Be sure to keep the same file permissions and modified date. We haven't yet decided how often to run this script, perhaps weekly.
2) A separate script/cron job (not yet written) will then do the actual delete from ./trash for files last modified ?? number of days or more (probably 90 days). This allows the users a last chance to keep the file before it is deleted.
Thanks so much for your help!
Ben Prusinski
System Administrator
benp@csus.edu
I have not written scripts in a while and would greatly appreciate your help on creating a unix shellscript to do the following on our hp9000 hpux 11.00 server:
File selection criteria:
1) File location: /ifas/admin/datagc (remove only files from this directory)
2) Because IFAS still has roots from its MPE days, each file has an MPE header record which tells us what program created the file. The files we want to remove were created by the IFAS Ad-Hoc report writer.
Example:
The first record for /ifas/admin/datagc/BACTBSG is:
MPE 1028 196 64 50000 0 -1 0 0 -1 0
The string from the above that we need to select on is : " 0 0 -1 0" (there is a space before the first 0). This is the file code for the output from the Ad-Hoc Report Writer.
3) The third criteria is to remove only those files with a last modified date of ?? number of days or more (probably 30 days).
Process
1) The selected files should be moved (mv) from /ifas/admin/datagc to /ifas/admin/trash (new directory). The file should be appended with the directory name that the file came from. Example: /ifas/admin/datagc/BACTBSG is moved to /ifas/admin/trash/BACTBSG.datagc. Be sure to keep the same file permissions and modified date. We haven't yet decided how often to run this script, perhaps weekly.
2) A separate script/cron job (not yet written) will then do the actual delete from ./trash for files last modified ?? number of days or more (probably 90 days). This allows the users a last chance to keep the file before it is deleted.
Thanks so much for your help!
Ben Prusinski
System Administrator
benp@csus.edu
"that which does not kill you makes you stronger"- Nieschze
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-05-2003 08:04 PM
03-05-2003 08:04 PM
Re: need help with writing a script to do the following cleanup tasks
Ben
1. Finding files in a directory with a string can be done with the grep command:
grep -l " 0 -1 0 0 -1 0" *
Although this will check every file in the dir and every line in the file but it looks pretty unique.
2. Removing old files is pretty straight-forward using the find command with the exec option.
e.g.
/usr/bin/find / \( -name '' \) -mtime +2 -exec rm -r {} \;
this removes files older than 2 days.
3. To add the directory name to the files when they are moved, the following code segment will do this:
e.g.
DIR_NAME=`pwd | sed 's/\//./g'`
mv test test.$DIR_NAME
the sed command removes all the '/' and replaces them with '.'.
Use these techniques and string them together into a script and you should be OK.
Regards,
Tim .
1. Finding files in a directory with a string can be done with the grep command:
grep -l " 0 -1 0 0 -1 0" *
Although this will check every file in the dir and every line in the file but it looks pretty unique.
2. Removing old files is pretty straight-forward using the find command with the exec option.
e.g.
/usr/bin/find /
this removes files older than 2 days.
3. To add the directory name to the files when they are moved, the following code segment will do this:
e.g.
DIR_NAME=`pwd | sed 's/\//./g'`
mv test test.$DIR_NAME
the sed command removes all the '/' and replaces them with '.'.
Use these techniques and string them together into a script and you should be OK.
Regards,
Tim .
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-05-2003 10:01 PM
03-05-2003 10:01 PM
Re: need help with writing a script to do the following cleanup tasks
here is a good start:
#!/usr/bin/ksh
fromDir=
toDir=
append=
out=crap
cd $toDir
find . -mtime +30 |
sed '/.\/.*\/.*/d' | #remove files in subdirectories
while read file
do
out=$(cat $file | awk '/NR==1/ { if ( $0 ~ "" ) print "match";"
/NR>1/ {exit;}')
if [[ $out = "match" ]] ;then
print $file | cpio -pm $toDir
rm $file
mv $toDir/$file $toDir/${file}.$append
out=crap
fi
done
you might want to add some error checking. such as your toDir exists, the cpio was sucessfull before removing the file, etc.
#!/usr/bin/ksh
fromDir=
toDir=
append=
out=crap
cd $toDir
find . -mtime +30 |
sed '/.\/.*\/.*/d' | #remove files in subdirectories
while read file
do
out=$(cat $file | awk '/NR==1/ { if ( $0 ~ "
/NR>1/ {exit;}')
if [[ $out = "match" ]] ;then
print $file | cpio -pm $toDir
rm $file
mv $toDir/$file $toDir/${file}.$append
out=crap
fi
done
you might want to add some error checking. such as your toDir exists, the cpio was sucessfull before removing the file, etc.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-05-2003 10:24 PM
03-05-2003 10:24 PM
Re: need help with writing a script to do the following cleanup tasks
Hi
find /ifas/admin/datagc -mtime 90 -type f -exec grep -il " 0 0 -1 0" {} \; | xargs rm
explanation:
- find only in the directory /ifas/admin/datagc
- only files with modification time > 90
- only files (no links or dir's)
- containing search-string " 0 0 -1 0"
- removing this files
Chris
find /ifas/admin/datagc -mtime 90 -type f -exec grep -il " 0 0 -1 0" {} \; | xargs rm
explanation:
- find only in the directory /ifas/admin/datagc
- only files with modification time > 90
- only files (no links or dir's)
- containing search-string " 0 0 -1 0"
- removing this files
Chris
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
Company
Events and news
Customer resources
© Copyright 2025 Hewlett Packard Enterprise Development LP