LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
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 03-29-2012, 11:13 PM   #1
gkasica
Member
 
Registered: Jan 2011
Location: Jackson WI
Distribution: Fedora Core/Generic
Posts: 50

Rep: Reputation: 0
Shell script help needed to parse ntpd -q output


I am runing an ntp server here with hte shm PPS drivers and occasionaly the driver hangs causing the GPS signal and timing to fail...the driver is still running so I can't test for it with psmon...what I'd like to do is as follows but I don't know nearly enough awk/sed/shell programming to pull it all off.

Code:
My Main problem is:

Shell script to go out and look at Colums 5 & 6 of "ntpq -p" output - specifically the 3rd row - SHM(0) and compare the whn (col 5) and poll (Col 6) and 

when (col 5) values and if when is larger than poll then kill and restart ntpd and shm drivers


ntpq -p 
     remote           refid      st t when poll reach   delay   offset    disp
==============================================================================
*SHM(0)          .PPS.            0 l    2   16  377     0.00   -1.878    4.12
+saturn          .PPS.            1 u   57   64    7     0.69    1.346    5.26
-apollo          saturn           2 u   55   64    7     0.18    3.937    5.70
xtime-B.timefreq .ACTS.           1 u   59   64    7    80.45  -13.765    5.31
-time.nist.gov   .ACTS.           1 u   53   64    7    78.11   -7.228    5.36
+otc1.psu.edu    .WWV.            1 u   56   64    7    58.39    1.836    5.61


ntpq -p | /usr/bin/awk '{print $5}'

when
 
12
51
49
53
47
50

ntpq -p | /usr/bin/awk '{print $6}'                        

poll
 
16
64
64
64
64
64


IF ROW SHM(0) WHEN > POLL THEN 


killall -9 ntpd
sleep 3
ps -efw | grep 'shm_splc2' | grep -v grep |  /usr/bin/awk '{print $2}' | /usr/local/bin/xargs kill -9
sleep 3
ntpd -q -g
sleep 3
/usr/local/bin/ntpd
sleep 3
cd /Linux/shmpps/shmpps
./start.sh
sleep 3
killall -9 ntpd
sleep 3
/usr/local/bin/ntpd
Thanks in advance for any help you can give.

George
Attached Files
File Type: txt Clock Monitoring.txt (1.8 KB, 1 views)

Last edited by gkasica; 03-29-2012 at 11:15 PM.
 
Old 03-30-2012, 01:13 AM   #2
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Servers: Debian Squeeze and Wheezy. Desktop: Slackware64 14.0. Netbook: Slackware 13.37
Posts: 8,516
Blog Entries: 27

Rep: Reputation: 1174Reputation: 1174Reputation: 1174Reputation: 1174Reputation: 1174Reputation: 1174Reputation: 1174Reputation: 1174Reputation: 1174
Something like
Code:
#!/bin/bash

i=0
while read -r _ _ _ _ when poll _
do
    (( i++ ))
    if (( i == 3 )); then
        if (( when > poll )); then
           echo "doing stuff"
        fi  
        break
    fi  
done <<< "$( ntp -q )"
 
Old 03-30-2012, 06:31 AM   #3
gkasica
Member
 
Registered: Jan 2011
Location: Jackson WI
Distribution: Fedora Core/Generic
Posts: 50

Original Poster
Rep: Reputation: 0
That looks like it will do it.

One note I had to change the last tine to done <<< "$( ntpq -p )"

---------- Post added 03-30-12 at 06:31 AM ----------

I'll test it out and report back by end of day hopeflly.
 
Old 03-30-2012, 10:20 PM   #4
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Servers: Debian Squeeze and Wheezy. Desktop: Slackware64 14.0. Netbook: Slackware 13.37
Posts: 8,516
Blog Entries: 27

Rep: Reputation: 1174Reputation: 1174Reputation: 1174Reputation: 1174Reputation: 1174Reputation: 1174Reputation: 1174Reputation: 1174Reputation: 1174
Quote:
Originally Posted by gkasica View Post
One note I had to change the last tine to done <<< "$( ntpq -p )
Sorry about that. I tested using the ntpq -p output you provided (very good LQ netiqette ) rather than the command itself because it allowed setting "when" > "poll".
 
Old 03-31-2012, 06:19 AM   #5
gkasica
Member
 
Registered: Jan 2011
Location: Jackson WI
Distribution: Fedora Core/Generic
Posts: 50

Original Poster
Rep: Reputation: 0
No problem. What I have here isworking well.
Thank you very much. I'll be markingit solved with your solution.
 
  


Reply

Tags
awk, script, sed, shell


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
Help needed for using awk to parse a file to make array for bash script tallmtt Programming 12 04-14-2012 01:16 PM
How can I configure a shell script which will parse ldap data in for each dn: vikki Linux - Server 2 12-28-2011 07:38 AM
[SOLVED] How to parse and modify these keywords using shell script? corone Programming 17 04-26-2011 07:33 AM
[shell script] execute command and parse output stoiss Programming 2 01-26-2009 01:49 AM
Shell script to parse csv-like output, row by row utahnix Linux - General 8 12-08-2007 05:03 AM


All times are GMT -5. The time now is 11:10 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