Sponsored Content
Top Forums Shell Programming and Scripting Change the Windows Batch script to UNIX shell script. Post 302347080 by KenJackson on Monday 24th of August 2009 10:13:30 PM
Old 08-24-2009
It would help to see the format of the files you are reading. I'm not positive what your intent is, but here's a start:
Code:
#!/bin/bash
Region="$1"
CubeType="$2"
CommonPath=/export/home/essbase/OTL_REFRESH
found=

while IFS=, read a b c d e remainder; do
    if [ b = $CubeType ]; then
        Server="$a"
        CubeType="$b"
        Application="$d"
        OTL_Application="$c"
        Database="$e"
        found=yes
        break
    fi
done < $CommonPath/CubeList_$Region.txt

test -z "$found"  &&  { echo "Not found"; exit 1; }

OTLUnLockLog=$CommonPath/Logs/$OTL_Application_UnLock_Object.log

#=============================================================
Unlock_Objects $Server $OTL_Application $Application $Database $OTLUnLockLog

This finds the first line in which the second field matches and exits the loop. I think that's what you want.

The IFS=, sets the very special IFS variable to the single comma character.

The read a b c d e remainder; reads each line into 6 variables, using the commas (the $IFS character) to delimit fields.

The brackets and comparison operator, [, ] and =, need spaces around them (except for the final semicolon);

You really only need the quotes around the variables, "$1", if they contain spaces.

Of course, you still have to translate Unlock_Objects.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

how to convert unix .ksh script to windows .batch script

I am using awk in my .ksh script but when I am trying to run in windows its not recognising awk part of the ksh script , even when I changed it to gawk it does not work, this is how my .ksh and .bat files look like. thanx. #!/bin/ksh egrep -v "Rpt 038|PM$|Parameters:|Begin |Date: |End... (1 Reply)
Discussion started by: 2.5lt V8
1 Replies

2. Shell Programming and Scripting

FTP from unix shell script to windows

Hi, I m trying to connect/establish FTP from unix shell script to my PC.Below the script i have written #!/bin/ksh ftp -v -n ddcappip01.com << "EOF" user Amit jason bye EOF ------------------------------ERROR-------------------------- but i m getting the below error for the... (4 Replies)
Discussion started by: ali560045
4 Replies

3. 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

4. Windows & DOS: Issues & Discussions

Gawk Script in Windows batch file - Help

Good morning all. I have been running into a problem running a simple gawk script that selects every third line from an input file and writes it to an output file. gawk "NR%3==0" FileIn > FileOut I am attempting to run this command from a batch file at the command line. I have several hundred... (6 Replies)
Discussion started by: 10000springs
6 Replies

5. Shell Programming and Scripting

FTP from windows to unix server using unix shell script

Hi, Is it possible to ftp a huge zip file from windows to unix server using unix shell scripting? If so what command i need to use. thanks in advance. (1 Reply)
Discussion started by: Shri123
1 Replies

6. 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

7. Shell Programming and Scripting

Windows Batch script for Unix commands

I wish to create a folder on a unix server B from my windows box using windows batch script. Below is my windows batch script. @ ECHO OFF ::Enter your Directory name: echo Enter your Directory name: set /p mydir= plink user1@ServerA mkdir %mydir% At plink command i get logged... (7 Replies)
Discussion started by: mohtashims
7 Replies

8. 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

9. 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

10. Shell Programming and Scripting

Batch script to execute shell script in UNIX server

Hi team, My requirement is to transfer pdf files from windows machine to unix server and then from that unix server we should sftp to another server. I have completed the first part i.e From windows to using to unix server with the help of psftp.exe code: psftp user@host -pw password <... (1 Reply)
Discussion started by: bhupeshchavan
1 Replies
sh(1)							      General Commands Manual							     sh(1)

Name
       sh,  for, case, if, while, :, ., break, continue, cd, eval, exec, exit, export, login, read, readonly, set, shift, times, trap, umask, wait
       - command language

Syntax
       sh [ -ceiknrstuvx ] [ arg...  ]

Description
       The command is a command programming language that executes commands read from a terminal or a file.  See Invocation  for  the  meaning	of
       arguments to the shell.

       Commands
       A  simple  command is a sequence of nonblank words separated by blanks (a blank is a tab or a space).  The first word specifies the name of
       the command to be executed.  Except as specified below, the remaining words are passed as arguments to the invoked  command.   The  command
       name  is  passed as argument 0.	For further information, see The value of a simple command is its exit status if it terminates normally or
       200+status if it terminates abnormally.	For a list of status values, see

       A pipeline is a sequence of one or more commands separated by |.  The standard output of each command but the last is connected by a to the
       standard input of the next command.  Each command is run as a separate process; the shell waits for the last command to terminate.

       A  list	is a sequence of one or more pipelines separated by ;, &, && or || and optionally terminated by ; or &.  ; and & have equal prece-
       dence which is lower than that of && and ||, && and || also have equal precedence.  A semicolon causes sequential execution.  An  ampersand
       causes the preceding pipeline to be executed without waiting for it to finish.  The symbol && (||) causes the list following to be executed
       only if the preceding pipeline returns a zero (nonzero) value.  Newlines may appear in a list, instead of semicolons, to delimit commands.

       A command is either a simple command or one of the following.  The value returned by a command is that of the last simple command  executed
       in the command.

       for name [ in word ... ] do list done
	      Each  time  a  for  command  is executed, name is set to the next word in the for word list.  If in word ...  is omitted, in "$@" is
	      assumed.	Execution ends when there are no more words in the list.

       case word in [ pattern [ | pattern ] ...) list ;; ] ... esac
	      A case command executes the list associated with the first pattern that matches word.  The form of the patterns is the same as  that
	      used for file name generation.

       if list then list [ elif list then list ] ... [ else list ] fi
	      The  list  following if is executed and if it returns zero, the list following then is executed.	Otherwise, the list following elif
	      is executed and if its value is zero, the list following then is executed.  Failing that, the else list is executed.

       while list [ do list ] done
	      A while command repeatedly executes the while list and, if its value is zero, executes the do list; otherwise the  loop  terminates.
	      The  value  returned  by a while command is that of the last executed command in the do list.  Use until in place of while to negate
	      the loop termination test.

       ( list )
	      Execute list in a subshell.

       { list }
	      list is simply executed.

       The following words are only recognized as the first word of a command and when not quoted.

	      if then else elif fi case in esac for while until do done { }

       Command substitution
       The standard output from a command enclosed in a pair of back quotes (``) may be used as part or all of a  word;  trailing  new	lines  are
       removed.

       Parameter substitution
       The  character $ is used to introduce substitutable parameters.	Positional parameters may be assigned values by set.  Variables may be set
       by writing

	      name=value [  name=value	] ...

       ${parameter}
	      A parameter is a sequence of letters, digits or underscores (a name), a digit, or any of the characters * @ # ? - $ !.   The  value,
	      if  any, of the parameter is substituted.  The braces are required only when parameter is followed by a letter, digit, or underscore
	      that is not to be interpreted as part of its name.  If parameter is a digit, it is a positional parameter.  If parameter is *  or  @
	      then  all  the  positional parameters, starting with $1, are substituted separated by spaces.  $0 is set from argument zero when the
	      shell is invoked.

       ${parameter-word}
	      If parameter is set, substitute its value; otherwise substitute word.

       ${parameter=word}
	      If parameter is not set, set it to word; the value of the parameter is then substituted.	Positional parameters may not be  assigned
	      to in this way.

       ${parameter?word}
	      If parameter is set, substitute its value; otherwise, print word and exit from the shell.  If word is omitted, a standard message is
	      printed.

       ${parameter+word}
	      If parameter is set, substitute word; otherwise substitute nothing.

       In the above word is not evaluated unless it is to be used as the substituted string.  (So that, for example,  echo  ${d-`pwd`}	will  only
       execute pwd if d is unset.)

       The following parameters are automatically set by the shell.

	      #      The number of positional parameters in decimal.
	      -      Options supplied to the shell on invocation or by set.
	      ?      The value returned by the last executed command in decimal.
	      $      The process number of this shell.
	      !      The process number of the last background command invoked.

       The following parameters are used but not set by the shell.

	      HOME   The default argument (home directory) for the cd command.
	      PATH   The search path for commands (see execution).
	      MAIL   If this variable is set to the name of a mail file, the shell informs the user of the arrival of mail in the specified file.
	      PS1    Primary prompt string, by default `$ '.
	      PS2    Secondary prompt string, by default `> '.
	      IFS    Internal field separators, normally space, tab, and newline.

       Blank interpretation
       After  parameter  and command substitution, any results of substitution are scanned for internal field separator characters (those found in
       $IFS) and split into distinct arguments where such characters are found.  Explicit null arguments ("" or '') are retained.   Implicit  null
       arguments (those resulting from parameters that have no values) are removed.

       File name generation
       Following  substitution,  each  command	word  is scanned for the characters *, ?  and [ .  If one of these characters appears, the word is
       regarded as a pattern.  The word is replaced with alphabetically sorted file names that match the pattern.  If no file name is  found  that
       matches	the pattern, the word is left unchanged.  The character .  at the start of a file name or immediately following a /, and the char-
       acter /, must be matched explicitly.

       *      Matches any string, including the null string.
       ?      Matches any single character.
       [ ... ]
	      Matches any one of the characters enclosed.  A pair of characters separated by - matches any character lexically between the pair.

       Quoting.
       The following characters have a special meaning to the shell and cause termination of a word unless quoted.

	      ;   &   (   )   |   <   >   new line   space   tab

       A character may be quoted by preceding it with a .  
ew-line is ignored.  All characters enclosed between a pair  of  quote  marks  (''),
       except a single quote, are quoted.  Inside double quotes () parameter and command substitution occurs and  quotes the characters  ' " and
       $.

       "$*" is equivalent to "$1 $2 ..."  whereas
       "$@" is equivalent to "$1" "$2" ... .

       Prompting
       When used interactively, the shell prompts with the value of PS1 before reading a command.  If at any time a new line is typed and  further
       input is needed to complete a command, the secondary prompt ($PS2) is issued.

       Input output
       Before  a command is executed, its input and output may be redirected using a special notation interpreted by the shell.  The following may
       appear anywhere in a simple command or may precede or follow a command and are not passed on to the invoked command.   Substitution  occurs
       before word or digit is used.

       <word  Use file word as standard input (file descriptor 0).

       >word  Use  file word as standard output (file descriptor 1).  If the file does not exist, it is created; otherwise it is truncated to zero
	      length.

       >>word Use file word as standard output.  If the file exists, output is appended (by seeking to the end); otherwise the file is created.

       <<word The shell input is read up to a line the same as word, or end of file.  The resulting document becomes the standard input.   If  any
	      character  of word is quoted, no interpretation is placed upon the characters of the document; otherwise, parameter and command sub-
	      stitution occurs, 
ew-line is ignored, and  is used to quote the characters  $ ' and the first character of word.

       <&digit
	      The standard input is duplicated from file descriptor digit; see Similarly for the standard output using >.

       <&-    The standard input is closed.  Similarly for the standard output using >.

       If one of the above is preceded by a digit, the file descriptor created is that specified by the digit (instead of the  default	0  or  1).
       For example,

	    ... 2>&1

       creates file descriptor 2 to be a duplicate of file descriptor 1.

       If  a  command is followed by & then the default standard input for the command is the empty file Otherwise, the environment for the execu-
       tion of a command contains the file descriptors of the invoking shell as modified by input output specifications.

       Environment
       The environment is a list of name-value pairs that is passed to an executed program in the same way as a normal argument list; see and  The
       shell  interacts  with  the  environment  in several ways.  On invocation, the shell scans the environment and creates a parameter for each
       valid name found (except IFS), giving it the corresponding value.  (IFS cannot be set by the environment; it can only be set in the current
       shell  session.)  Executed commands inherit the same environment.  If the user modifies the values of these parameters or creates new ones,
       none of these affects the environment unless the export command is used to bind the shell's parameter to the environment.  The  environment
       seen  by any executed command is thus composed of any unmodified name-value pairs originally inherited by the shell, plus any modifications
       or additions, all of which must be noted in export commands.

       The environment for any simple command may be augmented by prefixing it with one or more assignments to parameters.  Thus these	two  lines
       are equivalent

	      TERM=450 cmd args
	      (export TERM; TERM=450; cmd args)

       If  the	-k  flag  is  set,  all keyword arguments are placed in the environment, even if they occur after the command name.  The following
       prints 'a=b c' and 'c':
       echo a=b c
       set -k
       echo a=b c

       Signals
       The INTERRUPT and QUIT signals for an invoked command are ignored if the command is followed by &; otherwise signals have the values inher-
       ited by the shell from its parent.  (But see also trap.)

       Execution
       Each  time  a command is executed, the above substitutions are carried out.  Except for the special commands listed below, a new process is
       created and an attempt is made to execute the command with an

       The shell parameter $PATH defines the search path for the directory containing the command.  Each alternative directory name  is  separated
       by  a  colon  (:).   The  default  path is :/bin:/usr/bin.  If the command name contains a /, the search path is not used.  Otherwise, each
       directory in the path is searched for an executable file.  If the file has execute permission but is not an a.out file, it is assumed to be
       a  file	containing  shell commands.  A subshell (that is, a separate process) is spawned to read it.  A parenthesized command is also exe-
       cuted in a subshell.

       Special commands
       The following commands are executed in the shell process and, except where specified, no input output redirection  is  permitted  for  such
       commands.

       :      No effect; the command does nothing.
       . file Read and execute commands from file and return.  The search path $PATH is used to find the directory containing file.
       break  [  n  ] Exit from the enclosing for or while loop, if any.  If n is specified, break n levels.
       continue
	      [  n  ] Resume the next iteration of the enclosing for or while loop.  If n is specified, resume at the nth enclosing loop.
       cd     [  arg  ] Change the current directory to arg.  The shell parameter $HOME is the default arg.
       eval   [  arg ... ] The arguments are read as input to the shell and the resulting command(s) executed.
       exec   [  arg ... ] The command specified by the arguments is executed in place of this shell without creating a new process.  Input output
	      arguments may appear and if no other arguments are given cause the shell input output to be modified.
       exit   [  n  ] Causes a noninteractive shell to exit with the exit status specified by n.  If n is omitted, the exit status is that of  the
	      last command executed.  (An end of file will also exit from the shell.)
       export [  name ... ] The given names are marked for automatic export to the environment of subsequently executed commands.  If no arguments
	      are given, a list of exportable names is printed.
       login  [  arg ... ] Equivalent to 'exec login arg ...'.
       read   name ...	One line is read from the standard input; successive words of the input are assigned to the variables name in order,  with
	      leftover words to the last variable.  The return code is 0 unless the end-of-file is encountered.
       readonly
	      [   name ... ] The given names are marked readonly and the values of these names may not be changed by subsequent assignment.  If no
	      arguments are given, a list of all readonly names is printed.
       set    [  -eknptuvx [  arg ... ] ]
	      -e If noninteractive, exit immediately if a command fails.
	      -k All keyword arguments are placed in the environment for a command, not just those that precede the command name.
	      -n Read commands but do not execute them.
	      -t Exit after reading and executing one command.
	      -u Treat unset variables as an error when substituting.
	      -v Print shell input lines as they are read.
	      -x Print commands and their arguments as they are executed.
	      -  Turn off the -x and -v options.

	      These flags can also be used upon invocation of the shell.  The current set of flags may be found in $-.

	      Remaining arguments are positional parameters and are assigned, in order, to $1, $2, and so forth.  If no arguments are  given,  the
	      values of all names are printed.

       shift  The positional parameters from $2...  are renamed $1...

       times  Print the accumulated user and system times for processes run from the shell.

       trap   [   arg  ] [  n  ] ...  The arg is a command to be read and executed when the shell receives signal(s) n.  (Note that arg is scanned
	      once when the trap is set and once when the trap is taken.)  Trap commands are executed in  order  of  signal  number.   If  arg	is
	      absent,  all  trap(s)  n	are reset to their original values.  If arg is the null string, this signal is ignored by the shell and by
	      invoked commands.  If n is 0, the command arg is executed on exit from the shell, otherwise upon receipt of signal n as numbered	in
	      The trap with no arguments prints a list of commands associated with each signal number.

       umask [	nnn  ]
	      The  user  file  creation mask is set to the octal value nnn .  For further information, see If nnn is omitted, the current value of
	      the mask is printed.

       wait   Wait for all child background processes to terminate.  The return code from this command is that returned upon  termination  of  the
	      last process being waited for.

       Invocation
       If  the	first  character  of  argument zero is -, commands are read from $HOME/.profile, if such a file exists.  Commands are then read as
       described below.  The following flags are interpreted by the shell when it is invoked.
       -c string  If the -c flag is present, commands are read from string.
       -s	  If the -s flag is present or if no arguments remain, then commands are read from the standard input.	Shell output is written to
		  file descriptor 2.
       -i	  If  the  -i  flag  is  present or if the shell input and output are attached to a terminal (as told by gtty), then this shell is
		  interactive.	In this case the terminate signal SIGTERM is ignored (so that 'kill 0' does not kill an interactive shell) and the
		  interrupt  signal  SIGINT  is  caught  and  ignored  (so that wait is interruptible).  For further information, see In all cases
		  SIGQUIT is ignored by the shell.

       The remaining flags and arguments are described under the set command.

Restrictions
       If << is used to provide standard input to an asynchronous process invoked by &, the shell becomes confused about naming  the  input  docu-
       ment.  A garbage file is created, and the shell complains about not being able to find the file by another name.

       The command is not 8-bit clean. The command is 8-bit clean.

       VAX Only Restriction
       If  is run from another program (by the system or exec system calls) whose maximum descriptor in use is number 10, the prompt string is not
       printed.

Diagnostics
       Errors detected by the shell, such as syntax errors cause the shell to return a nonzero exit status.  If the shell is being used  noninter-
       actively,  then	execution  of the shell file is abandoned.  Otherwise, the shell returns the exit status of the last command executed (see
       also exit).

Files
See Also
       csh(1), sh5(1), test(1), execve(2), environ(7)

																	     sh(1)
All times are GMT -4. The time now is 11:26 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy