Sponsored Content
Top Forums UNIX for Dummies Questions & Answers if statement in shell is not getting fired? Post 302575233 by abhi_123 on Monday 21st of November 2011 02:26:28 AM
Old 11-21-2011
Question if statement in shell is not getting fired?

Hi,
When i am executing the shell script, i am unable to get the dates values substituted for variables &mtd and &wsd.
Please let me know where i am going wrong and please let me know how to get the values of these variables.
I have tried all methods but the if condition is getting fired twice or is not getting recognise and getting statement ignored.
Code:
#!/bin/ksh -x

SOURCE_NAME="$1"

if [ $SOURCE_NAME = "ss" ] 
then
# recursive call for all us_stars sub sources
        $PCR_HOME/bin/update_load_status_dly.sh ss
fi

LOAD_TABLE_NAME=""
WHERE_CLAUSE="where TRADE_DATE= "

case $SOURCE_NAME in
aa) LOAD_TABLE_NAME="aa_TRADE_DLY";;

*)     exit 0;;
esac


sqlplus -s $user/$PASSWORD$ORACLE_SID <<END

       col cd new_value wsd noprint
       col md new_value mtd noprint

DECLARE

BEGIN
       select to_char(max(week_start_date),'dd-mon-yyyy') cd
       from temp
       where run_type='DAILY'
       and loading_stage=0;

       select to_char(max(week_start_date),'dd-mon-yyyy') md
       from temp
       where run_type='DAILY'
       and loading_stage=0;

       if (pcrstage.is_str_source ($SOURCE_NAME))
       then
       update table1 s
       set record_count = record_count + (select count(*)
                     from $LOAD_TABLE_NAME  $WHERE_CLAUSE to_date       ('&mtd','dd-mon-yyyy'))
       where run_type='DAILY'
       and loading_stage=0
       and source='$SOURCE_NAME'
       and week_start_date=to_date('&wsd','dd-mon-yyyy');
       
        else
       update temp1 s
       set record_count = (select count(*)
                     from $LOAD_TABLE_NAME  $WHERE_CLAUSE to_date('&mtd','dd-mon-yyyy'))
       where run_type='DAILY'
       and loading_stage=0
       and source='$SOURCE_NAME'
       and week_start_date=to_date('&wsd','dd-mon-yyyy');
       end if;

       commit;
END;
       
END
       
exit;


Last edited by Scott; 11-21-2011 at 05:13 AM.. Reason: Code tags...
 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Read the entire output fired by ps command

Actually I want to display the entire output fired by ps command. My output gets trucated after 80 chars. Thus, i am not able to see the entire command running when i give a ps -eaf .... Does anyone know how do i display the entire output fired by ps command .. (i.e the command along with... (5 Replies)
Discussion started by: vinithepoo
5 Replies

2. Shell Programming and Scripting

put a shell in for statement

I'm a newbie here, today I've got a problem. Here's the shell: b.sh #!/bin/bash rm -rf $1 a.sh #!/bin/bash for file in '/root/Desktop/test/*' do echo $file sh ./b.sh $file done ls /root/Desktop/test When I sh a.sh, the result is : (2 Replies)
Discussion started by: very.very.sorry
2 Replies

3. Shell Programming and Scripting

Shell case statement

echo -e "Select: \c" read IN pattern="1-20" case $IN in ) echo "Selected: $IN" ;; *) echo "Invalid selection: $IN" ;; esac # sh test Select: 10 Invalid selection: 10 # sh test Select: 2 (6 Replies)
Discussion started by: Ikon
6 Replies

4. Shell Programming and Scripting

If then Else statement in shell script

Hi, I am having a shell Script which i need to modify. I am new to shell scripting , needs help. The Logic which needs to be incorporated is as follows :- The script need to check the length of first Line in a data fine and of the length of the file is > 130 then validated the input... (2 Replies)
Discussion started by: mvichare
2 Replies

5. Shell Programming and Scripting

Conditional Shell Statement

I want to add a conditional statement to a user's .profile file. I have a certain number of users that log in and use the rksh (Restricted Korn Shell). When they log in, it starts a certain program and when they exit this program, the system logs them out. When they are in this program, they can... (2 Replies)
Discussion started by: rjulich
2 Replies

6. Shell Programming and Scripting

shell programming if statement help

Hello i am trying to change every word that starts with "a" or "b" . if it starts with one of the letters i want to add xx rho the end of the word. Example : boy ==> boyxx that what i did so far #!/bin/ksh echo "please enter a word: " read word if || ; then echo "the word is... (6 Replies)
Discussion started by: koricha
6 Replies

7. Shell Programming and Scripting

This find command could have got me fired

Oracle Linux 6.4/Bash shell I am not an expert in find command I wanted to delete all files with extension .dmp which are older than 60 days. So I executed rm command from within find as show below and it deleted ALL THE FILES (even files without any extention) which the user had permission... (4 Replies)
Discussion started by: John K
4 Replies

8. Shell Programming and Scripting

Print statement in shell script

Hi All, when I executed the query in normal unix mode, the output is expected. if I executed the query using shell script, I am not getting the result. not sure whether I need to use dbms_output.put_line or echo. dbms_output.put_line("COUNTRY_CODE"||" "||"SUB_TYPE"||" ... (3 Replies)
Discussion started by: arun888
3 Replies

9. Shell Programming and Scripting

Using shell to generate case statement

Hi Gurus, I have a very weird requirement and have no clue to resolve the issue. please help me get out this difficulty below two tables, table1 contains the column name. D means this column used for the rule. for example: rule 0 is all columns have value, rule1 is col3 and col7 have no value.... (2 Replies)
Discussion started by: Torhong
2 Replies

10. Shell Programming and Scripting

If statement in a shell script

Please see part of a shell script below. #Move folder to HOT folder echo " moving $PRE_OCR_DIR/$BATCHNAME to $HOT_FOLDER_DIR\n" #chmod -R 777 $PRE_OCR_DIR/$BATCHNAME mv $PRE_OCR_DIR/$BATCHNAME $HOT_FOLDER_DIR I wish to write an if statement around the move that if that if $BATCHNAME... (3 Replies)
Discussion started by: worky
3 Replies
wait(1)                                                            User Commands                                                           wait(1)

NAME
wait - await process completion SYNOPSIS
/bin/sh wait [pid...] /bin/jsh /bin/ksh /usr/xpg4/bin/sh wait [pid...] wait [ % jobid...] /bin/csh wait DESCRIPTION
The shell itself executes wait, without creating a new process. If you get the error message cannot fork,too many processes, try using the wait command to clean up your background processes. If this doesn't help, the system process table is probably full or you have too many active foreground processes. There is a limit to the number of process IDs associated with your login, and to the number the system can keep track of. Not all the processes of a pipeline with three or more stages are children of the shell, and thus cannot be waited for. /bin/sh, /bin/jsh Wait for your background process whose process ID is pid and report its termination status. If pid is omitted, all your shell's currently active background processes are waited for and the return code will be 0. The wait utility accepts a job identifier, when Job Control is enabled (jsh), and the argument, jobid, is preceded by a percent sign (%). If pid is not an active process ID, the wait utility will return immediately and the return code will be 0. csh Wait for your background processes. ksh When an asynchronous list is started by the shell, the process ID of the last command in each element of the asynchronous list becomes known in the current shell execution environment. If the wait utility is invoked with no operands, it will wait until all process IDs known to the invoking shell have terminated and exit with an exit status of 0. If one or more pid or jobid operands are specified that represent known process IDs (or jobids), the wait utility will wait until all of them have terminated. If one or more pid or jobid operands are specified that represent unknown process IDs (or jobids), wait will treat them as if they were known process IDs (or jobids) that exited with exit status 127. The exit status returned by the wait utility will be the exit status of the process requested by the last pid or jobid operand. The known process IDs are applicable only for invocations of wait in the current shell execution environment. OPERANDS
The following operands are supported: One of the following: pid The unsigned decimal integer process ID of a command, for which the utility is to wait for the termination. jobid A job control job ID that identifies a background process group to be waited for. The job control job ID notation is applicable only for invocations of wait in the current shell execution environment, and only on systems supporting the job control option. USAGE
On most implementations, wait is a shell built-in. If it is called in a subshell or separate utility execution environment, such as one of the following, (wait) nohup wait ... find . -exec wait ... ; it will return immediately because there will be no known process IDs to wait for in those environments. EXAMPLES
Example 1: Using A Script To Identify The Termination Signal Although the exact value used when a process is terminated by a signal is unspecified, if it is known that a signal terminated a process, a script can still reliably figure out which signal is using kill, as shown by the following (/bin/ksh and /usr/xpg4/bin/sh): sleep 1000& pid=$! kill -kill $pid wait $pid echo $pid was terminated by a SIG$(kill -l $(($?-128))) signal. Example 2: Returning The Exit Status Of A Process If the following sequence of commands is run in less than 31 seconds (/bin/ksh and /usr/xpg4/bin/sh): sleep 257 | sleep 31 & jobs -l %% then either of the following commands will return the exit status of the second sleep in the pipeline: wait <pid of sleep 31> wait %% ENVIRONMENT VARIABLES
See environ(5) for descriptions of the following environment variables that affect the execution of wait: LANG, LC_ALL, LC_CTYPE, LC_MES- SAGES, and NLSPATH. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWcsu | +-----------------------------+-----------------------------+ |Interface Stability |Standard | +-----------------------------+-----------------------------+ SEE ALSO
csh(1), jobs(1), ksh(1), sh(1), attributes(5), environ(5), standards(5) SunOS 5.10 12 Dec 1997 wait(1)
All times are GMT -4. The time now is 09:53 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy