AnandSahoo
asked on
MSDOS or Pearl or VB Script or Jscriptt to check the file size and disk space and send the alert.
Some XML files are generate on one server and comes to other server. The script and path is set in a different application log file. When they are coming to 2nd server, in case the disk space of the server is less than the files size, the file is not getting saved properly.It shows 0 KB. Can you provide a tool or script which will evaluate the size of the file and space of the server .. Once the server space is less than the files size it should send a alert. Alert by email is better.
ASKER
Yes... It will have both source and destination path. We can save the filw n destination server and make it run automatically. Whenever it finds.the source file size is more than the destination drive path, it can alert.
Okay, here's a VB script that should get you pretty close, but you will have to adjust as needed. For the email sending, take a look at the following reference for different settings that may be needed depending on your environment.
http://www.paulsadowski.com/wsh/cdo.htm
http://www.paulsadowski.com/wsh/cdo.htm
' Constants needed
Const cdoSendUsingPickup = 1 'Send message using the local SMTP service pickup directory.
Const cdoSendUsingPort = 2 'Send the message using the network (SMTP over the network).
Const cdoAnonymous = 0 'Do not authenticate
Const cdoBasic = 1 'basic (clear-text) authentication
Const cdoNTLM = 2 'NTLM
' Specify file to be copied, and folder copying to (need trailing backslash!)
strCopyFile = "c:\ee\EE27482608\temp.txt"
strDestDir = "g:\ee\"
' Try to do the copy, and end
DoCopy strCopyFile, strDestDir
Wscript.Quit
Sub DoCopy(strFile, strDir)
Set objFSO = WScript.CreateObject("Scripting.FileSystemObject")
' Get the source file object
Set objFile = objFSO.GetFile(strFile)
' Get the dest folder and drive objects
Set objDir = objFSO.GetFolder(strDir)
Set objDrive = objDir.Drive
' See if there is enough space to fit this file
If objFile.Size > objDrive.FreeSpace Then
' Not enough space, send email
SendEmail objFile.Path, objFile.Size, objDir.Path, objDrive.FreeSpace
Else
' Enougn space, copy the file
objFSO.CopyFile strFile, strDir
End If
' Free objects
Set objDrive = Nothing
Set objDir = Nothing
Set objFile = Nothing
Set objFSO = Nothing
End Sub
Sub SendEmail(strFile, intSize, strDir, intFree)
' Create CDO object
Set objEmail = CreateObject("CDO.Message")
' Specify settings needed for email and send it
objEmail.From = "your.from@you.com"
objEmail.To = "your.to@you.com"
objEmail.Subject = "Insufficient Space"
objEmail.Textbody = "Insufficient space to copy file." & vbCrLf & _
" File Path: " & strFile & vbCrLf & _
" File Size: " & intSize & vbCrLf & _
" Dest Path: " & strDir & vbCrLf & _
" Dest Free: " & intFree
objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.you.com"
objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objEmail.Configuration.Fields.Update
objEmail.Send
' Free object
Set objEmail = Nothing
End Sub
~bpASKER
Let me try this. Can you please help me with the steps to set it in the pc. Also if we can scedule it to run automatically will be grateful.
Save it as a VBS file. Edit the two lines near the top to reference your file and folder. Edit the needed lines in the email routine to your server and addresses, etc.
There are plenty of tutorials on using the windows task scheduler to schedule a program to run, here's one example (make sure you also view the "part 2" link).
http://www.windowsnetworking.com/articles_tutorials/Working-Windows-Server-2008-Task-Scheduler-Part1.html
~bp
There are plenty of tutorials on using the windows task scheduler to schedule a program to run, here's one example (make sure you also view the "part 2" link).
http://www.windowsnetworking.com/articles_tutorials/Working-Windows-Server-2008-Task-Scheduler-Part1.html
~bp
ASKER
M testing the above vb script n will get back by eod.
I also want to implement the similar thing in unix environment. Can i do it in pearl ?
I also want to implement the similar thing in unix environment. Can i do it in pearl ?
Sorry, I don't work with perl.
~bp
~bp
ASKER
Its throwing me error as below
send using configuration value is invalid.
Cdo.message.1
Also can we add the email if the source file is not available or deleted?
send using configuration value is invalid.
Cdo.message.1
Also can we add the email if the source file is not available or deleted?
ASKER
I used the following Script. Since smtp is not available with me was trying to use gmail.
' Constants needed
Const cdoSendUsingPickup = 1 'Send message using the local SMTP service pickup directory.
Const cdoSendUsingPort = 2 'Send the message using the network (SMTP over the network).
Const cdoAnonymous = 0 'Do not authenticate
Const cdoBasic = 1 'basic (clear-text) authentication
Const cdoNTLM = 2 'NTLM
' Specify file to be copied, and folder copying to (need trailing backslash!)
strCopyFile = "c:\Program Files.zip"
strDestDir = "z:\"
' Try to do the copy, and end
DoCopy strCopyFile, strDestDir
Wscript.Quit
Sub DoCopy(strFile, strDir)
Set objFSO = WScript.CreateObject("Scri pting.File SystemObje ct")
' Get the source file object
Set objFile = objFSO.GetFile(strFile)
' Get the dest folder and drive objects
Set objDir = objFSO.GetFolder(strDir)
Set objDrive = objDir.Drive
' See if there is enough space to fit this file
If objFile.Size > objDrive.FreeSpace Then
' Not enough space, send email
SendEmail objFile.Path, objFile.Size, objDir.Path, objDrive.FreeSpace
Else
' Enougn space, copy the file
objFSO.CopyFile strFile, strDir
End If
' Free objects
Set objDrive = Nothing
Set objDir = Nothing
Set objFile = Nothing
Set objFSO = Nothing
End Sub
Sub SendEmail(strFile, intSize, strDir, intFree)
' Create CDO object
Set emailObj = CreateObject("CDO.Message" )
emailObj.From = "sahooanand@gmail.com"
emailObj.To = "sahooanand@gmail.com"
emailObj.Subject = "Insufficient Space"
emailObj.TextBody = "Insufficient space to copy file." & vbCrLf & _
" File Path: " & strFile & vbCrLf & _
" File Size: " & intSize & vbCrLf & _
" Dest Path: " & strDir & vbCrLf & _
" Dest Free: " & intFree
Set emailConfig = emailObj.Configuration
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com"
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtppusessl") = true
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendusername") = "sahooanand@gmail.com"
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "Test123"
emailConfig.Fields.Update
emailObj.Send
Set emailObj = nothing
Set emialConfig = nothing
End Sub
This is the error I am getting "The transport failed to connect to the server"
' Constants needed
Const cdoSendUsingPickup = 1 'Send message using the local SMTP service pickup directory.
Const cdoSendUsingPort = 2 'Send the message using the network (SMTP over the network).
Const cdoAnonymous = 0 'Do not authenticate
Const cdoBasic = 1 'basic (clear-text) authentication
Const cdoNTLM = 2 'NTLM
' Specify file to be copied, and folder copying to (need trailing backslash!)
strCopyFile = "c:\Program Files.zip"
strDestDir = "z:\"
' Try to do the copy, and end
DoCopy strCopyFile, strDestDir
Wscript.Quit
Sub DoCopy(strFile, strDir)
Set objFSO = WScript.CreateObject("Scri
' Get the source file object
Set objFile = objFSO.GetFile(strFile)
' Get the dest folder and drive objects
Set objDir = objFSO.GetFolder(strDir)
Set objDrive = objDir.Drive
' See if there is enough space to fit this file
If objFile.Size > objDrive.FreeSpace Then
' Not enough space, send email
SendEmail objFile.Path, objFile.Size, objDir.Path, objDrive.FreeSpace
Else
' Enougn space, copy the file
objFSO.CopyFile strFile, strDir
End If
' Free objects
Set objDrive = Nothing
Set objDir = Nothing
Set objFile = Nothing
Set objFSO = Nothing
End Sub
Sub SendEmail(strFile, intSize, strDir, intFree)
' Create CDO object
Set emailObj = CreateObject("CDO.Message"
emailObj.From = "sahooanand@gmail.com"
emailObj.To = "sahooanand@gmail.com"
emailObj.Subject = "Insufficient Space"
emailObj.TextBody = "Insufficient space to copy file." & vbCrLf & _
" File Path: " & strFile & vbCrLf & _
" File Size: " & intSize & vbCrLf & _
" Dest Path: " & strDir & vbCrLf & _
" Dest Free: " & intFree
Set emailConfig = emailObj.Configuration
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com"
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtppusessl") = true
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendusername") = "sahooanand@gmail.com"
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "Test123"
emailConfig.Fields.Update
emailObj.Send
Set emailObj = nothing
Set emialConfig = nothing
End Sub
This is the error I am getting "The transport failed to connect to the server"
I did a test using gmail with the same code you have, but different account info, it send fine. Check your account info, and any firewalls on the computer or the network.
~bp
~bp
ASKER
Ok, I think I got the idea now.
Can we just edit the script to check for the availability of the file before comparing with disk space.
If the file is not available or deleted send the email.
Can we just edit the script to check for the availability of the file before comparing with disk space.
If the file is not available or deleted send the email.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Petfect ..im sure this will do. Thanks for the time n effort u have put for me.
Welcome, glad to help.
~bp
~bp
~bp