LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 05-10-2008, 05:58 PM   #1
tronica
Member
 
Registered: Nov 2005
Location: KCMO
Posts: 82

Rep: Reputation: 15
log monitor bash script


Im trying to make a bash script that monitors a few logs, so i used tail -f /some/log & /some/log. that worked great, but then the person who im making it for decided it needed to have a gui. so i used zenity

Code:
tail -f /var/log/apache2/access.log & tail -f /var/log/apache2/access.log | zenity --title "Apache Log Viewer" --text-info --width 1024 --height 800
That works great but its now be decided that instead of a windows that displays that we need to have popups when data enters ther log. My question is how do i replace zenity with notify-send. i can't make it work, am i missing something?
 
Old 05-11-2008, 12:37 PM   #2
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 62
Note: The version of tail which comes with most modern Linux distros can tail multiple files at once... just supply the multiple files as arguments, e.g.
Code:
tail -f /var/log/log1 /var/log/log2 /var/log/log3
tail will print a line like this when it swaps which file it is reading from:
Code:
==> /var/log/log1 <==
After that, it prints any new lines in the file. If the next activity is in the same file, the file name message is not re-printed, so you might want to keep track of this yourself, and use it as the title of your notify-send messages, e.g.
Code:
#!/bin/bash

file=unknown

tail -f log1 log2 |while read line; do
        case "$line" in
        ==\>*\<==)
                file="${line#==> }"
                file="${file% <==}"
                ;;
        *)
                notify-send "$file" "$line"
                ;;
        esac
done
 
Old 05-11-2008, 11:55 PM   #3
tronica
Member
 
Registered: Nov 2005
Location: KCMO
Posts: 82

Original Poster
Rep: Reputation: 15
thank you so much for your help, one last question is there a way to adjust the size of the pop ups? thanks again works great.
 
Old 05-12-2008, 03:59 AM   #4
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 62
I don't know. Doesn't look like it from the notify-send manual page.
 
Old 05-13-2008, 07:18 PM   #5
tronica
Member
 
Registered: Nov 2005
Location: KCMO
Posts: 82

Original Poster
Rep: Reputation: 15
sorry to keep harping on this subject, but i have one last question. Now lets say i wanted to monitor these log files on a server from my desktop. is it possible to do so and have the popups appear on my desktop? i know i could add ssh user@ip and it would log into that server, but what about notify-send. Its going to try to run local on that server. any ideas there? thanks again for your help.

Last edited by tronica; 05-13-2008 at 07:24 PM.
 
Old 05-14-2008, 02:53 AM   #6
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 62
If you ssh to the server from your desktop and have X forwarding enabled (and your DISPLAY variable set properly), then I would imagine that executing notify-send on the server would still display on your machine.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to log everything from a bash script to a file prodsac Linux - Server 2 04-15-2008 04:56 PM
bash script help - finding last n log files in all sub folders jeepescu Programming 4 11-03-2007 07:57 PM
Clean log bash script? QuarQuar Linux - General 4 10-27-2007 11:46 PM
Bash script for server log (namely var/log/messages) tenaciousbob Programming 17 05-24-2007 10:43 AM
A live log monitor script ? ifm Linux - Software 1 07-19-2002 02:54 AM


All times are GMT -5. The time now is 04:25 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration