Solved

calling batch script with parametes

Posted on 2014-01-16
20
550 Views
Last Modified: 2014-02-11
Support,

I have requirement like this..

I need run one fullcompile batch file with parameters like DEV or TEST then it's goes corresponding environment calling another batch file with parameter passing like userid and password and DNS name.

I have developed some thing like this. But I don't how to call batch file with parameter substitution?

name: test.bat

@ECHO OFF
:BEGIN
CLS
set /p env= Which Environment would you like do fullcompile(CRDEV OR SIT 0R MDEV)?
IF %env% ==CRDEV GOTO ONE
IF %env% ==MDEV GOTO TWO
IF %env% ==SIT GOTO THREE
GOTO END

:ONE
call fullcomplie.bat
GOTO END

 Fullcomplie.bat contain following thing

siebdev.exe /c %CONFDIR%\..\Conf\tools_ALL.cfg /d %2 /tl %3 /u !vusername! /p !vpassword! /bc "Siebel Repository" %SRFDIR%\%2\%3\siebel.srf  

Generally after substitution parameters it's should be like this

"siebdev.exe" /c C:\Migration\Conf\tools_All.cfg /d MDEV /tl ENU /u xxxx /p xxxxx /bc "Siebel Repository" C:\Migration\Deployments\SRF\MDEV\ENU\siebel_sia.srf
0
Comment
Question by:iamsateesh
  • 10
  • 10
20 Comments
 
LVL 82

Expert Comment

by:oBdA
ID: 39786636
Should look like this (Dummy might be replaced with whatever fullcompile.bat requires when "%1" shows up):
@ECHO OFF
:BEGIN
CLS
set /p env= Which Environment would you like do fullcompile(CRDEV OR SIT 0R MDEV)?
IF %env% ==CRDEV GOTO ONE
IF %env% ==MDEV GOTO TWO
IF %env% ==SIT GOTO THREE
GOTO END

:ONE
call fullcompile.bat Dummy %env% ENU
GOTO END

Open in new window

Or, if fullcompile.bat really only contains this single line, there's no real need to have it in a separate batch, you can just combine:
@ECHO OFF
:BEGIN
CLS
set /p env= Which Environment would you like do fullcompile(CRDEV OR SIT 0R MDEV)?
IF %env% ==CRDEV GOTO ONE
IF %env% ==MDEV GOTO TWO
IF %env% ==SIT GOTO THREE
GOTO END

:ONE
siebdev.exe /c %CONFDIR%\..\Conf\tools_ALL.cfg /d %env% /tl ENU /u !vusername! /p !vpassword! /bc "Siebel Repository" %SRFDIR%\%env%\ENU\siebel.srf
GOTO END

Open in new window

0
 

Author Comment

by:iamsateesh
ID: 39786798
Thanks for responding.. I need to use first solution itself. but how to pass the MDEV, ENU and userid and password?

can you give me full script.. I'm new to this scripting...
0
 

Author Comment

by:iamsateesh
ID: 39786822
We need to use fullcompile.bat file in another place passing different parameters according into environment.
0
 
LVL 82

Expert Comment

by:oBdA
ID: 39786944
"Full script" to do what? username and password are not command line parameters in fullcompile.bat.
What exactly is your new script supposed to do? Query for all of the arguments, so that they won't have to be passed in a command line? fullcompile.bat would need to be changed as well then. How are username and password set currently, without your new script?
0
 

Author Comment

by:iamsateesh
ID: 39787417
My fullcompile script contain following thing:


siebdev.exe /c %CONFDIR%\..\Conf\tools_ALL.cfg /d <parameter1> /tl <parameter2> /u <paramter3> /p <paramter 4> /bc "Siebel Repository" %SRFDIR%\<parameter1>\<parameter2>\siebel.srf

whenever I'm calling fullcompile script it should be automatically substitution above parameters according into the environment.

I'm ok with putting all these parameters in one txt file also. if it's not possible with batchfile. I'm ok with another scripting language.

If still you need any thing from my side please give me your cell number or call me at 732-485-5253
0
 
LVL 82

Expert Comment

by:oBdA
ID: 39788391
You still haven't answered what your new script that calls fullcompile.bat is supposed to do exactly.
How are you using the fullcompile.bat script currently?
What is the source of the parameters you need?
Which parameters are static so that they can be hardcoded?
Which parameters should the user be queried for?
Can the fullcompile.bat script be adjusted as well, or are there other dependencies (since you need it in another place)
Does the fullcompile.bat script really only consists of that one line, or is that just a part of the script?
0
 

Author Comment

by:iamsateesh
ID: 39788681
Please find my answers in the below for your questions

You still haven't answered what your new script that calls fullcompile.bat is supposed to do exactly.

Ans: Whenever I ran new script it will ask for which environment has ran fullcompile? Then after passing environment like DEV or QA OR UAT
     then it will go to particular environment then it will call fullcompile batch script according into environment specific parameters
 
How are you using the fullcompile.bat script currently?
Ans: Right now I'm not using that's my idea. right now I'm manually executing
What is the source of the parameters you need?
Ans: Any thing is ok to me
Which parameters are static so that they can be hardcoded?
Ans: Yes these are static
Which parameters should the user be queried for?  
Ans: userid , password, Environment and language
Can the fullcompile.bat script be adjusted as well, or are there other dependencies (since you need it in another place)
Ans: we can Adjusted
Does the fullcompile.bat script really only consists of that one line, or is that just a part of the script?
Ans: yes it's only one line.
0
 
LVL 82

Expert Comment

by:oBdA
ID: 39789820
Here's a stand-alone script (that is, you don't need the fullcompile.bat) with a flexible menu that queries for the settings, saves them in a (user specific) ini file for the next execution, and finally calls siebdev.exe. The script is currently in test mode and will only display the siebdev.exe command it would normally run, so that you can test it. Simply remove the uppercase ECHO in the last line to run it for real.
You still might have to set the CONFDIR and SRFDIR variables, unless they're already set as default variables, and you might want  to add some more languages to VerifyList_Language.
@echo off
setlocal enabledelayedexpansion
set IniFile=%Temp%\~n0.ini
REM *** List of variable names to query for:
set QueryList=UserID Password Environment Language
REM *** List of variable names in QueryList to save in the ini file (clear text) for repeated use:
set SaveList=UserID Environment Language
REM *** Lists for variables where only certain inputs are allowed
REM *** Set a variable starting with "VerifyList_" and ending with the name of a queried variable in QueryList:
set VerifyList_Environment=CRDEV SIT MDEV DEV QA UAT
set VerifyList_Language=ENU
:Menu
cls
for %%a in (%QueryList%) do (set %%a=)
if exist "%IniFile%" (for /f %%a in ('type %Inifile%') do set %%a)
set UserID=Bla
for %%a in (%QueryList%) do (
	if defined VerifyList_%%a (
		set Choice= ^(choose from !VerifyList_%%a!^)
	) else (
		set Choice=
	)
	(set /p %%a=Please enter %%a!Choice! [!%%a!]: )
)
cls
set AllVerified=True
for %%a in (%QueryList%) do (
	if defined VerifyList_%%a (
		set Verified=False
		for %%v in (!VerifyList_%%a!) do (
			if /i "%%v"=="!%%a!" set Verified=True
		)
		if /i "!Verified!"=="False" (
			set AllVerified=False
			echo Incorrect input for %%a: !%%a!
			echo Allowed: !VerifyList_%%a!
		)
	)
)
if /i "%AllVerified%"=="False" (
	color 4F
	echo Please enter any key to try again.
	pause >NUL
	color
	goto Menu
)
(for %%a in (%SaveList%) do (echo %%a=!%%a!))>"%Inifile%"
ECHO siebdev.exe /c "%CONFDIR%\..\Conf\tools_ALL.cfg" /d %Environment% /tl ENU /u %UserID% /p %Password% /bc "Siebel Repository" "%SRFDIR%\%Environment%\%Language%\siebel.srf"

Open in new window

0
 

Author Comment

by:iamsateesh
ID: 39795791
Thanks for your response.. Sorry for the delay.. I was out of station.

I checked your code. I put in the fullcompile.bat. But again it's asking Environment and asking all userid and password?

if you see my first script it will ask "which environment would you like to do fullcompile" after passing environment details then it's automatically substitution in fullcompile along with environment userid and password [this values we can hard coded somewhere]..

Thanks,
Sateesh
0
 
LVL 82

Expert Comment

by:oBdA
ID: 39796167
From http:#a39788681
Which parameters should the user be queried for?  
Ans: userid , password, Environment and language
Take the script below as it is (some minor corrections and additions), save it as WhateverYouWant.cmd, and run it.
It should query for the parameters you wanted, and then display (not run - remove the uppercase ECHO in the last line to actually start it) the command line created.
Please enter UserID []: SomeUser
Please enter Password []: TopSecret
Please enter Environment (choose from CRDEV SIT MDEV DEV QA UAT) []: QA
Please enter Language (choose from ENU) []: ENU
Settings saved to '%Temp%\<ScriptName>.ini'
siebdev.exe /c "\..\Conf\tools_ALL.cfg" /d QA /tl ENU /u SomeUser /p "TopSecret" /bc "Siebel Repository" "\QA\ENU\siebel.srf"

Open in new window

When you run it a second time, the values you entered the last line should be already filled in (except for the password), just hit Enter to use them again.
Please enter UserID [SomeUser]:
Please enter Password []: TopSecret
Please enter Environment (choose from CRDEV SIT MDEV DEV QA UAT) [QA]:
Please enter Language (choose from ENU) [ENU]:
Settings saved to '%Temp%\<ScriptName>.ini'
siebdev.exe /c "\..\Conf\tools_ALL.cfg" /d QA /tl ENU /u SomeUser /p "TopSecret" /bc "Siebel Repository" "\QA\ENU\siebel.srf"

Open in new window

If you want the password to be saved as well, add "Password" to the SaveList variable in line 7.
If you need to pick from more environments and/or more languages, add them to the VerifyList_Environment and VerifyList_Language variables, respectively.
@echo off
setlocal enabledelayedexpansion
set IniFile=%Temp%\%~n0.ini
REM *** List of variable names to query for:
set QueryList=UserID Password Environment Language
REM *** List of variable names in QueryList to save in the ini file (clear text) for repeated use:
set SaveList=UserID Environment Language
REM *** Lists for variables where only certain inputs are allowed
REM *** Set a variable starting with "VerifyList_" and ending with the name of a queried variable in QueryList:
set VerifyList_Environment=CRDEV SIT MDEV DEV QA UAT
set VerifyList_Language=ENU
:Menu
cls
for %%a in (%QueryList%) do (set %%a=)
if exist "%IniFile%" (for /f %%a in ('type %Inifile%') do set %%a)
for %%a in (%QueryList%) do (
	if defined VerifyList_%%a (
		set Choice= ^(choose from !VerifyList_%%a!^)
	) else (
		set Choice=
	)
	(set /p %%a=Please enter %%a!Choice! [!%%a!]: )
)
cls
set AllVerified=True
for %%a in (%QueryList%) do (
	if defined VerifyList_%%a (
		set Verified=False
		for %%v in (!VerifyList_%%a!) do (
			if /i "%%v"=="!%%a!" set Verified=True
		)
		if /i "!Verified!"=="False" (
			set AllVerified=False
			echo Incorrect input for %%a: !%%a!
			echo Allowed: !VerifyList_%%a!
		)
	)
)
if /i "%AllVerified%"=="False" (
	color 4F
	echo Please enter any key to try again.
	pause >NUL
	color
	goto Menu
)
(for %%a in (%SaveList%) do (echo %%a=!%%a!))>"%Inifile%"
echo Settings saved to '%Inifile%'
ECHO siebdev.exe /c "%CONFDIR%\..\Conf\tools_ALL.cfg" /d %Environment% /tl ENU /u %UserID% /p "%Password%" /bc "Siebel Repository" "%SRFDIR%\%Environment%\%Language%\siebel.srf"

Open in new window

0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

Author Comment

by:iamsateesh
ID: 39797171
Dear Savant,

Thanks for your response..really appropriate your help. but my intention is not fill here..

Is there any way calling batch script with parameters substitution?

Example:

ssh2 sbladm@10.31.144.182 "sh /tmp/crash_file_move.sh c9324s130 CRSIT R /tmp -1"  

In above command we are calling crash_file_move.sh file with passing c9324s130 as server name and CRSIT as environment like this

In crash_file_move.sh contain like this:


#!/bin/sh

hostname=$1
env=$2
shorthostname=$3
tmpfolder=$4
noOfDays=$5

fdrcount=`find /u01/ses/siebsrvr/bin/*.fdr -type f  -mtime $noOfDays 2> /dev/null| wc -l`
corecount=`find /u01/ses/siebsrvr/bin/core.* -type f  -mtime $noOfDays 2> /dev/null| wc -l`


if [ $fdrcount -gt 0 ] || [ $corecount -gt 0 ]; then

 echo "Core dump or FDR files exists for $2. Please check //10.31.144.188/$shorthostname/crashfiles/$hostname folder"|mailx -r BE-nxgenappadminteam@jci.com -s "Core dump or FDR files exists for $2" `cat $tmpfolder/notify_email`

 if [ $fdrcount -gt 0 ]; then
   find /u01/ses/siebsrvr/bin/*.fdr -type f  -mtime $noOfDays -exec mv {} /siebel/$shorthostname/crashfiles/$hostname \;
   find /siebel/$shorthostname/crashfiles/$hostname/*.fdr -type f -mtime $noOfDays -exec sh -c '. /u01/ses/siebsrvr/siebenv.sh; sarmanalyzer -o "$1".csv -x -f "$1"' _ {}  \;
 fi
 if [ $corecount -gt 0 ]; then
   find /u01/ses/siebsrvr/bin/core.* -type f  -mtime $noOfDays -exec mv {} /siebel/$shorthostname/crashfiles/$hostname \;
 fi
fi
0
 
LVL 82

Expert Comment

by:oBdA
ID: 39797406
Is there any way calling batch script with parameters substitution?
If with that you mean passing arguments to a batch file using the command line, then yes, of course that's possible. What you started, though, was a script that queried the user for input.
So let me rephrase:
1. Your main goal is to start siebdev.exe
2. You want to pass 4 parameters as variables to siebdev.exe: userid , password, Environment and language
Is that correct? If so:
a. Which of these four arguments should be passed using the command line of the batch script?
b. Which of these four arguments should the user be prompted for in the script?
c. Which of these four arguments should be hardcoded in the script?
0
 

Author Comment

by:iamsateesh
ID: 39813287
Hi,

Here your answers for your questions.

1. Your main goal is to start siebdev.exe
Ans : Yes
2. You want to pass 4 parameters as variables to siebdev.exe: userid , password, Environment and language
Is that correct? If so:
a. Which of these four arguments should be passed using the command line of the batch script? No
b. Which of these four arguments should the user be prompted for in the script? yes but it's should ask only environment and Language[sometimes I will give both instead of ENU or FRA. If I give both then it will start both ENU and FRA]
c. Which of these four arguments should be hardcoded in the script? Yes we can hardcoded userid and password
0
 
LVL 82

Expert Comment

by:oBdA
ID: 39816276
You're not very clear, sorry.
After a solution that prompted for all arguments, allowing to store each of them (or just a selection) for the next execution, you said in http:#a39797171
but my intention is not fill here..
Is there any way calling batch script with parameters substitution?
and gave an example of passing arguments on the command line to a Linux shell script.
When I then asked which of the arguments you wanted to pass on the command line, you now say in http:#a39813287
a. Which of these four arguments should be passed using the command line of the batch script? No
Before I look into enabling multiple languages, I need to know what's what.
The script I posted in http:#a39796167 basically fulfills the requirements you posted in http:#a39813287 with the following variable settings, except for specifying multiple languages at once:
set SaveList=UserID Environment Language Password
set VerifyList_Language=ENU FRA

Open in new window

This basically hardcodes the settings (while still allowing flexibility), as you have to enter them only once for the very first time you're calling the script.
0
 

Author Comment

by:iamsateesh
ID: 39816352
Hi.. Sorry for all confusion, forget all these things.. Just I will give my requirement

   When I ran the batch file[or any script] then it should be asked for which environment[DEV, QA, UAT]?
  then after I passing the environment then it will call fullcompile.bat file with one time ENU as language and another time FRA as language with user id and password[In both language userid and password is same]..

[edited by SouthMod]
0
 
LVL 82

Expert Comment

by:oBdA
ID: 39819270
Try this; it still uses the menu with optional save of queried arguments, but allows multiple selection for the language with multiple siebdev.exe runs. As before, the script is in test mode and will only display the commands it would normally run. Remove the upper case ECHO in line 52 o run it for real.
@echo off
setlocal enabledelayedexpansion
set IniFile=%Temp%\%~n0.ini
REM *** List of variable names to query for:
set QueryList=UserID Password Environment Language
REM *** List of variable names in QueryList to save in the ini file (clear text) for repeated use:
set SaveList=UserID Password Environment Language
REM *** Lists for variables where only certain inputs are allowed
REM *** Set a variable starting with "VerifyList_" and ending with the name of a queried variable in QueryList:
set VerifyList_Environment=CRDEV SIT MDEV DEV QA UAT
set VerifyList_Language=ENU FRA
:Menu
cls
for %%a in (%QueryList%) do (set %%a=)
if exist "%IniFile%" (for /f "delims=" %%a in ('type %Inifile%') do set %%a)
for %%a in (%QueryList%) do (
	if defined VerifyList_%%a (
		set Choice= ^(choose from !VerifyList_%%a!^)
	) else (
		set Choice=
	)
	(set /p %%a=Please enter %%a!Choice! [!%%a!]: )
)
cls
set AllVerified=True
for %%a in (%QueryList%) do (
	if defined VerifyList_%%a (
		for %%m in (!%%a!) do (
			set Verified=False
			for %%v in (!VerifyList_%%a!) do (
				if /i "%%v"=="%%m" set Verified=True
			)
			if /i "!Verified!"=="False" (
				set AllVerified=False
				echo Incorrect input for %%a: !%%a!
				echo Allowed: !VerifyList_%%a!
			)
		)
	)
)
if /i "%AllVerified%"=="False" (
	color 4F
	echo Please enter any key to try again.
	pause >NUL
	color
	goto Menu
)
for %%a in (%Environment%) do (set Environment=%%a)
(for %%a in (%SaveList%) do (echo %%a=!%%a!))>"%Inifile%"
echo Settings saved to '%Inifile%'
for %%a in (%Language%) do (
	ECHO siebdev.exe /c "%CONFDIR%\..\Conf\tools_ALL.cfg" /d %Environment% /tl %%a /u %UserID% /p "%Password%" /bc "Siebel Repository" "%SRFDIR%\%Environment%\%%a\siebel.srf"
)

Open in new window

This should produce an output similar to this (note that only the language was changed to both FRA and ENU, the other arguments were offered as default from an earlier run):
Please enter UserID [SomeUser]:
Please enter Password [TopSecret]:
Please enter Environment (choose from CRDEV SIT MDEV DEV QA UAT) [QA]:
Please enter Language (choose from ENU FRA) [FRA]: FRA ENU

Settings saved to '%Temp%\<ScriptName>.ini'
siebdev.exe /c "\..\Conf\tools_ALL.cfg" /d QA /tl FRA /u SomeUser /p "TopSecret" /bc "Siebel Repository" "\QA\FRA\siebel.srf"
siebdev.exe /c "\..\Conf\tools_ALL.cfg" /d QA /tl ENU /u SomeUser /p "TopSecret" /bc "Siebel Repository" "\QA\ENU\siebel.srf"

Open in new window

0
 

Author Comment

by:iamsateesh
ID: 39819328
Thanks for your response.. Is there anyway we can hard coded userid and password in some text file instead of entering?
0
 
LVL 82

Expert Comment

by:oBdA
ID: 39820092
Again: You have to enter them only once, then they'll be saved ("hardcoded") in the ini file (location will be listed right before siebdev.exe is started; this file can be deleted at any time).
When you run the script a second time, you can just press "<Enter>" to confirm the values in the square brackets.
0
 

Author Comment

by:iamsateesh
ID: 39828314
I understand.. But I don't what enter first time also.. it should be pick userid and password from the file.
0
 
LVL 82

Accepted Solution

by:
oBdA earned 500 total points
ID: 39828839
@echo off
setlocal enabledelayedexpansion
set IniFile=%Temp%\%~n0.ini
REM *** List of variable names to query for:
set QueryList=Environment Language
REM *** List of variable names in QueryList to save in the ini file (clear text) for repeated use:
set SaveList=Environment Language
REM *** Lists for variables where only certain inputs are allowed
REM *** Set a variable starting with "VerifyList_" and ending with the name of a queried variable in QueryList:
set VerifyList_Environment=CRDEV SIT MDEV DEV QA UAT
set VerifyList_Language=ENU FRA
set UserID=SomeUser
set Password=TopSecret
:Menu
cls
for %%a in (%QueryList%) do (set %%a=)
if exist "%IniFile%" (for /f "delims=" %%a in ('type %Inifile%') do set %%a)
for %%a in (%QueryList%) do (
	if defined VerifyList_%%a (
		set Choice= ^(choose from !VerifyList_%%a!^)
	) else (
		set Choice=
	)
	(set /p %%a=Please enter %%a!Choice! [!%%a!]: )
)
cls
set AllVerified=True
for %%a in (%QueryList%) do (
	if defined VerifyList_%%a (
		for %%m in (!%%a!) do (
			set Verified=False
			for %%v in (!VerifyList_%%a!) do (
				if /i "%%v"=="%%m" set Verified=True
			)
			if /i "!Verified!"=="False" (
				set AllVerified=False
				echo Incorrect input for %%a: !%%a!
				echo Allowed: !VerifyList_%%a!
			)
		)
	)
)
if /i "%AllVerified%"=="False" (
	color 4F
	echo Please enter any key to try again.
	pause >NUL
	color
	goto Menu
)
for %%a in (%Environment%) do (set Environment=%%a)
(for %%a in (%SaveList%) do (echo %%a=!%%a!))>"%Inifile%"
echo Settings saved to '%Inifile%'
for %%a in (%Language%) do (
	ECHO siebdev.exe /c "%CONFDIR%\..\Conf\tools_ALL.cfg" /d %Environment% /tl %%a /u %UserID% /p "%Password%" /bc "Siebel Repository" "%SRFDIR%\%Environment%\%%a\siebel.srf"
)

Open in new window

0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

I have published numerous articles here at Experts Exchange that present programs/scripts written in a language called AutoHotkey. Each of those articles has a brief paragraph describing where to download the product and how to install it. I have al…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
How to install and configure Citrix XenApp 6.5 - Part 1. In this video tutorial we have explained step by step installation of Citrix XenApp 6.5 Server on Windows Server 2008 R2 is explained in this video. We have explained the difference between…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now