Solved! Need a help to create a batch file

Oct 25, 2018
1
0
10
1. A file copied/placed in a specific directory/folder in a remote windows machine (Windows server 2012 R2 Standard)
2. Check for any spaces in the file, if found, remove the space.
3. rename and save the file with .js on that path (specific directory/folder where it was copied/placed).
4. Copy the file now to the other directory/folder of that machine.
5. go to one of the other path where an existing batch file is kept.
6. Open command prompt, so that you can run an existing batch script that will take the file (we have mentioned above) as

an input, after providing a set of command in the command prompt.
7. let the batch to run and finish.
8. check for key word 'DONE' on the command prompt screen or if the prompt is returned, this will indicate that the batch

file has completed running and now a log should be generated for review.
9. search for the that log file (txt) created (with key word out_main) at the same path where the file was copied after

rename.
10. send the log file to recipients over email.

so basically we need to create a batch program which will include all coding including all the steps mentioned above.

can someone help if this can be achieved or how that be can be achieved or is there an existing batch file i can refer to

re-code/write as a reference?

Thanks You so much!
Sandeep M
 
Solution
Nothing too crazy in there. I recommend powershell. For each step, simply type in your line item and the word powershell into google. Should get you want you need. (Your first step is really two, you first need to map a remote drive, then perform the first action)

It could be done VB Script, but it would probably be a lot more learning on your part.

Eximo

Distinguished
Herald
Nothing too crazy in there. I recommend powershell. For each step, simply type in your line item and the word powershell into google. Should get you want you need. (Your first step is really two, you first need to map a remote drive, then perform the first action)

It could be done VB Script, but it would probably be a lot more learning on your part.
 
Solution
@Sandeep,

Unless you're ready to pay someone to do that for you, you have to dig deep into PowerShell, or other scripting languages (you can run Perl, Python etc under Windows, if this is your target platform). Emaling from within that script will pose another challenge, unless you have SMTP server inhouse.
 

Peter Martin

Estimable
Oct 9, 2014
471
0
5,010
AutoIt is very handy and the Forum support is great. However you have to show initiative and start writing a script but I’m sure that kind of stuff is been done and I think I might even have some code to share..

Code:
#include-once
#include <Date.au3>
#include <FileConstants.au3>
#include "log4a.au3"


; #FUNCTION# ====================================================================================================================
; Name ..........: _BackupFiles
; Description ...:
; Syntax ........: _BackupFiles($from, $to, $filespec)
; Parameters ....: $from        - dirctory you wish to back up
;                  $to          - base directory where output goes
;                  $filespec    - filename. supports wildcards
;		- if $filespec = '' then it copies entire directory and all files
;		- Error Code set to 1 if failure so it will be in @error to the returning function
;		- should the $TargetDir be '' blank, either way you know you have an error
; Return values .: Unique, Time/Date stamped folder name containing the backups
; Author ........: Peter Martin
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _BackupFiles($from, $to, $filespec = "")
	; Get the time
	Local $sTime = _Date_Time_GetSystemTime()
	; convert to string
	$sTime = _Date_Time_SystemTimeToDateTimeStr($sTime)
	_log4a_Info('Captured System Date and Time String: ' & $sTime)

	Local $rep1 = StringReplace($sTime, " ", "-")
	Local $rep2 = StringReplace($rep1, "/", "-")
	Local $rep3 = StringReplace($rep2, ":", "-")
	$rep3 = StringReplace($rep2, ":", "-")
	; Set dir string
    Local $TargetDir = $to &"\Backups\BACKUP-" & $rep3

	If (DirCreate($TargetDir) > 0) Then
		_log4a_Info('Creation of Backup Directory Successful: ' & $TargetDir)
		; copy file to backup location
		If ( Stringlen($filespec) = 0 ) Then
			DirCopy($from, $TargetDir, 1)
		Else
			FileCopy($from &"\"&$filespec, $TargetDir, 1)
		EndIf
	Else
		_log4a_Error('Creation of Backup Directory Failed: ' & $TargetDir)
		$TargetDir = ''
		SetError (1)
	EndIf

	return($TargetDir)
EndFunc


that's how to backup user files for instance, you can see how to change the spaces or non legal characters. You can mod the code to do your renaming/copying as you please.

AutoIt is way easier than powershell. Anyway, that's most of what you would need for your copy stuff.

Get it here
https://www.autoitscript.com/site/
 

Peter Martin

Estimable
Oct 9, 2014
471
0
5,010
as far as remote copies, use UNC names and you should be safe--unless you just map the drive first for that session, AutoIt has you covered. There are UDFs for emailing and all that too, and logging, professional grade logging, log4j.au3 can be downloaded from their site. easy to use. you can do everything in AutoIt. batch would be next to impossible.

if you want to take a stab at it, go join the forum and we can help you out. but do try to do something in script before asking others to do it. They are there to help you learn, not do it for you. ;-) Teach a man to fish....

I can teach you how to log properly with AutoIt, easy peasy. you can then compile your script to exe and schedule it, etc..