Hi there --
I have a script on several of our systems that runs a series of checks, and e-mails the results to the system administrator. The workstations in question are running a derivative of Fedora Core. The code for the script is listed 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 -c peers >> dailycheck.txt
echo >> dailycheck.txt
echo >> dailycheck.txt
# NOTE: Be sure to use the '-c peers' option and argument after the ntpq command. They are
# necessary for the output of the ntpq command to be saved to the dailycheck.txt file.
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-SIM1 Daily Check" admin@company.com < /root/dailycheck.txt
When the script is run interactively, the output 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.
11:43:32 up 10:42, 3 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.3G 75% /
/dev/sda1 99M 7.3M 87M 8% /boot
/dev/shm 2.0G 0 2.0G 0% /dev/shm
/dev/sda6 7.7G 390M 7.3G 5% /export/dbsroot
/dev/sda7 764M 144K 764M 1% /export/cdr
/dev/sda8 13G 501M 13G 4% /export/home
/dev/md0 274G 143G 131G 53% /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.
remote refid st t when poll reach delay offset jitter
==============================================================================
*ccores2.mgh.har CHU_AUDIO(1) 5 u 885 1024 377 4.982 -0.932 2.859
+mcores2.mgh.har CHU_AUDIO(1) 5 u 1012 1024 377 5.387 0.771 0.667
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 1542 Jan 15 11:43 dailycheck.txt
|
The script is meant to be run as a cron job and provide the same output. However, when it is run in that state, the output, as shown below, is missing the ntpq -p data.
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.3G 75% /
/dev/sda1 99M 7.3M 87M 8% /boot
/dev/shm 2.0G 0 2.0G 0% /dev/shm
/dev/sda6 7.7G 390M 7.3G 5% /export/dbsroot
/dev/sda7 764M 144K 764M 1% /export/cdr
/dev/sda8 13G 501M 13G 4% /export/home
/dev/md0 274G 143G 131G 53% /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 15 07:00 dailycheck.txt
|
I wrote another script where only the ntpq -p command was executed prior to the output being e-mailed to the administrator. As with the aforementioned script, when run interactively, the output is correct. When run as a cron job, the output is missing the ntpq data.
I tried using the ntpq -p as well as ntpq peers command syntax in the scripts, and both resulted in the issue that has been described here.
Does anyone have an idea as to why this is occurring? Thanks.