Terminal Command into script

Hi All

I have this script that checks to see if ntp is enabled on a machine

launchctl load -w /System/Library/LaunchDaemons/org.ntp.ntpd.plist  

It retuns

org.ntp.ntpd: Already loaded

if it is loaded, is there a way to script it so that if it is loaded it does not say anything but if it is not loaded it will a) say that it is not loaded b) load it

thanks

Adam

Yeah, capture the return value. May in a perl script,

$output = `script`;

Based up on the output, do required action? What's the big deal?

# if no output 
if ( $output eq '')  {
print "not loaded";
# do load !
} elsif ( $output =~ /Already loaded/ )  {
print "loaded";
} else {
print "unexpected behaviour";
}

script not tested, but should be simple to develop & test if you know a little amount of perl.

The ntp daemon is alway running on your machine. Whether the machine uses network time is controlled by System Preferences.

if /usr/sbin/systemsetup -getusingnetworktime  | /usr/bin/grep -q Off
then
    echo "SYNCING TO NETWORK TIME"
    /usr/sbin/systemsetup -setusingnetworktime on
fi

Code is not thoroughly tested-Use at your own risk. It probably should be run as root.