- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Bash script for "tails -f"
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
Discussions
Discussions
Forums
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
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
тАО11-27-2009 06:24 AM
тАО11-27-2009 06:24 AM
I tried to run a specific script for executing this command and it works fine :
tail -f t1 | logger &
But how I also can send "tail -f" of t2,t3 to syslogd into same command ? Because I wish having only one process to kill and not 3 processes for 3 tails. Suggestions ?!
Solved! Go to Solution.
- Tags:
- bash
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-27-2009 07:04 AM
тАО11-27-2009 07:04 AM
Re: Bash script for "tails -f"
You could launch one script as a background process that looks something like this:
# cat ./mytails
#!/usr/bin/sh
tail -f t1 | logger &
PID1=$!; PIDS=${PID1}
tail -f t2 | logger &
PID2=$!; PIDS=$(echo ${PIDS} ${PID2})
tail -f t3 | logger &
PID3=$!; PIDS=$(echo ${PIDS} ${PID3})
echo "${PIDS}" > /tmp/mytails.pids
wait ${PID1}; wait ${PID2}; wait ${PID3}
exit 0
# ./mytails &
Now, when you want to terminate all processes do:
# kill $(
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-27-2009 07:26 AM
тАО11-27-2009 07:26 AM
SolutionI neglected to add cleanup for the temporary file. This corrects that:
# cat ./mytails
#!/usr/bin/sh
FILE=/tmp/mytails.pids
trap 'rm -f ${FILE}' EXIT
tail -f t1 | logger &
PID1=$!; PIDS=${PID1}
tail -f t2 | logger &
PID2=$!; PIDS=$(echo ${PIDS} ${PID2})
tail -f t3 | logger &
PID3=$!; PIDS=$(echo ${PIDS} ${PID3})
echo "${PIDS}" > ${FILE}
wait ${PID1}; wait ${PID2}; wait ${PID3}
exit 0
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-27-2009 02:39 PM
тАО11-27-2009 02:39 PM
Re: Bash script for "tails -f"
This assumes a file ./logfiles exists, in which the files to watch are listed (t1 t2 t3). Every 5 seconds it checks if the no. of lines has increased. If so, the new lines are logged. If a file suddenly has less lines, a log reset is assumed and the file is logged from line 1.
It's one job to launch (or kill), you can tweak the intervals (and pretty much anything, of course), and if a file gets reset with content ( echo "resetting log" > t1 ) it doesn't seem to miss the first line as tail tends to do.
Again, I have not truly tested this or anything, so please do and improve where needed, but who knows it could be useful.
Cheers
Wout
#!/bin/sh
FIRST=1
while true
do
if [ $FIRST -eq 1 ]
then
for i in $(
eval ${i}C=$(wc -l $i|awk '{print $1}')
done
FIRST=0
else
for i in $(
eval ${i}N=$(wc -l $i|awk '{print $1}')
eval NN=\$${i}N
eval CC=\$${i}C
if [ $NN -gt $CC ]
then
eval ${i}C=$((${i}C+1))
eval sed -n "\$${i}C,\${${i}N}p" $i | logger
eval ${i}C=\$${i}N
elif [ $NN -lt $CC ]
then
echo "$i decreased in size, assuming reset." | logger
eval sed -n "1,\${${i}N}p" $i | logger
eval ${i}C=\$${i}N
fi
done
fi
sleep 3
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-27-2009 02:40 PM
тАО11-27-2009 02:40 PM
Re: Bash script for "tails -f"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-29-2009 01:20 AM
тАО11-29-2009 01:20 AM
Re: Bash script for "tails -f"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-29-2009 05:14 AM
тАО11-29-2009 05:14 AM
Re: Bash script for "tails -f"
I don't know what the perks or drawbacks would be vs tail, you'd have to test.
I did notice that when I reset a file by echoing a line ( echo reset > t1 ), tail tends to drop that first line. This thing logs the complete file when its size decreased, so you shouldn't miss any lines when that happens. You could also edit it further to fit your needs.
Cheers
Wout
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-29-2009 09:30 AM
тАО11-29-2009 09:30 AM
Re: Bash script for "tails -f"
Here's a much cleaner version with a consistent approach and the absence of the need for any temporary file handling.
# cat ./mytails
#!/usr/bin/sh
trap 'kill ${PID1} ${PID2} ${PID3}' HUP INT QUIT TERM
tail -f t1 | logger &
PID1=$!
tail -f t2 | logger &
PID2=$!
tail -f t3 | logger &
PID3=$!
wait ${PID1}; wait ${PID2}; wait ${PID3}
exit 0
Normally you would want to launch this into the background:
# ./mytails &
Now, to terminate, simply 'kill' the process in the background ('kill %1' for example) or use the pid of the 'mytails' process:
If you start the 'mytails' in the foreground, a simple 'control_C' will also will terminate everything too.
If you start 'mytails' as below, you can logoff your sesssion, of course:
# nonhup ./mytails &
...and then latter easily find and kill everything with:
# UNIX95= ps -C mytails -o pid=|xargs kill
Notice that a space (whitespace) follows 'UNIX95=' without an intervening semicolon before the 'ps' command.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-02-2009 01:50 AM
тАО12-02-2009 01:50 AM