*** Into about the script ******
the scripts listed below are used to sync the time of the main pbx and the pbx in remote offices. all of the meridian switch are connected to the IP network. the script runs on a win2k pc that is time sync to the internet time source (ntp).
time sync is done using Script #1. it is an expect script. expect runs on a number of popular OS including Linux, Unix, BSD, and Windows(thru cygwin). add an entry in cron to run the scrip daily. the script can be run from the command line e.g.
#expect pbxtimesync.xpt pbx_ip_address pbx_password
for win2k, you may want to use a vbscript wrapper (script #2) to do extra functions. cygwin rlogin may not end properly so a function in vbscript is included to kill rlogin processes. note that you need to download cygwin to get rlogin and expect (
add an entry in windows scheduler to run the vbscript everyday.
*** List scripts ****************
*********************************
* Script #1 (pbxtimesync.xpt)
***********************************
#!/usr/local/bin/expect -f
#
set timeout 60
set targetpbx [lindex $argv 0]
set pbxusr [lindex $argv 1]
log_file $targetpbx.log
spawn rlogin -l CPSID $targetpbx
expect "Done" {} default {exit}
send "\n"
send "\n"
expect ">" {} default {exit}
send "logi\n"
expect "PASS" {} default {exit}
send $pbxusr
send "\n"
expect "LOGGED IN" {} default {exit}
send "ld 2\n"
expect "." {} default {exit}
send "stad [exec date "+%d %m %Y %H %M %S"]\n"
expect "." {} default {exit}
send "****"
send "\n"
expect ">" {} default {exit}
send "logo\n"
expect "LOGGED OUT" {} default {exit}
close
exit
*************************************************
* Script #2 (vbscript wrapper)
* this script was slapped together by jetb
*************************************************
Dim WshShell, oExec
Set WshShell = CreateObject("WScript.Shell"

Set fso = CreateObject("Scripting.FileSystemObject"
mypbx="MeridianPBX"
'mypbx can be hostname or IP address
pbxpassword="secretpassword"
call setpbxtime(mypbx, pbxpassword)
'if you have more pbx to time sync, you can make
'another call to setpbxtime
hostpc="name_of_pc"
psname="rlogin.exe"
call KillPs(hostpc, psname)
'****************************************
sub setpbxtime(targetpbx, pbxpass)
Set oExec = WshShell.Exec("c:\winnt\system32\cmd /c c:\hdtools\cygwin\bin\expect pbxtime.xpt " & targetpbx & " " & pbxpass)
logfile="c:\hdtools\cygwin\bin\" + targetpbx + ".log"
'Wait for the end of process
Do While oExec.Status = 0
WScript.Sleep 100
Loop
'Scan and display the output of Exec
Do While oExec.Stdout.AtEndofStream <> True
pgm_out=oExec.StdOut.ReadLine
pos_match=Instr(1, pgm_out, ".stad", 0)
match_count = match_count + pos_match
Loop
if match_count > 0 then
EmailMsg=targetpbx & ": Time Sync OK"
EmailTxt="Time Sync successful. Please see attached file for session snapshot."
else
EmailMsg=targetpbx & ": Time Sync Error"
EmailTxt="Time Sync Failed. Please see attached file for session snapshot."
end if
call sendmail(EmailMsg, EmailTxt, logfile)
call delfile(logfile)
end sub
'****************************************
sub sendmail(EmailMsg, EmailTxt, EmailFile)
'Sending a text email using a remote server
Set objMessage = CreateObject("CDO.Message"
objMessage.Subject = EmailMsg
objMessage.From = "PBX Time Sync<pbxtimesync@domain.com>"
objMessage.To = "pbxadmin@domain.com"
objMessage.TextBody = EmailTxt
objMessage.AddAttachment EmailFile
'==This section provides the configuration information for the remote SMTP server.
'==Normally you will only change the server name or IP.
objMessage.Configuration.Fields.Item _
("
= 2
'Name or IP of Remote SMTP Server
objMessage.Configuration.Fields.Item _
("
= "hdbosmx.haleanddorr.com"
'Server port (typically 25)
objMessage.Configuration.Fields.Item _
("
= 25
objMessage.Configuration.Fields.Update
'==End remote SMTP server configuration section==
objMessage.Send
end sub
'****************************************
sub delfile(logfile)
'on error continues
dim filesys, xfile
set filesys = CreateObject ("Scripting.FileSystemObject"

set xfile = filesys.GetFile(logfile)
xfile.Delete
end sub
'****************************************
Sub KillPs(strTarget, strAppToKill)
Dim strWMIConnectionString, strWMIQuery, objProcess
strWMIConnectionString = "winmgmts:{impersonationLevel=impersonate}!\\" _
& strTarget & "\root\cimv2"
strWMIQuery = "SELECT * FROM Win32_Process WHERE Name='" _
& strAppToKill & "'"
For Each objProcess In GetObject(strWMIConnectionString).ExecQuery(strWMIQuery)
objProcess.Terminate
Next
End Sub
'************************************************