Converting DOS Batch file to Shell Script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Converting DOS Batch file to Shell Script
# 1  
Old 02-18-2013
Converting DOS Batch file to Shell Script

Hi,
This is my DOS Batch file.
Code:
@echo off
echo "Program Name               :" %0
rem  echo "Next param                 :" %1
echo "Next param                 :" "Username/Password"
echo "User Id                    :" %2
echo "User Name                  :" %3
echo "Request ID                 :" %4
echo "File Name                  :" %5 
echo "Entity Name                :" %6
echo "Email Address              :" %7
echo "Extract ID                 :" %8
echo "path name                  :" %9

cd %9

echo "Process Output files"
IF NOT EXIST C:\OraOutput GOTO MAPERROR
IF EXIST o%8.out (COPY o%8.out %5.csv) ELSE echo "Output file does not exists"
IF EXIST %5.csv (MOVE %5.csv C:\OraOutput\%5.cvs) ELSE echo "Could not move file to Share Drive"
GOTO ENDPROCESS
:MAPERROR
echo "The Share Directory has not been mapped Contact your System Administrator"
EXIT -1
:ENDPROCESS
echo "Process finished goodbye"

for this DOS Batch file, I have written equivalent shell script file.
Code:
#!/bin/bash
DATAFILE=/OraOutput
@echo off
echo "Program Name               :" $0
#echo "Next param                :" $1
echo "Next param                 :" "Username/Password"
echo "User Id                    :" $2
echo "User Name                  :" $3
echo "Request ID                 :" $4
echo "File Name                  :" $5 
echo "Entity Name                :" $6
echo "Email Address              :" $7
echo "Extract ID                 :" $8
echo "path name                  :" $9

cd $9

echo "Process Output files"
if [ ! -e DATAFILE]; then
 echo "The Share Directory has not been mapped Contact your System Administrator"
else
  if [ -e o$8.out ]; then
     (cp o$8.out $5.csv) 
  else
      echo "Output file does not exists"
  fi
   if [-e $5.csv ]; then
        mv $5.csv $DATAFILE/$5.cvs)
    else  
	    echo "Could not move file to Share Drive"
    fi
	echo "Process finished goodbye"
  fi
exit -1

Please provide suggestion on how i can write script for the same.

Thanks,
# 2  
Old 02-18-2013
Hi,

What else you are expecting as you have already written the script?

Regards,
Ravi
# 3  
Old 02-18-2013
I thought for a while I was the only one not understanding the request...
# 4  
Old 02-18-2013
Your solution was fairly close, below should be correct bash script.

Code:
#!/bin/bash
DATAFILE=/OraOutput
echo "Program Name               :" $0
#echo "Next param                :" $1
echo "Next param                 :" "Username/Password"
echo "User Id                    :" $2
echo "User Name                  :" $3
echo "Request ID                 :" $4
echo "File Name                  :" $5 
echo "Entity Name                :" $6
echo "Email Address              :" $7
echo "Extract ID                 :" $8
echo "path name                  :" $9

cd $9

echo "Process Output files"
if [ ! -d "$DATAFILE" ]; then
  echo "The Share Directory has not been mapped Contact your System Administrator"
  exit 1
else
  if [ -f "o$8.out" ]; then
     cp "o$8.out" "$5.csv"
  else
      echo "Output file does not exists"
  fi
  if [ -f "$5.csv" ]; then
        mv "$5.csv" "$DATAFILE/$5.cvs"
  else  
	echo "Could not move file to Share Drive"
  fi
fi
echo "Process finished goodbye"

# 5  
Old 03-30-2013
hi

i tried this code but while running in putty its cuming output file does nt exist
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Converting the following batch script to Linux shell

I am currently migrating to ubuntu from my windows system. Now I am learing to convert all my batch scripts into linux shell. Although the common commands are more or less similar, but I found it difficult for the following set of commands in windows cmd: setlocal :PROMPT SET /P... (2 Replies)
Discussion started by: net.genere
2 Replies

2. Shell Programming and Scripting

Shell script from batch file

Hi, I am a junior dba and started carrier very new. I have a batch file to create some script of db creation. I want that batch file to convert in .sh file so that I can directly run that in the AIX box to generate those files. Please help me with the code for AIX. Batch file is here: ... (2 Replies)
Discussion started by: dba_aix
2 Replies

3. Shell Programming and Scripting

To run a shell script in remote server from windows batch file

Hi all, i need to run a shell script on remote server. I have created file .bat file in windows server with following code, c:\Users\Desktop\putty.exe -ssh -pw password user@server ./script.sh i need to run the script.sh in my remote server Above command is not working, any... (4 Replies)
Discussion started by: rammm
4 Replies

4. Shell Programming and Scripting

Dos batch script to execute unix shell script

Can anyone help me with a dos batch script to execute a shell script residing in an unix server. I am not able to use ssh. Thanks in advance (2 Replies)
Discussion started by: Shri123
2 Replies

5. UNIX for Dummies Questions & Answers

Unix shell, Dos batch

Is the unix shell script equivalent to dos batch command? Thanks (2 Replies)
Discussion started by: zhshqzyc
2 Replies

6. Windows & DOS: Issues & Discussions

variable in dos batch file

Sir I have a very old cobol programme (source not availble). On execution and invoking some menu commands, depending upon the "pressed menu commands" it is writing certain values into a dos batch file. At the end of cobol file, this batch file gets exeuted. On keying in the Drive from which you... (6 Replies)
Discussion started by: chssastry
6 Replies

7. UNIX for Dummies Questions & Answers

DOS batch file to capture routers log

Hi, Please help to write DOS /Perl script to capture router AAA logs to store in file. RADIUS: id 1, priority 1, host 59.163.6.103, auth-port 1901, acct-port 1902 State: current UP, duration 1928071s, previous duration 0s Dead: total time 2798488914s, count 0 Authen:... (0 Replies)
Discussion started by: patilanna
0 Replies

8. Windows & DOS: Issues & Discussions

dos batch script

We need to write a dos batch script that does following in order numbered below: Connect to all UNIX boxes using IP,userid and password from a file. validate if login was successful check if there is at least 30mb disk space in the home folder of the user Check if there are any processes... (3 Replies)
Discussion started by: chandraachii
3 Replies

9. Windows & DOS: Issues & Discussions

dos batch script

Please dont post duplicate threads :confused: (0 Replies)
Discussion started by: lorcan
0 Replies

10. Shell Programming and Scripting

Converting Shell script to Dos batch files

Hi friends! I am having some simple shell script files to build postgresql database and all. Now i want to convert those scripts to dos batch scripts(to run on windows XP/2000/NT) because there is no need of unix emulation for latest release of postgresql. Please somebody help me. (1 Reply)
Discussion started by: darwinkna
1 Replies
Login or Register to Ask a Question