return value not coming as expected


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting return value not coming as expected
# 1  
Old 08-12-2011
return value not coming as expected

Hi,
We are using a shell script which is called from COBOL program. Here the program works fine till we are using MicroFocus(MF) COBOL 4 and UNIX AIX 5.3.
Recently we have upgraded to MicroFocus(MF) COBOL 5.1 but same AIX version. now the shell script not working as expected.

The shell script does the following:
Code:
grep -l "some_value" $Dir_name* > $File_name

It should return 0 if its successful and 2 if there is any error. This is coming perfect when we execute it from sample cobol program in MF COBOL 5.1, but not from our existing cobol program which was working till before upgrade. Also shell script is working good if we execute as standalone script.

Could any one help me where it might gone wrong here?

Kindly let me know if further information is required.

Thanks & Regards,
Venkatesh S

Last edited by vbe; 08-12-2011 at 09:13 AM.. Reason: use code tags please - thanks
# 2  
Old 08-12-2011
Well extracting a bit of code from a script isnt of much help for we do not know what makes (it) return a value such as 2 or 0...
If its a script and you havent changed or upgraded the OS then the result should not be affected and it is, reading your last statement so it is more to do with the MFcobol part
# 3  
Old 08-12-2011
Hi,
Thanks for your reply.
Actually this is the first line of the script and based on that return code, we processed some statements in "If" condition.
Our understanding is since the return code is coming wrongly, its not going inside the "If" condition and the part is skipped.

Basically this grep command list the files based on some value given if its part of that file.

Regarding COBOL, one sample program which is in MF COBOL 5.1 is calling the same script correctly. But the existing COBOL program not calling it correctly.

Thanks & Regards
Venkatesh S
# 4  
Old 08-12-2011
Anyway this question about COBOL programming, not about shell or AIX. How we can help you if your script runs without problems on the command line and with problems as a subprocess (if I understand right) from your COBOL program?
# 5  
Old 08-12-2011
You haven't been very clear with what's going on, so what follows may or may not be relevant.

grep is supposed to return 0 if a match is found, 1 if no match is found, and >1 if an error occurs. Testing specifically for 2 is probably not a good idea.

Regards,
Alister
# 6  
Old 08-18-2011
Hi,
Thanks for all for your reply.
Before going into return variables to COBOL, first i would like to know the return variables between grep and ls in UNIX command prompt and shell script.
if i gave grep -l "555" $Dir_name* > $File_name, the return value is '0' if match found, else '1' if no match found.

Similarly, if i gave ls -l /tmp/sh12.sh, the return value is '0' if any file found, else '2' if no file match found.

Is my understanding of this return values correct?

Thanks & Regards,
Venkatesh S
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Return: can only `return' from a function or sourced script

Not sure where the problem is. I can run the script without any issue using the following command. . /opt/app/scripts/cdc_migration.sh But it fails with the below error when I try it this way /opt/app/scripts/cdc_migration.sh /opt/app/scripts/cdc_migration.sh: line 65: return: can only... (1 Reply)
Discussion started by: svajhala
1 Replies

2. Infrastructure Monitoring

Notifications not coming through

Issue: I'm not receiving notifications I can succesfully receive an e-mail if I do this on the command line: /usr/bin/mail -s "NAGIOS HOST ALERT on $HOSTNAME$" rgouette@butlerbros.com but, my command.cfg configuration below, refuses to send an e-mail when I set a service to a critical... (3 Replies)
Discussion started by: rgouette
3 Replies

3. UNIX for Dummies Questions & Answers

Why my find return not expected?

root@intel_5500_server:~# find / -name bin -o -name sbin /usr/bin /usr/lib64/pm-utils/bin /usr/lib64/rpm/bin /usr/sbin /bin /sbin root@intel_5500_server:~# which ovs-pki /usr/bin/ovs-pki why below command return nothing root@intel_5500_server:~# find /... (8 Replies)
Discussion started by: yanglei_fage
8 Replies

4. Shell Programming and Scripting

Result of Catching Return Value from Sub_script.sh to Main_script.sh is not as Expected

Main_script.sh #! /bin/sh ./Sub_script.sh rc=$? echo "Return code from Sub_script.sh : $rc" if ; then echo "$rc = 991" echo "" exit 1 elif ; then echo "$rc = 992" echo "" exit 1 elif ; then echo "$rc = 0" echo "" exit 1 fi (2 Replies)
Discussion started by: duddukuri
2 Replies

5. UNIX for Dummies Questions & Answers

coming out from vi editior

Hi Folks, I have opened a log file through Vi editor in putty itself and I was searching for a pattern in logs , let say 'ABCD' /abcd then I want to come out from vi editor, Please advise what is the command to come out from unix editor..! (1 Reply)
Discussion started by: KAREENA18
1 Replies

6. Emergency UNIX and Linux Support

syslog not coming up

Hi All, I have a whole root zone, tsesbd02-zesbx01. On this zone, syslog service is not coming up. While it is working good on Global zone. Below are commands from tsesbd02-zesbx01 root@tsesbd02-zesbx01:/# svcs -a svc:/system/system-log:default svcs: -a ignored when used with arguments.... (13 Replies)
Discussion started by: solaris_1977
13 Replies

7. UNIX for Dummies Questions & Answers

to pick up the Return Code ( RC) from the mailx command and return it to SAS uisng 's

Hi All, Can anyone please let me know the syntax / how to pick up the Return Code ( RC) from the mailx command and return it to SAS uisng 'system()' function and '${?}'. I am in a process to send the mail automatically with an attachment to bulk users. I have used 'Mailx' and 'Unencode'... (0 Replies)
Discussion started by: manas6
0 Replies

8. Red Hat

Sendmail help on RH 9 - going out but NOT coming in..

Is there not one of us who can help here?? I'm really letting down my pants here - not sure what's going on but if you could foreward this link to a group you may know I would greatly appreciate it. I'm getting this error: May 30 22:18:35 MYSERVERNAME sendmail: j4V2HWka015549: ... (1 Reply)
Discussion started by: angelohl
1 Replies
Login or Register to Ask a Question