So basically I already have a batch script that would log some information in a text file. The thing is I want to have it send an email with the results. I was wondering if there is a way to do it using the task scheduler or something of the sort. I just want this thing to be automated without the use of any other software. I only want to use what is built in with the OS.
I would recommend using a VBScript... everything is built in and it is pretty darn easy.
Here is a write up: http://www.paulsadowski.com/wsh/cdo.htm
Another one: http://www.activexperts.com/activmonitor/windowsmanagement/adminscripts/enterprise/mail/
The easiest thing would be to attach your file as an attachment whose name doesn't change. So your batch would like something like (not tested)
.... your existing stuff .... > emailAttach.txt
cscript.exe theEmailSendingScript.vbs
del /f emailAttach.txt
That way the timer can kick this off and reuse the same filename. The vbscript can attach emailAttach.txt and it was always be the new file.
A couple solutions for future readers:
Task Scheduler can now send email as an action in a Task. I believe the feature was added to Windows Server 2008.
I have used blat.exe in batch files for years. Very flexible tool found here
Powershell's Send-MailMessage cmdlet
Related
I am looking for an approach / design through which i want to automate the process of FTP from windows location to IFS location present on AS400 environment when ever there is a new file added to windows path.
Below is the approach I thought, Please refine it if needed.
We have an option WRKJOBSCDEthrough which we can run a CL program in a scheduled threshold of 1hr.
To write a CL program which invokes a script(pyton/shell) to talk to windows location(say X:drive having its IP as xx.xxx.xx.xx).
Shell script has to search for latest file in the location X:drive and FTP that jar(of size 5mb max) to IFS location(say /usr/dta/ydrive) on AS400 machine.
Thus, CL program we invoked in STEP2 has to mail to me using SNDDSTthe list of all the jars ftp'd by the scheduler job that runs every 1 hr in STEP1.
All I am new to CL programming/RPGLE . Please help me with some
learning stuff and also design of such concepts.
You could use a library like the one provided by Scott Klement at https://www.scottklement.com/ftpapi/ to roll your own automation client. It was designed to be used from RPG, and is easy to use. From there it is a simple task to:
retrieve a list of files in the directory
parse the list to retrieve file timestamps
get any files with a timestamp later than the last successful run
The CL command RUNRMTCMD can be used to invoke a command on a PC running a rexec() client. iSeries Access for Windows offers such a client, and there are others available. With the iSeries client, the output of the PC command is placed in a spool file on the AS/400, which should contain the results of the FTP session.
You can copy the spool file to a file using the CPYSPLF command and SNDDST it to yourself, but I am not sure the contents will be converted from EBCDIC to ASCII.
Check out Easy400.net for the MMAIL programs developed by Giovanni Perotti. This package includes an EMAILSPL command to email a spool file. I believe you will need to pay $50 for the download.
I think you are on the right track, but the are a lot of details.
You have to learn to program windows. dotnet filewatcher Out of scope for a complete answer. All of the other solutions seem to be polling solutions "Are we there yet?" "No were not there."
I want to make a script on windows to move my files on folde1 to folder2 when i add some new file in folder 1, is it possible or at least any part of this?
Yes, it's possible. You can use:
Powershell (example)
Batch file, with or without task scheduler (example on link above)
Task Scheduler and a VBScript (example)
VBScript and WMI __InstanceModificationEvent event (reference)
.NET's FileSystemWatcher (example)
Third party software (some suggestions)
Concept is called DirectoryWatcher/FileWatcher, you can google it by these keywords for your programming language. It's represented in most languages now.
I'm wanting to create an automated job in Windows (presumably using Task Scheduler) to copy a CSV file from a URL to my desktop. From what I can gather, a batch file cannot copy a file from an external location. Not familiar with Powershell, but it looks like it might have that capability.
What is the best way to create a script and automate the process to copy a file (http://example.com/file.csv) to my Desktop for instance? Would like to use features native to Windows without having to download a third-party application if possible.
Thanks for any and all help!
You can download a file using powershell using syntax like this:
$client = new-object System.Net.WebClient
$client.DownloadFile("http://example.com/file.csv","C:\tmp\file.txt")
Save this as a script (something.ps1). Then create a task in the Task Scheduler and add a new "Action" of the type Open Program. Use program PowerShell, and specify the path to the script (like C:\something.ps1) as the argument.
More info:
How to download files using powershell
Scheduling Powershell script execution
Windows Scripting Host does allow you to get files via HTTP.
See AnthonyWJones' answer at HTTP GET in VBS
Change code as appropriate, save as .vbs file, schedule same.
I know very little about powershell so I don't know if it can do it. I know you prefer not to use a third-party application, but you can easily do what you want with curl which comes as a single stand-alone exe: http://curl.haxx.se/dlwiz/
Is their a way to zip a file without VB Script.I got a lot of examples on web to zip file or folder using vbs but i want to do it in a single BAT file.
Yes and no. There is no built in way to do this inside windows. You can use a external application like vbscript, a exe file like 7zip, rar, lots of resources can do this. Since windows is application poor when it comes to command lines is not really surprising. But no you do not need the VB Script for anything.
Just not so easy out of the box. Maybe makecab could do it for you? As a general rule you have a hard constraint in your question. A single BAT file which in general can not do almost anything without the support of hundreds of preinstalled or commonly installed other applications.
Could you specify a the constraints a bit better. Tel WHY you need this particular constraint? And what does it mean as even most of the bat command you use require more than one file.
I'm currently in working on a script to create a custom backup script, the only piece I'm missing is a file monitor. I need some form of a script that will monitor a folder for file changes, and then run a command with the file that's changed.
So, for example, if the file changes, it'll execute "c:/syncbatch.bat %Location_Of_File%"
In VBScript, you can monitor a folder for file changes by subscribing to the WMI __InstanceModificationEvent event. These articles contain sample code that you can learn from and adapt to your specific needs:
WMI and File System Monitoring
How Can I Monitor for Different Types of Events With Just One Script?
Calling WMI is fairly cryptic and it causes the WMI service to start running which can contribute to bloat since its fairly large and you really can't cancel the file change notifications you've requested from it without rebooting. Some people experimenting with remote printing from a Dropbox folder found that a simple VBScript program that ran an endless loop with a 10 second WScript.Sleep call in the loop used far less resource. Of course to stop it you have to task kill that script or program into it some exit trigger it can find like a specifically named empty file in the watch folder, but that is still easier to do than messing with WMI.
The Folder Spy http://venussoftcorporation.blogspot.com/2010/05/thefolderspy.html
is a free lightweight DOT.NET based file/folder watching GUI application I'ved used before to run scripts based on file changes. It looks like the new version can pass the event filename to the launched command. The old version I had didn't yet support file event info so when launched, my script had to instance a File System Object and scan the watched folder to locate the new files based on criteria like datestamps and sizes.
This newer version appears to let you pass the file name to the script if you say myscript.vbs "*f" on the optional script call entry. Quotes can be important when passing file paths that have spaces in folder names. Just remember if you are watching change events you will get a lot of them as a file grows or is edited, usually you just want notification of file adds or deletes.
Another trick your script can do is put the file size in a variable, sleep for a few seconds, and check the file again to see if its changed. if it hasn't changed in a few seconds you can usually assume whatever created it is done writing it to disk. if it keeps changing just loop until its stable.