Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 204
  • Last Modified:

How to Dynamically Build a .bat file

1)Here is my file:

login 'Essbase Admin' 'essbase1';

export database Alloc.Alloc data to data_file 'C:\EssbaseBackup\Monday\Export\Alloc.txt';


exit;

2)The 'login' and 'exit' lines are static.

3) The lines in between need to be dynamic.  For instance I need a way to go out to a location which is another file named 'databases.txt'.  This file would contain the following lines and these lines could change every day:

Alloc.Alloc
isgit.isgit
z_test.z_test

4) I need the script to build my file in Step 1 to include 2 lines total. One for the Alloc.Alloc and one for the isgit.isgit.  It needs to ignore adding a line when the line in the file in Step 3 begins with 'z_'

5) The end result file would be:

login 'Essbase Admin' 'essbase1';
export database Alloc.Alloc data to data_file 'C:\EssbaseBackup\Monday\Export\Alloc.txt';
export database isgit.isgit data to data_file 'C:\EssbaseBackup\Monday\Export\isgit.txt';
exit;

6) Then save this .bat file using same name as before.


Thanks,

Sam
0
elwayisgod
Asked:
elwayisgod
2 Solutions
 
NopiusCommented:
As I said before, install UnxUtils to your Windows from here http://unxutils.sourceforge.net/ add to your PATH
and then convert like this:

gawk -F. -f convert.awk file.txt

where file.txt:
Alloc.Alloc
isgit.isgit
z_test.z_test

convert.awk is:
BEGIN{
print "login 'Essbase Admin' 'essbase1';"
}
{
print "export database " $1 FS $2 " data to data_file 'C:\\EssBaseBackup\\Monday\\Export\\" $1 ".txt;'"
}
END{print "exit;"}
0
 
bigjosh2Commented:
So, this simple 2 line batch file will almost do exactly what you want...

login 'Essbase Admin' 'essbase1';
for /f %1 in (databases.txt) do export database %1 data to data_file 'C:\EssbaseBackup\Monday\Export\%1.txt';

..except,

1) The output files will be named "Alloc.Alloc.txt" instead of "Alloc.txt" etc. This might be ok for your application.

2) It will not ignore the "Z_" line, which again might be ok in your application, depending on what the EXPORT command does when passed an invalid name.

Both #1 and/or #2 can be fixed with a bit more work. Let me know if you need to see how.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now