- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- using tail -f in a 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
10-23-2002 05:03 AM
10-23-2002 05:03 AM
Here's what I am basically trying to do:
tail -f log_X | grep n > log_Y
I am doing a tail -f on log_X . Once it sees "n", I would like for it to grep it, then put it into log_Y. It ain't making it to log_Y.
I have been manually adding "n" to log_X, and the tail command is definitely seeing it, but it fails to pass it to log_Y.
Why? Is it because the command is trying to "complete" the tail -f before it executes the > (redirect) to log_Y??
Is there a better way to appraoch this?
TYIA
Solved! Go to Solution.
- Tags:
- tail
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2002 05:09 AM
10-23-2002 05:09 AM
Re: using tail -f in a script
Use tail -100 log_X
C.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2002 05:12 AM
10-23-2002 05:12 AM
Re: using tail -f in a script
I'm not sure if tail -f will work like you want it to. If I were going to try to do it, I would use a Perl script and get the Tail module from CPAN. The Tail module looks like it will do what you are looking for, and inside the Perl script you can grab what you need and write it to another file. I'm sure one of the local Perl experts will pick up on this thread and show you how to really do it right.
Just one way to try it.
JP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2002 05:23 AM
10-23-2002 05:23 AM
Re: using tail -f in a script
That would be helpful...but, I don't know PERL.
TYIA
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2002 05:31 AM
10-23-2002 05:31 AM
Re: using tail -f in a script
you could also try something like this:
tail -1f log_X | while read line
do
echo $line | grep n
if [ "$?" = "0" ]
then
# found, append
echo $line >>/log_Y
fi
done
regards,
John K.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2002 05:31 AM
10-23-2002 05:31 AM
Re: using tail -f in a script
Lets suppose I do a ls -la /etc/myfile. Here's what I expect to see:
-r--r--r-- 1 root sys 17867 Oct 21 13:37 /etc/myfile.
I am interested in the file size of this file, which in this case is 17867.
I could do a ls -la /etc/myfile | awk '{print $5}' and it would echo 17867...right?
That's cool, but what if I want to do something other than printing $5. Let's say i wanna store it, then do something else based on it's value.
For example (and I realize that STORE is not a real option here):
ls -la /etc/myfile | awk '{STORE $5}'
if [ $5 = 0 ];
echo All is well
else
echo All is not well
fi
What is the magic word here? I know it is not STORE. All I can find on using awk is the "print" option.
I don't wanna print $5, I wanna store it then use it in an IF statement.
Ideas?
TYIA
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2002 05:38 AM
10-23-2002 05:38 AM
Re: using tail -f in a script
You can store the results of your ls command in a variable, and test that variable in an if statement. Try something like this:
FILESIZE=$ls -la /etc/myfile | awk '{STORE $5}')
if (( $FILESIZE -eq = 17867 ));
echo All is well
else
echo All is not well
fi
JP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2002 05:48 AM
10-23-2002 05:48 AM
Re: using tail -f in a script
you cam do the if-statement in awk:
ls -la /etc/myfile | awk '{if ( $5 == 0) print "ok"; else print "notok"}'
Chris
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2002 05:49 AM
10-23-2002 05:49 AM
Re: using tail -f in a script
I'm not sure if tail -f will work fine or not,but usually I use for example tail -50 or 150 logfile.
regards,
Hamdy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2002 05:50 AM
10-23-2002 05:50 AM
Re: using tail -f in a script
I tried your suggestion. Same thing happened...the tail catches the "n", but it is not passed to log_Y.
?????
TYIA
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2002 05:55 AM
10-23-2002 05:55 AM
Re: using tail -f in a script
What about,for example
tail -50 /var/adm/syslog/syslog.log > /tmp/robert.
regards,
Hamdy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2002 05:57 AM
10-23-2002 05:57 AM
Re: using tail -f in a script
My example is messed up. I can't write shell scripts until I get enough caffeine into my system!
Christian's awk example will do the job.
JP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2002 06:11 AM
10-23-2002 06:11 AM
Solutionsounds strange. I have just tried this:
1) created a logfile
# touch /tmp/dunavent
2) made the script dunavent.sh with this content:
#!/usr/bin/sh
LOGFILE=/tmp/dunavent
tail -1f $LOGFILE | while read line
do
echo $line | grep e
if [ "$?" = "0" ]
then
# found
echo $line >>./log_Y
fi
done
3) executed dunavent.sh in the background:
# dunavent.sh &
4) added lines to /tmp/dunavent
# echo "ee and e" >>/tmp/dunavent
And all lines containing "e" are added to log_Y
(!?)
How did you do it?
regards,
John K.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2002 06:34 AM
10-23-2002 06:34 AM
Re: using tail -f in a script
Here is a shell which does it without a daemon :
#!/usr/bin/sh
tail -f log_X |&
NPID=$!
while :
do
read -p VAR
echo $VAR | grep n > log || continue
kill $!
break
done
cat log
Regards,
Jean-Louis.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2002 08:50 AM
10-24-2002 08:50 AM
Re: using tail -f in a script
Your script did the trick for me!!! Thanks!!
-cd