Windows script to shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Windows script to shell script
# 1  
Old 03-27-2018
Windows script to shell script

Code:
SETLOCAL  	
REM execute merged script into DB
IF "%EnvName%"=="DEV" (
echo This is Dev

for /f "tokens=2 delims=^=" %%l in ('findstr "Server_%EnvName%" "%~dp0%configFilePath%"') do (
SET serv=!serv!%%l
echo "Server Name !serv!"
)

for /f "tokens=2 delims=^=" %%m in ('findstr "User_%EnvName%" "%~dp0%configFilePath%"') do (
SET usrName=!usrName!%%m
echo "USER Name !usrName!"
)

for /f "tokens=2 delims=^=" %%n in ('findstr "Pwd_%EnvName%" "%~dp0%configFilePath%"') do (
SET pwd=!pwd!%%n
echo "Password !pwd!"
)

for /f "tokens=2 delims=^=" %%n in ('findstr "DB_%EnvName%" "%~dp0%configFilePath%"') do (
SET db=!db!%%n
echo "Database !db!"
)

rem Execute for ddldml scripts first then SP.
sqlcmd -S !serv! -U !usrName! -P !pwd! -d !db! -i "%~dp0SourceCode\Output\MergedDDLAndDMLFile.sql"
sqlcmd -S !serv! -U !usrName! -P !pwd! -d !db! -i "%~dp0SourceCode\Output\MergedStoredProcs_!stamp!.sql"
echo SQLCommend ended successfully.
endlocal

Moderator's Comments:
Mod Comment Welcome on board, please use code tags for your code and data, thanks

Last edited by vbe; 03-27-2018 at 03:44 AM.. Reason: code tags
# 2  
Old 03-27-2018
Nice script, but you forgot to ask a question.
# 3  
Old 03-27-2018
Hi ,I want to convert this file to shell script .
Can you help in this
# 4  
Old 03-27-2018
I guess you mean that you want to *rewrite* it as a shell script (because Windows Batch is so different from all reasonable shell languages that the idea of "conversion" does not really apply).

Since you for sure do not expect that someone is programming for free whole scripts for you - if you are looking for a programmer doing this kind of work, I recommend the site Les meilleurs freelances, la securite et les services en plus - Freelance.com -, we need concrete questions as to which Batch statements you want to know how to perform this operation in some shell language. If you have trouble with several statements, I recommend you to create separate posts, as it makes discussion easier.

Also, you should indicate what kind of shell you have in mind (Posix Shell, Korn Shell, Z-Shell,...).
This User Gave Thanks to rovf For This Post:
# 5  
Old 03-27-2018
Hi rovf ,

Thanks for your reply
My basic concern was to rewrite this command in linux shell script
IF "%EnvName%"=="DEV" (
echo This is Dev
for /f "tokens=2 delims=^=" %%l in ('findstr "Server_%EnvName%" "%~dp0%configFilePath%"') do (
)

This is what i tried writing
if [$EnvName:==:"DEV"]; then
echo This is DEV environment
for -f "tokens=2 delims=^= A in ('findstr "Server_$EnvName" "$path$configFilePath"')";do
set serv=!serv!$A
echo "Server Name !serv!"
done
fi

but I am getting syntax error near unexpected token `"tokens=2 delims=^= A in ('findstr "Server_$EnvName" "$path$configFilePath"')"'
main.sh: line 43: `for -f "tokens=2 delims=^= A in ('findstr "Server_$EnvName" "$path$configFilePath"')";do '

Can you please sugegest
very new in Linux
# 6  
Old 03-27-2018
You didn't say under which shell you are running your code (there is no such thing like a "Linux shell"), and the syntax you are used, doesn't resemble any of the shells which are typically available under Linux. Are you looking for a Posix-shell solution? In this case, your 'for' statement doesn't make any sense. Have a look at Shell Command Language ; you find the 'for' statement described in section 2.9.4.

It would also help if you would describe with a few words, what your statement is supposed to do. While I have a coarse knowledge about how to write loops in the Windows batch language, I don't know all the gory details.

Also, since spacing is important, always post your code within code tags, otherwise we can not see well, where you have white space in your code. Please reformat your post accordingly.

Finally, one recommendation: I have the impression that you try to replace your Batch script statement by statement by shell commands. This approach has a good chance to fail. Instead, just destill the idea what your Batch script is supposed to do, and write it from scratch in the shell of your choice.
# 7  
Old 03-27-2018
This might get you started:

Code:
if [ "$EnvName" = "Dev" ]
then
    echo "This is Dev"
fi

usrName=$(grep "User_$EnvName=" "$configFilePath" | cut -d= -f2)
[ -n "$usrName" ] && echo "USER Name $usrName"

Note you didn't show us the contents of $configFilePath my guess is it's something like this:

Code:
Server_Dev=mydevbox
User_Dev=Alice
DB_Dev=devDB

Server_Live=mylivebox
User_Live=Bob
DB_Live=liveDB

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

C Shell script not run with Windows 10

Hi all, I have a script has been writing for Unix or Linux. Now I want to run under Windows 10. is give me Error: if:Badly formed number How to fix this please help *** This is a copy of a part of Script. set absolute_gap = 0 if ($min_p_to_p != "" && $min_p_to_p != "N/A" && $min_p_to_t... (5 Replies)
Discussion started by: dovo
5 Replies

2. Shell Programming and Scripting

Windows batch script to Shell script

Hi everyone, I've below windows batch script which is used to filter the file contents line by line and assign the matched values to the variables in for loop. for /F "tokens=1,3 delims=:" %%A in (%LOG_DIR%\PM_IS_workflow_status.log) do ( set "ATTR_NAME=%%A" if /i "!ATTR_NAME!" EQU "Folder"... (1 Reply)
Discussion started by: Kathraji
1 Replies

3. Shell Programming and Scripting

Unix shell script to Copy files from one Windows server to another Windows server.

Can anybody please help me on how to code for the below requirement: I need to write a shell script (on different unix server) to copy files from multiple folders (ex. BRN-000001) from one windows server (\\boldls-mwe-dev4)to a different windows server(\\rrwin-ewhd04.ecomad.int). This shell... (4 Replies)
Discussion started by: SravsJaya
4 Replies

4. UNIX for Advanced & Expert Users

ftp in shell script from linux to windows XP

Hi, I have 9 different linux based servers and i am automating there healthcheckup by doing ssh and fetching deviations out of it in a single text file. I am doing so by using ssh keygen. I am done with the above part . Now i want to ftp that text file to my windows XP desktop and i want to... (4 Replies)
Discussion started by: gemnian.g
4 Replies

5. Shell Programming and Scripting

Change the Windows Batch script to UNIX shell script.

Hi, When I run the below script in UNIX it's throwing syntax errors. Actually it's a windows batch script. Could anyone change the below Windows Batch script to UNIX shell script... Script: REM :: File Name : Refresh_OTL.bat REM :: Parameters : %1 - Region REM :: : %2 - Cube Type REM ::... (5 Replies)
Discussion started by: tomailraj
5 Replies

6. UNIX for Dummies Questions & Answers

Shell script in windows

I use windows and I wanted to know how I can use shell script in windows. I saw windows power shell but the commands they use seem to be different from those I know as a newbie. For example I wanted to change the permission of a file using chmod, but it doesn't recognise such a command. So I would... (12 Replies)
Discussion started by: #moveon
12 Replies

7. UNIX for Advanced & Expert Users

Executing a shell script from windows;script present in unix

I need to execute a shell script kept in unix machine from windows. User id, password area available. For eg. There's a shell script wich moves all the logs kept in my home directory to a directory named LOGS. Now i need to get this done through windows; either using a batch file, or java... (4 Replies)
Discussion started by: rajneesh_kapoor
4 Replies

8. Shell Programming and Scripting

Renaming putty windows with a shell script

i frequently have to open multiple putty windows to ssh into a unix server running HP-UX 11.23. Since i use some of the windows for dedicated processes i would like to rename them (the caption displayed in the titlebar) to something more convenient than the standard <Host>.<Server>.com While... (4 Replies)
Discussion started by: orno
4 Replies

9. UNIX for Advanced & Expert Users

Executing shell script from Windows FTP

Hello, Any inputs on the possibility of executing a shell script on unix box from Windows FTP TIA (1 Reply)
Discussion started by: B2BIntegrator
1 Replies

10. UNIX for Dummies Questions & Answers

How to execute a shell script from Windows

I like to start a korn job remotely, from windows. I tried REXEC and that is not what I want. Need help !!!! thanks (4 Replies)
Discussion started by: kyawlin
4 Replies
Login or Register to Ask a Question