Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum. |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
01-13-2009, 11:02 AM
|
#1
|
Member
Registered: Nov 2003
Posts: 810
Rep:
|
Problem with output from script
Hi there --
There is a script running on several of our systems that is designed to run several commands, output the results to a file, and then e-mail the file to the system administrator. The code for the script is shown below:
Code:
#!/bin/bash
# This script will run the df and uptime commands,
# and output them to a file. The file, in turn, will
# be e-mailed to the system administrator.
# Change to the home directory of the root user.
cd /root
# Run the df and uptime commands, and save the output
# to a text file.
echo "The following line will be the readout for the amount" > dailycheck.txt
echo "of time the system has been up since the last reboot." >> dailycheck.txt
echo >> dailycheck.txt
uptime >> dailycheck.txt
echo >> dailycheck.txt
echo >> dailycheck.txt
echo "The information shown below is the readout of the current" >> dailycheck.txt
echo "disk space usage on the ct-sim workstation. The most important" >> dailycheck.txt
echo "is the /export/home1 line. This filesystem is where the DICOM" >> dailycheck.txt
echo "patient data is located on the system." >> dailycheck.txt
echo >> dailycheck.txt
df -h >> dailycheck.txt
echo >> dailycheck.txt
echo >> dailycheck.txt
echo "The output shown below gives the date and time that is currently" >> dailycheck.txt
echo "on the system. The workstation should be synchronized with the network" >> dailycheck.txt
echo "time servers. The '+' and '*' symbols that precede the time servers" >> dailycheck.txt
echo "indicate the workstation is in sync with both of them." >> dailycheck.txt
echo >> dailycheck.txt
ntpq -p >> dailycheck.txt
echo >> dailycheck.txt
echo >> dailycheck.txt
echo "The file listed below should have today's date as its timestamp." >> dailycheck.txt
echo "If it does not, the administrator should investigate the cause." >> dailycheck.txt
# Run the ls -l command to list in detail dailycheck.txt,
# and save the output to a text file
echo >> dailycheck.txt
ls -l dailycheck.txt >> dailycheck.txt
# E-mail the text file to the system administrator.
mail -s "CT-SIM3 Daily Check" admin@company.com < /root/dailycheck.txt
All the output is generated successfully with one exception: The output from the ntpq -p command does not appear in the file. The text of the file is the following:
Quote:
The following line will be the readout for the amount
of time the system has been up since the last reboot.
07:00:01 up 5:58, 0 users, load average: 0.00, 0.00, 0.00
The information shown below is the readout of the current
disk space usage on the ct-sim workstation. The most important
is the /export/home1 line. This filesystem is where the DICOM
patient data is located on the system.
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 5.1G 3.8G 1.4G 75% /
/dev/sda1 99M 7.3M 87M 8% /boot
/dev/shm 2.0G 0 2.0G 0% /dev/shm
/dev/sda6 7.7G 563M 7.1G 8% /export/dbsroot
/dev/sda7 764M 144K 764M 1% /export/cdr
/dev/sda8 13G 1.1G 12G 9% /export/home
/dev/md0 274G 174G 100G 64% /export/home1
The output shown below gives the date and time that is currently
on the system. The workstation should be synchronized with the network
time servers. The '+' and '*' symbols that precede the time servers
indicate the workstation is in sync with both of them.
The file listed below should have today's date as its timestamp.
If it does not, the administrator should investigate the cause.
-rw-r--r-- 1 root bin 1226 Jan 13 07:00 dailycheck.txt
|
The output for the ntpq -p command, when run manually and either displayed on-screen or saved to file is as follows:
Quote:
remote refid st t when poll reach delay offset jitter
==============================================================================
*mcores2.mgh.har CHU_AUDIO(1) 5 u 226 1024 377 0.835 0.305 2.319
+ccores2.mgh.har CHU_AUDIO(1) 5 u 376 1024 377 0.484 -2.837 6.969
|
What would cause the ntpq -p output to not appear in the file that is e-mailed to the administrator, and what do I need to do in order to have it correctly appear in the file? Thanks.
|
|
|
01-13-2009, 01:30 PM
|
#2
|
Senior Member
Registered: Aug 2007
Location: South Carolina, U.S.A.
Distribution: Ubuntu, Fedora Core, Red Hat, SUSE, Gentoo, DSL, coLinux, uClinux
Posts: 1,302
Rep: 
|
Quote:
Originally Posted by kaplan71
Code:
ntpq -p >> dailycheck.txt
|
Try
Code:
ntpq -c peers >> dailycheck.txt
If that does not work, try
Code:
ntpq -p >> dailycheck.txt 2>&1
The second version will capture any error messages.
|
|
|
01-13-2009, 01:41 PM
|
#3
|
Member
Registered: Nov 2003
Posts: 810
Original Poster
Rep:
|
Hi there --
I changed the ntpq command syntax to read ntpq -c peers, and that seemed to do the trick. I read the man page concerning the -c option and peers argument.
If I understand what is being said, the -c tells ntpq the following argument is an interactive argument, while the peers argument lists the time servers in a so-called common format. Correct?
|
|
|
01-13-2009, 04:14 PM
|
#4
|
Senior Member
Registered: Aug 2007
Location: South Carolina, U.S.A.
Distribution: Ubuntu, Fedora Core, Red Hat, SUSE, Gentoo, DSL, coLinux, uClinux
Posts: 1,302
Rep: 
|
Quote:
Originally Posted by kaplan71
If I understand what is being said, the -c tells ntpq the following argument is an interactive argument, while the peers argument lists the time servers in a so-called common format. Correct?
|
This is the text for the "-c" option:
Code:
-c
The following argument is interpreted as an interactive format
command and is added to the list of commands to be executed on the
specified host(s). Multiple -c options may be given.
This is the text for the "-p" option:
Code:
-p
Print a list of the peers known to the server as well as a summary
of their state. This is equivalent to the peers interactive command.
I created this script:
Code:
#!/bin/bash
LOG_FILE=~/lq/ntp.log
echo -n "" > $LOG_FILE
echo "#----------------------------------------" >> $LOG_FILE
echo "# Attempting \"ntpq -p\"..." >> $LOG_FILE
ntpq -p >> $LOG_FILE 2>&1
echo "# Return value is $?" >> $LOG_FILE
echo "# Done." >> $LOG_FILE
echo "#----------------------------------------" >> $LOG_FILE
echo "# Attempting \"ntpq -c peers\"..." >> $LOG_FILE
ntpq -c peers >> $LOG_FILE 2>&1
echo "# Return value is $?" >> $LOG_FILE
echo "# Done." >> $LOG_FILE
The contents of ntp.log were
Code:
#----------------------------------------
# Attempting "ntpq -p"...
remote refid st t when poll reach delay offset jitter
==============================================================================
+clock.trit.net 192.12.19.20 2 u 152 1024 377 82.279 8.985 3.991
+clock3.redhat.c 66.187.233.4 2 u 1107 1024 376 77.828 8.264 0.615
-mirror 128.105.39.11 3 u 189 1024 377 50.685 -7.010 4.134
*druid.storyinme 130.207.244.240 2 u 224 1024 377 26.602 -1.512 0.946
LOCAL(0) 73.78.73.84 5 l 49 64 377 0.000 0.000 0.001
# Return value is 0
# Done.
#----------------------------------------
# Attempting "ntpq -c peers"...
remote refid st t when poll reach delay offset jitter
==============================================================================
+clock.trit.net 192.12.19.20 2 u 153 1024 377 82.279 8.985 3.991
+clock3.redhat.c 66.187.233.4 2 u 1107 1024 376 77.828 8.264 0.615
-mirror 128.105.39.11 3 u 189 1024 377 50.685 -7.010 4.134
*druid.storyinme 130.207.244.240 2 u 224 1024 377 26.602 -1.512 0.946
LOCAL(0) 73.78.73.84 5 l 49 64 377 0.000 0.000 0.001
# Return value is 0
# Done.
Basically, the two commands are equivalent. Without looking at the source for ntpq, I cannot tell you why one works for you, but the other does not.
|
|
|
All times are GMT -5. The time now is 06:34 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|