Welcome to the VanDyke Software Forums

Join the discussion today!


Go Back   VanDyke Software Forums > Scripting

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 09-09-2005, 02:30 PM
AI77 AI77 is offline
Registered User
 
Join Date: Sep 2005
Posts: 8
Appending data to an existing file

Hi all,

my script contains a loop in which i connect to different servers one by one and checking for some errors. the errors i find (hopefully i won't find any...) are written in a file with the date in the file name. the script is schedualed to run everyday.
my goal is that each day the check on all servers will be written to one file with the date in the file name.

and so just when i check the first server everyday, the file should be CREATED, and the rest of the servers will send the data to the same file.
somehow, i can't make it happen ( i'm missing something )
relevant part of the script:

Code:
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8 

Dim g_shel
set g_shell = createobject ("WScript.shell")

Dim FILENAME
Dim FILENAME1
FILENAME1 = g_shell.specialFolders ("C:\") & "\Check_Dropps_MM-DD-YYYY.txt"


Sub Main()
.
.
Set fso = CreateObject("Scripting.FileSystemObject")

.
.
If server = 1 Then
        FILENAME = FILENAME1
        FILENAME = Replace(FILENAME, "MM", mon)
        FILENAME = Replace(FILENAME, "DD", DayOfMon)
        FILENAME = Replace(FILENAME, "YYYY", yeardt)
  Set file = fso.OpenTextFile(FILENAME, ForWriting, True)

Else
   
  Set file = fso.OpenTextFile(FILENAME, ForAppending, True)

End If
.
.
.
the first file is created but the second server is opening a new file named: "Check_Dropps_MM-DD-YYYY.txt" - which is the basic name which i changed on the first server check. didn't it saved to "FILENAME" ? and can't i now append to it ?
Can anyone see where am I wrong?
Thank's in advance
AI.
Reply With Quote
  #2  
Old 09-10-2005, 06:54 AM
liufirst liufirst is offline
Registered User
 
Join Date: Aug 2005
Posts: 27
The file name should not be in Circle.

If you meet the error that you have refered. The reason should be that when the script connects to 2rd server , this sentence is performed again:

Code:
FILENAME1 = g_shell.specialFolders ("C:\") & "\Check_Dropps_MM-DD-YYYY.txt"
Reply With Quote
  #3  
Old 09-10-2005, 08:28 AM
AI77 AI77 is offline
Registered User
 
Join Date: Sep 2005
Posts: 8
Thank's for replying

thank you, liufirst, for replying
do you have any suggestions on how to resolve this?
maybe get the definition:

Code:
Dim g_shel
set g_shell = createobject ("WScript.shell")

Dim FILENAME
Dim FILENAME1
FILENAME1 = g_shell.specialFolders ("C:\") & "\Check_Dropps_MM-DD-YYYY.txt"
into the Sub Main() ? and inside the "If server=1" condition ?
will this solve the problem?
Reply With Quote
  #4  
Old 09-10-2005, 08:42 AM
liufirst liufirst is offline
Registered User
 
Join Date: Aug 2005
Posts: 27
I think you can delete the if ... then ... else.
Then when the script runs to here, it will caculate the filename, and in one day, the filename would not be changed.

try.
Reply With Quote
  #5  
Old 09-11-2005, 03:38 AM
AI77 AI77 is offline
Registered User
 
Join Date: Sep 2005
Posts: 8
Doesn't work

hi all,
my problem remains. something is not working with the "ForAppending" function. on my second server check it get stuck showing an error with the appending line.
can you think of anything i didn't?
really need your help
Thanks guys (/girls)
Reply With Quote
  #6  
Old 09-11-2005, 04:00 AM
AI77 AI77 is offline
Registered User
 
Join Date: Sep 2005
Posts: 8
Problem solved, you guys

i solved the problem.
and just so you know the problem was that I didn't close the file before trying to reopen it for appending ( file.Close ).
so it now works.

thanks a lot, even though i solved it you gave me some leads.
AI77
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -6. The time now is 07:39 PM.