- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- log file 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-20-2001 05:33 AM
09-20-2001 05:33 AM
Can someone please assist me with writing a log script. I'm very new to Unix and defintely new to writing scripts. I need to be able to run a script that I can run from any directory, that will simply take my current log file, rename it to .(date). and then clean out the original file so it can be used the next day. My big thing here is for the script to be able to run from any directory and be able to pick up any type of lig files. Any help will be greatly appreciated here. Is someone has a sample script that I can use would also be very helpful. Thanks and have a nice day.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2001 05:57 AM
09-20-2001 05:57 AM
Re: log file script
The following processes all the log files defined in syslog.conf - sorry if it's heavy going, but will give you an idea:
======================================
#!/usr/bin/sh
#
# Set IFS to
IFS='
'
export IFS
PATH=/sbin:/usr/sbin:/usr/bin
export PATH
SHELL=/usr/bin/sh
export SHELL
CONFIG="${CONFIG:-/etc/syslog.conf}"
SYSLOGPID="${SYSLOGPID:-$(< /etc/syslog.pid)}"
#echo CONFIG is $CONFIG
#echo SYSLOGPID is $SYSLOGPID
today=$(date +%a)
typeset -i i=0 file=0
# Now get paths of all syslog files.
grep -v -e '^[ ]*#' -e '^[ ]*$' "${CONFIG}" |
while read selector action ; do
if [[ -f "${action}" ]] ; then
files[file]="${action}"
let file=file+1
fi
done
if [[ file -gt 0 ]] ; then
let i=0
while [[ i -lt file ]] ; do
rm -f "${files[i]}.${today}" "${files[i]}.${today}.Z"
if mv "${files[i]}" "${files[i]}.${today}" ; then
files[i]="${files[i]}.${today}"
else
files[i]=""
fi
let i=i+1
done
kill -1 $SYSLOGPID
let i=0
while [[ i -lt file ]] ; do
if [[ "" != "${files[i]}" ]] ; then
compress "${files[i]}"
fi
let i=i+1
done
fi
exit 0
=======================================
Rgds, Robin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2001 06:15 AM
09-20-2001 06:15 AM
Re: log file script
To fill a log from your script do:
For creating logfiles with timestamps use the following within your script: (man date ;-)
----snip-------
#!/bin/sh
TIMESTAMP=`date +
cp ${LOGFILE} ${LOGFILE}.${TIMESTAMP}
> ${LOGFILE}
# set logfile
# copy old logfile to logfile with timestamp
# and clear the old logfile to fill it with new
# informations.
----snip-------
To run a script form any position do the following: (You may add this entry to your .profile)
----snip-------
PATH=$PATH:/sbin/scripts
----snip-------
Never put a . into PATH, it is a potential security breach.
NOTE: For handling logfiles, the tool logrotate has been ported to HP-UX.
(See http://hpux.cs.utah.edu)
Hope this helps a bit
RGDS, Holger
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2001 06:55 AM
09-20-2001 06:55 AM
Re: log file script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2001 07:21 AM
09-20-2001 07:21 AM
Re: log file script
This script doesn't do much error checking
/Begin/
#!/bin/ksh
if [[ $# < 1 ]]
then
echo "Usage: $0 logfile"
fi
TIMESTAMP=`date +%m%d%y`
echo "Copying $1 to $1.${TIMESTAMP}"
cp $1 $1.${TIMESTAMP}
echo "/dev/null $1.${TIMESTAMP}"
cat /dev/null > $1
/End/
what kind of log files are you trying to move, there are already good scripts available which do lots of things, the above script will just
copy the logfile to logfile.monthdayyear format (eg logfile.092001)
-HTH
Ramesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2001 08:16 AM
09-20-2001 08:16 AM
Re: log file script
I'm trying to do this to any logfiles on any of my 30 systems that I have. I wonna be able to run this script from any directories also. Thanks for your help.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2001 08:34 AM
09-20-2001 08:34 AM
SolutionAs long as you give the right permissions to this script and give the right logfile (complete path to the logfile) you should be able to run this script from anywhere on any logfile (provided you have the right permissions on the logfile).
Like i said, if you are planning to do this for syslog, then there are better scripts like
1. logrotate.sh
http://www.introcomp.co.uk/examples/logrotate.html
2. rotatelog program by shaun Rowland (in Perl)
http://www.interhack.net/projects/rotatelog
(pretty nice)
3. Rotate logs
http://www.ginini.com.au/tools/rotatelogs/
Does this answer your question?
-Regards
Ramesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2001 08:43 AM
09-20-2001 08:43 AM
Re: log file script
Lets take a look. You have 30 systems and do you want to run script on any systems? It will be pain after couple days. If you are able to remsh from one system to all other system then setup your script in one server.
In order to run from any directory you have to setup path in your .cshrc. Then you copy script in to that directory
#echo $PATH and choose appropriate directory where you can save your script.
Now lets take script from Ramesh and change little
#!/bin/ksh
if [[ $# < 1 ]]
then
echo "Usage: $0 logfile"
fi
TIMESTAMP=`date +%m%d%y`
for SYSTEM in server1 server2 server3?? ; do
echo "Copying $1 to $1.${TIMESTAMP}"
remsh ${SYSTEM} cp $1 $1.${TIMESTAMP}
remsh ${SYSTEM} echo "/dev/null $1.${TIMESTAMP}"
remsh ${SYSTEM} cat /dev/null > $1
done
/End/
If you have that script as cleanup then run
#cleanup /var/adm/syslog/mail.log
It will run on three server.
Sachin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2001 08:44 AM
09-20-2001 08:44 AM