littleknowledge
IS-IT--Management
Hi
Is there anyone who han any idea why this script act weird when I'm not logged on to the server where it's scheduled on a one minute basis. ?
If I schedule a script that quits right away, it runs perfectly, so it must by my script.
It uses my username and password in the scheduled task, the same as I sign on with.
What I see is the following:
When I'm logged off the W2003 server, it starts the task in windows scheduler, which never ends, it just stays active. As you can see in the script I added a lot of logging, but it didn't even started to log, when I'm not signed on. If i sign on and ends the task, it resumes a normal cycle again and completes on a one minute basis. It's important information, that I don't see any GUI when it runs in the scheduler, so I assume that can't be the reason. But as soon as I log off again, it get's stuck again.
' VBS Script Generated by JABPE
' Generated at: 15-11-2007
' Create TEConnection object
Set MySite = CreateObject("CuteFTPPro.TEConnection")
Set fso = CreateObject("Scripting.FileSystemObject")
' Initialize remote server host name, protocol, port, etc.
MySite.Host = "ftp.xxxxxxx.com"
MySite.Protocol = "FTP"
MySite.Port = 21
MySite.Retries = 30
MySite.Delay = 30
MySite.MaxConnections = 4
MySite.TransferType = "AUTO"
MySite.DataChannel = "PORT"
MySite.AutoRename = "OFF"
' WARNING!!! SENSITIVE DATA: user name and password.
MySite.Login = "user"
MySite.Password = "password"
MySite.SocksInfo = ""
MySite.ProxyInfo = ""
listfilename="c:\jabpe\locallist.txt"
sfolder="c:\hjs\exports\xml\"
logfilename="c:\jabpe\FTPUpload.log"
'If script is already running, then terminate
If Not fso.FileExists(listfilename) Then
Call BuildListFile
' Connect to the site
MySite.Connect
If Err.number <> 0 Then
' Couldn't connect
Call SendMail("FTP transfer couldn't connect", "Check FTP tranfer on xxxxxxx",0,"")
End If
MySite.RemoteFolder = "/EXPORTS/XML"
' Create the log file if not create. If greater than 500 K delete and recreate
Call CreateLogfile
Set lso = fspenTextFile(logfilename,8,False,0)
Set tso = fspenTextFile(listfilename,1,false,0)
Do Until tso.AtEndOfStream
xmlname=tso.ReadLine
xmlfullname=sfolder+xmlname
MySite.Upload xmlfullname, xmlname
If mysite.remoteExists (xmlname) Then
fso.MoveFile xmlfullname, sfolder+"Archive\"+xmlname
line=("OK " + gettimestamp + " upload of " + xmlname)
lso.WriteLine(line)
Else
' File hasn't been sent and it's more than one hour old ?, if so mail
line=("FAIL " + gettimestamp + " upload of " + xmlname)
lso.WriteLine(line)
Set fileproperties = fso.GetFile(xmlfullname)
createdate = fileproperties.DateCreated
If createdate < DateAdd("h", -1,Now()) Then
Call SendMail("File hasn't been sent for more than one hour", "Check FTP tranfer on xxxxxxx for file" + xmlname,1,xmlfullname)
End If
End If
Loop
'Close and delete the file
lso.Close
tso.Close
fso.DeleteFile(listfilename)
Else
' Ensure that it hasn't been running for more than one hour
Set fileproperties = fso.GetFile(listfilename)
createdate = fileproperties.DateCreated
If createdate < DateAdd("h", -1,Now()) Then
Call SendMail("FTP export is pending for more then one hour", "Check FTP tranfer on xxxxxxx",0,"")
End If
End If
MySite.Close
Function GetTimeStamp
' Build timestamp
vNow = Now()
vYearStr = CStr(Year(vNow))
vMthStr = CStr(Month(vNow))
vDayStr = CStr(Day(vNow))
vHourStr = CStr(Hour(vNow))
vMinuteStr = CStr(Minute(vNow))
vSecStr = CStr(Second(vNow))
If Len(vMthStr) = 1 Then
vMthStr = "0" & vMthStr
End If
If Len(vDayStr) = 1 Then
vDayStr = "0" & vDayStr
End If
If Len(vHourStr) = 1 Then
vHourStr = "0" & vHourStr
End If
If Len(vMinuteStr) = 1 Then
vMinuteStr = "0" & vMinuteStr
End If
If Len(vSecStr) = 1 Then
vSecStr = "0" & vSecStr
End If
GetTimeStamp = vyearstr + "-" + vmthstr + "-" + vdaystr + " " + vhourstr + ":" + vminutestr + ":" + vsecstr
End Function
Sub CreateLogfile
If Not fso.FileExists(logfilename) Then
Set lso = fso.CreateTextFile(logfilename, True)
Else
' Is the file getting too large, then delete and redo it
Set fileproperties = fso.GetFile(logfilename)
logfilesize = fileproperties.size
If logfilesize >500000 Then
fso.DeleteFile(logfilename)
Set lso = fso.CreateTextFile(logfilename, True)
End if
End If
End Sub
Sub SendMail (InSubject, InTextBody,AttAdd, Attachment)
objEmail.From = "anyone@anyone.com"
objEmail.To = "anyone@anyone.com"
objEmail.Subject = InSubject
objEmail.Textbody = InTextBody
If AttAdd=1 Then
objEmail.AddAttachment (Attachment)
Else
objEmail.AddAttachment ("")
End If
objEmail.Configuration.Fields.Item _
(" = 2
objEmail.Configuration.Fields.Item _
(" = _
"smtp.xxxxx.net"
objEmail.Configuration.Fields.Item _
(" = 25
objEmail.Configuration.Fields.Update
objEmail.Send
End Sub
Sub BuildListFile
Set tso = fso.CreateTextFile(listfilename, True)
Set folder = fso.GetFolder(sFolder)
Set files = folder.Files
For each folderIdx In files
If InStr (1,folderIdx.Name,".XML")<> 0 Then
tso.WriteLine(folderIdx.Name)
End if
Next
tso.Close
End Sub
Is there anyone who han any idea why this script act weird when I'm not logged on to the server where it's scheduled on a one minute basis. ?
If I schedule a script that quits right away, it runs perfectly, so it must by my script.
It uses my username and password in the scheduled task, the same as I sign on with.
What I see is the following:
When I'm logged off the W2003 server, it starts the task in windows scheduler, which never ends, it just stays active. As you can see in the script I added a lot of logging, but it didn't even started to log, when I'm not signed on. If i sign on and ends the task, it resumes a normal cycle again and completes on a one minute basis. It's important information, that I don't see any GUI when it runs in the scheduler, so I assume that can't be the reason. But as soon as I log off again, it get's stuck again.
' VBS Script Generated by JABPE
' Generated at: 15-11-2007
' Create TEConnection object
Set MySite = CreateObject("CuteFTPPro.TEConnection")
Set fso = CreateObject("Scripting.FileSystemObject")
' Initialize remote server host name, protocol, port, etc.
MySite.Host = "ftp.xxxxxxx.com"
MySite.Protocol = "FTP"
MySite.Port = 21
MySite.Retries = 30
MySite.Delay = 30
MySite.MaxConnections = 4
MySite.TransferType = "AUTO"
MySite.DataChannel = "PORT"
MySite.AutoRename = "OFF"
' WARNING!!! SENSITIVE DATA: user name and password.
MySite.Login = "user"
MySite.Password = "password"
MySite.SocksInfo = ""
MySite.ProxyInfo = ""
listfilename="c:\jabpe\locallist.txt"
sfolder="c:\hjs\exports\xml\"
logfilename="c:\jabpe\FTPUpload.log"
'If script is already running, then terminate
If Not fso.FileExists(listfilename) Then
Call BuildListFile
' Connect to the site
MySite.Connect
If Err.number <> 0 Then
' Couldn't connect
Call SendMail("FTP transfer couldn't connect", "Check FTP tranfer on xxxxxxx",0,"")
End If
MySite.RemoteFolder = "/EXPORTS/XML"
' Create the log file if not create. If greater than 500 K delete and recreate
Call CreateLogfile
Set lso = fspenTextFile(logfilename,8,False,0)
Set tso = fspenTextFile(listfilename,1,false,0)
Do Until tso.AtEndOfStream
xmlname=tso.ReadLine
xmlfullname=sfolder+xmlname
MySite.Upload xmlfullname, xmlname
If mysite.remoteExists (xmlname) Then
fso.MoveFile xmlfullname, sfolder+"Archive\"+xmlname
line=("OK " + gettimestamp + " upload of " + xmlname)
lso.WriteLine(line)
Else
' File hasn't been sent and it's more than one hour old ?, if so mail
line=("FAIL " + gettimestamp + " upload of " + xmlname)
lso.WriteLine(line)
Set fileproperties = fso.GetFile(xmlfullname)
createdate = fileproperties.DateCreated
If createdate < DateAdd("h", -1,Now()) Then
Call SendMail("File hasn't been sent for more than one hour", "Check FTP tranfer on xxxxxxx for file" + xmlname,1,xmlfullname)
End If
End If
Loop
'Close and delete the file
lso.Close
tso.Close
fso.DeleteFile(listfilename)
Else
' Ensure that it hasn't been running for more than one hour
Set fileproperties = fso.GetFile(listfilename)
createdate = fileproperties.DateCreated
If createdate < DateAdd("h", -1,Now()) Then
Call SendMail("FTP export is pending for more then one hour", "Check FTP tranfer on xxxxxxx",0,"")
End If
End If
MySite.Close
Function GetTimeStamp
' Build timestamp
vNow = Now()
vYearStr = CStr(Year(vNow))
vMthStr = CStr(Month(vNow))
vDayStr = CStr(Day(vNow))
vHourStr = CStr(Hour(vNow))
vMinuteStr = CStr(Minute(vNow))
vSecStr = CStr(Second(vNow))
If Len(vMthStr) = 1 Then
vMthStr = "0" & vMthStr
End If
If Len(vDayStr) = 1 Then
vDayStr = "0" & vDayStr
End If
If Len(vHourStr) = 1 Then
vHourStr = "0" & vHourStr
End If
If Len(vMinuteStr) = 1 Then
vMinuteStr = "0" & vMinuteStr
End If
If Len(vSecStr) = 1 Then
vSecStr = "0" & vSecStr
End If
GetTimeStamp = vyearstr + "-" + vmthstr + "-" + vdaystr + " " + vhourstr + ":" + vminutestr + ":" + vsecstr
End Function
Sub CreateLogfile
If Not fso.FileExists(logfilename) Then
Set lso = fso.CreateTextFile(logfilename, True)
Else
' Is the file getting too large, then delete and redo it
Set fileproperties = fso.GetFile(logfilename)
logfilesize = fileproperties.size
If logfilesize >500000 Then
fso.DeleteFile(logfilename)
Set lso = fso.CreateTextFile(logfilename, True)
End if
End If
End Sub
Sub SendMail (InSubject, InTextBody,AttAdd, Attachment)
objEmail.From = "anyone@anyone.com"
objEmail.To = "anyone@anyone.com"
objEmail.Subject = InSubject
objEmail.Textbody = InTextBody
If AttAdd=1 Then
objEmail.AddAttachment (Attachment)
Else
objEmail.AddAttachment ("")
End If
objEmail.Configuration.Fields.Item _
(" = 2
objEmail.Configuration.Fields.Item _
(" = _
"smtp.xxxxx.net"
objEmail.Configuration.Fields.Item _
(" = 25
objEmail.Configuration.Fields.Update
objEmail.Send
End Sub
Sub BuildListFile
Set tso = fso.CreateTextFile(listfilename, True)
Set folder = fso.GetFolder(sFolder)
Set files = folder.Files
For each folderIdx In files
If InStr (1,folderIdx.Name,".XML")<> 0 Then
tso.WriteLine(folderIdx.Name)
End if
Next
tso.Close
End Sub