- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- how to auot delete a file
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
07-17-2002 02:10 AM
07-17-2002 02:10 AM
how to auot delete a file
how to monitor a file,when it reach the size defined,the script can delete if automaticaly?
thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-17-2002 02:15 AM
07-17-2002 02:15 AM
Re: how to auot delete a file
you can use the find- command for this:
find -name file_name -a -size 10000 -exec rm {}\;
--> looks for given file name, and checks if given file size is matched, then automatically removes the file.
Allways stay on the bright side of life!
Peter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-17-2002 02:17 AM
07-17-2002 02:17 AM
Re: how to auot delete a file
find /pathname \( -name filename -size +filesize \) -exec rm {} \;
HTH,
Pete
Pete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-17-2002 02:18 AM
07-17-2002 02:18 AM
Re: how to auot delete a file
One way is to use stat in your cron script:
#!/sbin/sh
file=/tmp/abc
if [ "`stat $file | head -2 | tail -1 | awk '{print $2}'`" -gt "65535" ]
then
rm -f $file
fi
Hope this helps. Regards.
Steven Sim Kok Leong
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-17-2002 02:21 AM
07-17-2002 02:21 AM
Re: how to auot delete a file
sorry, typo in my first answer:
forgot to give where to search...
find /path_to_directory ...........
Allways stay on the bright side of life!
Peter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-17-2002 02:25 AM
07-17-2002 02:25 AM
Re: how to auot delete a file
file=[your file]
lim=[file size limit]
if [ $(ls -l $file | awk '{ print $5)' -gt $lim ]
then
rm $file
fi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-17-2002 02:28 AM
07-17-2002 02:28 AM
Re: how to auot delete a file
find is indeed the most elegant way. Just be aware that by default, the number after -size is in 512-byte blocks by default.
If you want it to be in bytes, it must be followed by the 'c' character e.g. delete /tmp/my_file if exits 1024 bytes:
# find /tmp -name my_file -size +1024c -exec rm -f {} \;
Hope this helps. Regards.
Steven Sim Kok Leong
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-17-2002 02:38 AM
07-17-2002 02:38 AM
Re: how to auot delete a file
and i am sorry i didn't desc it clearly,i actually want to dete the size when its size exess the x%,as you know,some log file increase rapadily. the x is my define
thans a lot
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-17-2002 04:33 AM
07-17-2002 04:33 AM
Re: how to auot delete a file
it's not a good idea to remove logfiles, it's better to trim them to a defined size. You can use SAM for this, go to routine tasks, and trim your file to the desired size. Of course you can do this with a script also:
find / -name $1 -a -size +max_size -exec ls {} \; | tail -n 500 > my_file_trimmed
cat my_file_trimmed > $1
rm my_file_trimmed
This would get the last 500 lines of your logfile (which are the newest entries of course), put them into a dummy file and after this the original file is overwritten with the contents of the dummy file, which is deleted at the end. Call the script with the file, which you want to trim as argument, for example, your script name is trimmer.sh, and you want to trim a file named log_file, do the following command to get it to work:
trimmer.sh log_file
Allways stay on the bright side of life!
Peter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-17-2002 04:58 AM
07-17-2002 04:58 AM
Re: how to auot delete a file
First create a file with the file name and the maximum log size in it:
/var/adm/syslog/syslog.log 30000
/var/adm/cron/log 5000
Separate the file name and maximum size with a space. Let's call this file log.file.parameters.
Now we would create a script that could be scheduled in cron.
#!/bin/ksh
for log_file in `awk '{print $1}' log.file.parameters`
do
# Get the max size
max_size=`grep ^"$log_file " log.file.parameters | awk '{print $2}'`
# Check the size of the file
file_size=`ls -al $log_file | awk '{print $5}'`
# Compare the size values
if [ "$file_size" -ge "$max_size" ]
then
# Copy the file to a backup, compress the backup to conserve space, and null the data in the orig file
cp $log_file $log_file.BAK
compress $log_file.BAK
cat /dev/null > $log_file
fi
done
Hope this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2002 07:57 AM
07-18-2002 07:57 AM
Re: how to auot delete a file
basis. You can optionally,
comress the old files.
Rotation criteria can be size or time period.
If necessary, you can script in commands to restart or
interrupt programs that keep their log files open.
It is on the porting site.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2005 11:21 PM
02-06-2005 11:21 PM
Re: how to auot delete a file
My question is almost the same, but I will have to monitor 4 directories and if any file in those 4 dir exceeds 'X'MB(X is a var that the script reads from a config file and then accordingly deletes the files based on that size) , then it needs to be deleted.
i am a little confused with the usage of 'awk' and 'find'.
Please suggest.