Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Time Script for Switch via Procomm

Status
Not open for further replies.

mlevine

MIS
Jul 21, 2002
91
US
Hello,
I was wondering if anyone familar with Procomm Scripting can help here. Trying to make a simple little script to Change the time on the Option 81C. Every Monday, it seems, they want us to sync the time. I am wondering if some one knows a way to "suck" up the time from the PC and use that in the script.

Any thoughts are welcome.

Matt

 
I FOUND THIS A LITTLE WHILE AGO IT'S FROM THREAD798-685781
*** 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, &quot;.stad&quot;, 0)
match_count = match_count + pos_match
Loop

if match_count > 0 then
EmailMsg=targetpbx & &quot;: Time Sync OK&quot;
EmailTxt=&quot;Time Sync successful. Please see attached file for session snapshot.&quot;
else
EmailMsg=targetpbx & &quot;: Time Sync Error&quot;
EmailTxt=&quot;Time Sync Failed. Please see attached file for session snapshot.&quot;
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(&quot;CDO.Message&quot;)

objMessage.Subject = EmailMsg
objMessage.From = &quot;PBX Time Sync<pbxtimesync@domain.com>&quot;
objMessage.To = &quot;pbxadmin@domain.com&quot;
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 _
(&quot; = 2

'Name or IP of Remote SMTP Server
objMessage.Configuration.Fields.Item _
(&quot; = &quot;hdbosmx.haleanddorr.com&quot;

'Server port (typically 25)
objMessage.Configuration.Fields.Item _
(&quot; = 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 (&quot;Scripting.FileSystemObject&quot;)
set xfile = filesys.GetFile(logfile)
xfile.Delete

end sub

'****************************************
Sub KillPs(strTarget, strAppToKill)

Dim strWMIConnectionString, strWMIQuery, objProcess

strWMIConnectionString = &quot;winmgmts:{impersonationLevel=impersonate}!\\&quot; _
& strTarget & &quot;\root\cimv2&quot;
strWMIQuery = &quot;SELECT * FROM Win32_Process WHERE Name='&quot; _
& strAppToKill & &quot;'&quot;

For Each objProcess In GetObject(strWMIConnectionString).ExecQuery(strWMIQuery)
objProcess.Terminate
Next

End Sub
'************************************************




OLD ROLMEN WORKING ON NORTELS
 
Impressive thank you...

Mooched the some code... works nicely..
Thank you!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top