- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Script to backup log file and open new log fil...
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
12-09-2005 06:37 AM
12-09-2005 06:37 AM
Script to backup log file and open new log file
I want to add script in cron job file which should take care of ..
Check the size of the log file if it exceed 1GB then
Backup my log file with that day's date and time.
gzip backedup log file
Create new log file.
Restart process.
I am new to HP-UX. if anyone could help.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-09-2005 06:47 AM
12-09-2005 06:47 AM
Re: Script to backup log file and open new log file
Hi ,
Use the below script.
script.sh
------------
#!/usr/bin/sh
log_file=/path/file
size=`ls -al $logfile |awk '{print $5}'`
if [ $size -ge 1000000 ]
then
#backup log file
cp -p $log_file /new_location
#compress file
/path/gzip $log_file
#create new log file
touch $log_file
#Restart process , add your command below.
Restart command
fi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-09-2005 07:04 AM
12-09-2005 07:04 AM
Re: Script to backup log file and open new log file
Is the same script can we add date and time option ? And how ?
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-09-2005 07:05 AM
12-09-2005 07:05 AM
Re: Script to backup log file and open new log file
You can write a script and put it in cron to check in every 10 minute or so :
Here how it should b look like:
############################################
# script for backin up log file if larger than 1GB size. and create new logfile.
cd /logfile_dir
size=" `ls -l | grep logfile.log | awk '{print $5}'` "
echo " `echo "$size/1024" | bc` MB Current size AT: `date` "
sizemb="`echo "$size/1024" | bc ` "
##Condition :
if [ $sizemb -ge 1000 ]
then
echo " Logfile size is 1GB now at `date` "
echo "Compressing the file ...."
gzip logfile.log
mv logfile.log.gz logfile` date +%d%m%y.log
touch logfile.log
echo "Logged file moved after compress " |
## Sending email notification.
mailx -s "Log file compresseed and moved AT: `date`" yourmailid@domain.com
else
echo "Logfile not reached 1GB"
fi
##########################################
Hope this will help ,
Cheers,
Raj.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-09-2005 07:10 AM
12-09-2005 07:10 AM
Re: Script to backup log file and open new log file
Thanks for reply.So how do I restart the process in the script ?
Example. If I want to restart following process ...
root 571 1 1 Oct 28 ? 364:34 /usr/sbin/syslogd -D
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-09-2005 07:17 AM
12-09-2005 07:17 AM
Re: Script to backup log file and open new log file
Instead, cp -p the log file to logfile.1 (or something like that) and then zero out the original:
> logfile
Beter yet, why not download and install logrotate - that way everything is taken care of for you:
http://hpux.ee.ualberta.ca/hppd/hpux/Sysadmin/logrotate-2.5/
Rgds...Geoff
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-09-2005 07:18 AM
12-09-2005 07:18 AM
Re: Script to backup log file and open new log file
To restart the syslogd after , the file is compressed, and moved use this command , to the very next line:
kill -HUP `cat /var/run/syslog.pid`
Cheers,
Raj.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-09-2005 07:37 AM
12-09-2005 07:37 AM
Re: Script to backup log file and open new log file
Geoff is correct , the it should copy the file first to different place , then gzip the copied file , and then nullyfy the original file .
For setting date to the compressed file , you can use this string included in the script.
You can put it in cron to check in every 10 minute or so :
Here how it should be look like(again):
############################################
# script for backin up log file if larger than 1GB size. and create new logfile.
cd /logfile_dir
size=" `ls -l | grep logfile.log | awk '{print $5}'` "
echo " `echo "$size/1024" | bc` MB Current size AT: `date` "
sizemb="`echo "$size/1024" | bc ` "
##Condition :
if [ $sizemb -ge 1000 ]
then
echo " Logfile size is 1GB now at `date` "
### Copying to diff place & compressing. ##
dt="`date +%m%d%y`.`date +%R | awk -F : '{print $1"."$2}'`"
cp logfile.log /backupdir/logfile.$dt.log
####### Compressing the file in /backupdir...."
gzip logfile.$dt.log
####### Nullyfying the orginal log file.
cd /logfiledir
cat /dev/null > logfile.log
####### Sending email notification.
mailx -s "Log file compresseed and nullyfied the original AT: `date`" yourmailid@domain.com
####### Restarting the log.
# you can put here kill -HUP
else
echo "Logfile not reached 1GB"
fi
##########################################
Cheers,
Raj.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-09-2005 07:48 AM
12-09-2005 07:48 AM
Re: Script to backup log file and open new log file
It is designed to perform regular log
rotations.
It is available at the porting centre
http://hpux.cs.utah.edu/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2005 03:07 AM
12-19-2005 03:07 AM
Re: Script to backup log file and open new log file
cd /home/test
#size=`ls -al $logfile |awk '{print $5}'`
size=" `ls -l | grep test.log | awk '{print $5}'` "
echo " `echo "$size/1024" | bc` MB Current size AT: `date` "
sizemb="`echo "$size/1024" | bc ` "
if [ $sizemb -ge 1 ]
then
#echo " Logfile size is 1GB now at `date` "
#if [ $size -ge 1000000 ]
#then
#backup log file
cp -p $log_file /home/test/test.log
Received following error.
# ./logrotate
1973 MB Current size AT: Mon Dec 19 08:05:43 PST 2005
./logrotate[6]: Syntax error at line 7 : `then' is not matched.
If anyone helps.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2005 03:24 AM
12-19-2005 03:24 AM
Re: Script to backup log file and open new log file
You need a fi at the end of your script...
if [ test condtion ]
then
...
fi
HTH
Doug
------
Senior UNIX Admin
O'Leary Computers Inc
linkedin: http://www.linkedin.com/dkoleary
Resume: http://www.olearycomputers.com/resume.html
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2005 03:32 AM
12-19-2005 03:32 AM
Re: Script to backup log file and open new log file
I've been playing with logrotate on an HP-UX system. I was disappointed by the version at the Porting Center. It doesn't have as many of the options as the latest versions available as source from http://packages.qa.debian.org/l/logrotate.html, but if you have no way to compile (or don't want to bother with compiling), it'll do the basics well enough.
Jeff Traigle