Archive for September, 2007

Configure NTP client on Solaris 10

You need to start by editing the /etc/inet/ntp.conf file

# cat /etc/inet/ntp.conf
# define driftfile
driftfile /etc/inet/ntp.drift

# define servers:
server pool.ntp.org
server pool.ntp.org

#
# define peers:
peer ntpb.server.comany.com
peer ntpc.server.comany.com

Now you need to start up the ntp deamon.

Below is how you would do it in soalris 10.

root@server#svcadm enable ntp
root@server#svcs |grep ntp
online 13:35:01 svc:/network/ntp:default

[root@server# ps -ef|grep ntp
root 1459 1188 0 13:37:23 console 0:00 grep ntp
root 1393 1 0 13:35:01 ? 0:00 /usr/lib/inet/xntpd

You can also check the status using ntpq command at the command line.  There are many other useful commands that can be used for ntpq, which you can see by issuing the command help.

ntpq> peers
remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
+64.247.17.248   99.150.184.201   2 u  597 1024  377   28.365   11.667  26.918
-ns1.keeleysam.c 99.150.184.201   2 u  579 1024  377   66.606   29.525 105.990
+server1-a.your. 64.202.112.75    2 u   98 1024  377   45.574   -4.273   1.323
*time.nist.gov   .ACTS.           1 u  316 1024  157   71.618   -3.789   0.983
ntpq>

Other wise use the approate /etc/init.d/ntpd  script

Some important notes to keep in mind when setting up ntp.

If the accuracy of a clock becomes too insufficient (off by more than about 17 minutes), NTP aborts the NTP daemon, with the assumption that something has gone wrong with either the client or server. In order to synchronize well with a server, the client needs to avoid step adjustments.1

Which means if you clock is more then 17 minutes off when settign up NTP you should set it by hand first because NTP gets angry if it is off by more then 17 seconds

Comments

gather uptime of mulitipule machines

Below is a script that I put together to log into multipliable machines via ssh to grab the uptime of the machine. In this situation the machines are all Solaris of either 8,9,10. There is no reason that this script or any other script that I write can not be used on linux or any other *NIX with out a tiny bit of modification. I try to put plenty of comments into my scripts so they are easy to understand.

#!/bin/sh
# Written By: BAB
#Purpose: To gather the uptime from Unix machiens and present it in a readable fashion in order of uptime
#This is to be run from one central machine becuase that is where the ssh keys are set up from
#Prerequisites: ssh, sort, echo, nawk
#Files Used:uptime-before, and uptime-sorted. uptime-before is where all the machine names and uptime is stored before they are sorted and up in uptime-sorted
#Example Output: machine_name uptime, each on new line starting with shortest uptime, machines with <24 hours can show up not in their proper location because 17 hours is greater then 12 days!

DATE=`/usr/bin/date`

echo “” > uptime-before

echo “Starting to gather uptime”

#add additional files with machine names to the end of the cat command below. The files should have one machine name (host name translatable via DNS) per a line
for server in `cat /opt/scripts/sudo/sudoserver_list /opt/scripts/sudo/stagingserver_list /opt/scripts/sudo/non_sudo_server`
do
uptime=`ssh root@$server uptime | nawk ‘{print $3}’ `

echo “$server $uptime” >> uptime-before
done
echo “done getting uptime”

echo “$DATE” > uptime-sorted
sort -u uptime-before | sort +1 -n >> uptime-sorted

mailx -s “Weekly uptime report” manager@company.com < /opt/scripts/uptime-sorted

Comments

How to make a back up, encript it using gpg and copy it to a remote site using ssh

Below is a script that I wrote to back up a bunch of files, tar them and then compress them. Why use two different programs, tar and zip, because it is the UNIX way. Use one specialty program to do one thing, and one thing very well. If you put too many features into your UNIX programs then they just grow too monstrous and unmanageable like Windows (just a example).

#!/bin/bash#Written By: BAB
#The purpose of this script is to back up all directories listed, compress the directories, encript the directories, and send them to a remote site.
#compressioin /bin/bzip2
#archiving /bin/tar
#encription /usr/bin/gpg

ZIP=/bin/bzip2
TAR=/bin/tar
ENCRYPT=/usr/bin/gpg
RM=/usr/bin/rm
DATE=`/usr/bin/date +%m/%d/%Y`

BACKUPDIRS=/home/one /home/two
BACKUPNAME=server-backup$DATE
REMOTESERVER=server.com

REMOTEUSERNAME=username

GPGNAME=my name

echo “starting backup”

echo ” AKA tar”

$TAR -cf $BACKUPNAME.tar $BACKUPDIRS

echo “Starting zip”
$ZIP -z $BACKUPNAME.tar

echo “starting encryption”
$ENCRYPT –encrypt –recipient ‘$GPGNAME’ BACKUPNAME.tar

echo “sending to remote site one”
scp FILE $REMOTEUSERNAME@REMOTESERVER:~

echo “doing cleanup”
$RM $BACKUPNAME.tar.gpg
echo “cleanup done”

echo “Backup Complete!”

#echo “Decripting the file”
#gpg –output foo.txt –decrypt foo.txt.gpg

# echo “Usage: $0 {-encript -decript}” >&2
# exit 1
# ;;
#esac

#exit 0

Comments

« Previous entries Next Page » Next Page »