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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Referencing an external list . . . 1

Status
Not open for further replies.

CBOIT

IS-IT--Management
Jul 9, 2010
22
US
Okay, here's the situation background:
At the bank I work for, we have a total of 5 Dell servers. All of the servers have Dell OpenManage installed. OpenManage will trigger an executable when the server run into an error. I have a series of batch files to call several VBSripts. These VBScripts send an email to certain people.
Now, here's the problem:
The system is fully functional, but I'm shooting for efficiency. In order to add an email address to the list of notified people, I have to go in and edit a bazillion different VBScripts for each server . . . and that's not fun. I would like to be able to have all of the VBScripts reference an external text file with a list of contact email addresses. I thought that this would be pretty simple . . . but I think that I might have been overly confident in my newly found skills! :) Here is an example of my Chassis Intrusion Script:

Code:
'=====================================================
'Script Beginning
'=====================================================

Const ForReading = 1
Const Source = "\\server2006\tech\servalert\phonelist.txt"

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objList = objFSO.OpenTextFile(Source, ForReading)
Set objMessage = CreateObject("CDO.Message")
strName = objList.Readline

Do Until objList.AtEndofStream

objList.Close

With objMessage
  .To       = strName
  .From     = "ServAlert <webmaster@cbobanker.com>"
  .Subject  = "Server2006"
  .TextBody = "Server2006 has reported a chassis intrusion.  Please take immediate action."


'-----------------------Remote Server Configuration
objMessage.Configuration.Fields.Item _
("[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration/sendusing")[/URL] = 2 

'Remote SMTP Server IP
objMessage.Configuration.Fields.Item _
("[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration/smtpserver")[/URL] = "mail.cbobanker.com"

'Server port
objMessage.Configuration.Fields.Item _
("[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration/smtpserverport")[/URL] = 25 

objMessage.Configuration.Fields.Update

'--------------------End of configuration

objMessage.Send

End with

Loop

'=====================================================
'End of Script
'=====================================================

There are no errors . . . it just sits there and does absolutely nothing! If I remove the strName, and enter an email address in the format: "Display Name <email@server.com>" everything works perfectly. Arg! This is all very frustrating! Any help would be greatly appreciated!

[&infin;]MP
 
Hmmm.....

The purpose of this process is to report errors. Specifically send emails to people so they can quickly be notified of problems, allowing for a shorter recovery time. Right?

You want all 5 servers to read a file from "\\server2006\tech\servalert\phonelist.txt". What if... one server cannot read the file from the other server, but still has the ability to send email notifications. In this situation, a problem would exist but you wouldn't be able to notify people on the email list because that file is not accessible.

I would suggest that it's better to store the file on each server, but have an application that allows you to modify the file and then copy the modified file to each server.

-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
That's a good point. I still need the VBScript to call on the list, though. THat's where the problem is. :(

[&infin;]MP
 
I think I see your problem. Let's take a look at just the file handling stuff... (with some indenting)

Code:
Set objList = objFSO.OpenTextFile(Source, ForReading)
strName = objList.Readline

Do Until objList.AtEndofStream
  objList.Close
Loop

The problem is that you are closing the file within the loop. Instead, you should close the file when you are done with it. Try something like this instead...

Code:
Set objList = objFSO.OpenTextFile(Source, ForReading)

Do Until objList.AtEndofStream
  strName = objList.Readline
Loop

objList.Close


-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
This is how it looks so far. Still no go. :(
Code:
'=====================================================
' Beginning of Script
'=====================================================

Const ForReading = 1
Const Source = "\\server2006\tech\servalert\phonelist.txt"

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objList = objFSO.OpenTextFile(Source, ForReading)



Do Until objList.AtEndofStream
  strName = objList.Readline
Loop

objList.Close

Set objMessage = CreateObject("CDO.Message")
With objMessage
  .To       = strName
  .From     = "CBO <webmaster@cbobanker.com>"
  .Subject  = "CRITICAL ALERT"
  .TextBody = "Server2006 has reported a chassis intrusion.  Please take immediate action."


'==This section provides the configuration information for the remote SMTP server.
objMessage.Configuration.Fields.Item _
("[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration/sendusing")[/URL] = 2 

'Name or IP of Remote SMTP Server
objMessage.Configuration.Fields.Item _
("[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration/smtpserver")[/URL] = "mail.cbobanker.com"

'Server port (typically 25)
objMessage.Configuration.Fields.Item _
("[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration/smtpserverport")[/URL] = 25 

objMessage.Configuration.Fields.Update

'==End remote SMTP server configuration section==

objMessage.Send

End with


'=====================================================
' End of Script
'=====================================================

This code works perfectly, though:

Code:
'=====================================================
' Beginning of Script
'=====================================================

Set objMessage = CreateObject("CDO.Message")

With objMessage
  .To       = "NAME <EMAIL>"
  .From     = "ServAlert <webmaster@cbobanker.com>"
  .Subject  = "Server2006"
  .TextBody = "Server2006 has reported a chassis intrusion.  Please take immediate action."


'==This section provides the configuration information for the remote SMTP server.
objMessage.Configuration.Fields.Item _
("[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration/sendusing")[/URL] = 2 

'Name or IP of Remote SMTP Server
objMessage.Configuration.Fields.Item _
("[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration/smtpserver")[/URL] = "mail.cbobanker.com"

'Server port (typically 25)
objMessage.Configuration.Fields.Item _
("[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration/smtpserverport")[/URL] = 25 

objMessage.Configuration.Fields.Update

'==End remote SMTP server configuration section==

objMessage.Send


End with

'=====================================================
' End of Script
'=====================================================

Where is the logic in that!? lol

[&infin;]MP
 
>but have an application that allows you to modify the file and then copy the modified file

Windows servers already have a process that does this sort of thing ...
 
You did not implement my suggestion the way I had intended. Sorry for not being clear. I was suggesting something like this:

Code:
'=====================================================
' Beginning of Script
'=====================================================

Const ForReading = 1
Const Source = "\\server2006\tech\servalert\phonelist.txt"

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objList = objFSO.OpenTextFile(Source, ForReading)



Do Until objList.AtEndofStream
  strName = objList.Readline

  Set objMessage = CreateObject("CDO.Message")
  With objMessage
    .To       = strName
    .From     = "CBO <webmaster@cbobanker.com>"
    .Subject  = "CRITICAL ALERT"
    .TextBody = "Server2006 has reported a chassis intrusion.  Please take immediate action."


    '==This section provides the configuration information for the remote SMTP server.
    objMessage.Configuration.Fields.Item _
    ("[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration/sendusing")[/URL] = 2

    'Name or IP of Remote SMTP Server
    objMessage.Configuration.Fields.Item _
    ("[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration/smtpserver")[/URL] = "mail.cbobanker.com"

    'Server port (typically 25)
    objMessage.Configuration.Fields.Item _
    ("[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration/smtpserverport")[/URL] = 25

    objMessage.Configuration.Fields.Update

    '==End remote SMTP server configuration section==

    objMessage.Send
  End with
Loop

objList.Close

'=====================================================
' End of Script
'=====================================================

-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Okay . . . I have to apologize for being a complete idiot, but I still can't get this to work. :( On the implementation - I'm very, very new at this - so you were probably as clear as you needed to be! lol I ran your code as it was displayed, and The email still isn't being sent. I just don't get it. The text file has one line in it. It reads like this (qoutations included:

"Matthew <email@email.server.com>"

Does that make any difference? I really appreciate your help on this. It's been driving me crazy for the past few days!

[&infin;]MP
 
I think the quotes are causing your problems.

change this:
[tt].To = strName[/tt]

To this:
[tt].To = [!]Replace([/!]strName[!], """","")[/!][/tt]

This will remove double-quotes from the data and *hopefully* allow your emails to go through.

-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
You, sir . . . are an absolute GENIUS! It worked perfectly! Thank you so much! I might be able to sleep tonight! This will make everything SOOOO much easier! I have set up a batch file to copy the file to all of the servers on a daily basis, in case the scenario you presented at the very beginning of the thread. Again, thank you soooo much! You're brilliant!

[&infin;]MP
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top