Focal Point Banner


As of December 1, 2020, Focal Point is retired and repurposed as a reference repository. We value the wealth of knowledge that's been shared here over the years. You'll continue to have access to this treasure trove of knowledge, for search purposes only.

Join the TIBCO Community
TIBCO Community is a collaborative space for users to share knowledge and support one another in making the best use of TIBCO products and services. There are several TIBCO WebFOCUS resources in the community.

  • From the Home page, select Predict: WebFOCUS to view articles, questions, and trending articles.
  • Select Products from the top navigation bar, scroll, and then select the TIBCO WebFOCUS product page to view product overview, articles, and discussions.
  • Request access to the private WebFOCUS User Group (login required) to network with fellow members.

Former myibi community members should have received an email on 8/3/22 to activate their user accounts to join the community. Check your Spam folder for the email. Please get in touch with us at community@tibco.com for further assistance. Reference the community FAQ to learn more about the community.


Focal Point    Focal Point Forums  Hop To Forum Categories  WebFOCUS/FOCUS Forum on Focal Point     Invoking a Unix Shell Script from a WebFOCUS Procedure

Read-Only Read-Only Topic
Go
Search
Notify
Tools
Invoking a Unix Shell Script from a WebFOCUS Procedure
 Login/Join
 
Gold member
posted
I am looking for an example of invoking a Unix Shell Script from
WebFOCUS Fex Code. I used following. It works successfully but
does not return 33. It returns 0. Is this expected ? If so, how
to get the actual return code of 33 ?

Sample Fex Code:
================
-SET &RC1 = SYSTEM(&LEN,&SCR_NAME,'D4');
-RUN

Sample Shell Script:
===================
#/usr/bin/ksh
echo "Running"
return 33;


WebFOCUS 5.3.3 MRE - Solaris - Sun Web Server - Weblogic
 
Posts: 85 | Registered: December 20, 2005Report This Post
Virtuoso
posted Hide Post
I don't have a Unix Box to test this..but I've coded Unix Script in the past..try putting an !
Before it. Don't know about the ; after.


In Focus since 1993. WebFOCUS 7.7.03 Win 2003
 
Posts: 1903 | Location: San Antonio | Registered: February 28, 2005Report This Post
Guru
posted Hide Post
I've done the following:
  
-UNIX cd /opt/app/ibi52/ibi/apps/dcl
-UNIX dcl.ftp
-TYPE Unix Script Return code is: &RETCODE
-IF &RETCODE NE 0 GOTO ENDTASK;


(Prod: WebFOCUS 7.7.03: Win 2008 & AIX hub/Servlet Mode; sub: AS/400 JDE; mostly Self Serve; DBs: Oracle, JDE, SQLServer; various output formats)
 
Posts: 391 | Location: California | Registered: April 14, 2003Report This Post
Silver Member
posted Hide Post
change the "return 33;" line in your shell script to 'exit 33'
 
Posts: 40 | Registered: March 10, 2004Report This Post
Gold member
posted Hide Post
  
#!/usr/bin/ksh
return 33;


-SET &SHCMD   = '/home/webfocus/samp.sh';
-SET &LSHCMD  = &SHCMD.LENGTH;
-SET &RC1 = SYSTEM(&LSHCMD,&SHCMD,'D8');


I tried SYSTEM, !, UNIX and SPAWN. The SPAWN silently
returned zero no matter what the shell command/script was provided as
an argument. I used the SPAWN with DEFINE and COMPUTE
as stated in the manual and tried to generated a fake report with a
TABLE FILE. No luck. It returned zero.

The SYSTEM, !, UNIX successfully ran the script (I can see the side
effects by writing to some file) but with always zero return code. I tried
getting the return code by assignment, by &RETCODE and by using
-TYPE. I tried by putting return and exit statements in
the script. I tried the return type as D2, D4 and D8.
No luck.

This message has been edited. Last edited by: Govind Jujare,


WebFOCUS 5.3.3 MRE - Solaris - Sun Web Server - Weblogic
 
Posts: 85 | Registered: December 20, 2005Report This Post
Member
posted Hide Post
A couple of ways to achieve this, both a little long-winded:
1. Have your shell script write the return code to a file and have WebFocus -READ the result from the file. If you first test for the existence of the file, using STATE, and don't find it, you also know you have an error.
2. Have your shell script set and export an environment variable, then use the WebFocus FGETENV() subroutine to read that variable.
 
Posts: 15 | Location: New York | Registered: April 02, 2004Report This Post
Gold member
posted Hide Post
I tried follg.

-SET &SHCMD = '/home/webfocus/scr.sh';
-SET &LSHCMD = &SHCMD.LENGTH;
-SET &RC1 = FPUTENV(4,'VAR1',5,'FOCUS','A5');
-SET &RC2 = SYSTEM(&LSHCMD,&SHCMD,'D4');
-SET &RC3 = FGETENV(4,'VAR1',20,'A20');
-RUN

The scr.sh -

#!/usr/bin/ksh
echo $VAR1 > /tmp/out
export VAR1="MODIFY"
echo $VAR1 >> /tmp/out

The /tmp/out showed -

FOCUS
MODIFY

But RC3 came back as 'FOCUS' in the fex code. I guess this is to be expected. Because in Unix the values of shell
variables are not copied back from child process to the parent process (unless you explicitely send them through
a file or pipe or socket .. etc).

I didn't try writing to files because of efficiency concerns ... I guess I will have it give it another thought.


WebFOCUS 5.3.3 MRE - Solaris - Sun Web Server - Weblogic
 
Posts: 85 | Registered: December 20, 2005Report This Post
Gold member
posted Hide Post
Hi Robin,

I been struggling to recollect information about the 'STATE'
that you talked about (to check existence of a file). I am
not able to find it in manuals. Actually that can help me to
certain extent.

Thx,


WebFOCUS 5.3.3 MRE - Solaris - Sun Web Server - Weblogic
 
Posts: 85 | Registered: December 20, 2005Report This Post
Member
posted Hide Post
Govind,

This shows both methods working, and also the usage of STATE:

-* ttest.fex:
FILEDEF SRCFILE DISK out.txt (RECFM V LRECL 80
-DEFAULT &RC3='ABCDEFGH'
-DEFAULT &RC4='ABCDEFGH'
-RUN
!. ./scr.ksh
-RUN

-SET &RC3 = FGETENV(4,'VAR1',20,'A20');
-RUN
STATE ./out.txt
-RUN
-IF &RETCODE EQ 0 GOTO HAVDAT ;
-TYPE File out.txt not found in current directory.
-GOTO ENDIT

-HAVDAT
-READ SRCFILE &RC4.A8.
-TYPE IORET=&IORETURN
-RUN
-TYPE RC3=&RC3
-TYPE RC4=&RC4
-ENDIT


and this is the shell script:
#!/bin/ksh
# scr.ksh
VAR1="MODIFY"; export VAR1
echo $VAR1 > ./out.txt
 
Posts: 15 | Location: New York | Registered: April 02, 2004Report This Post
Gold member
posted Hide Post
Robin, I got follg output. Is RC3 supposed to show up as 'MODIFY' ? I used an absolute path for scr.ksh (because I am in MRE).

 IORET=       0
 RC3=
 RC4=MODIFY

To double check, I introduced a FPUTENV for VAR1 at the top of the fex and saw RC3 getting the value unchanged. I wonder what I am doing wrong. Thx for the tip on 'STATE'.


WebFOCUS 5.3.3 MRE - Solaris - Sun Web Server - Weblogic
 
Posts: 85 | Registered: December 20, 2005Report This Post
Gold member
posted Hide Post
Even though I was not able to make get the return code of the shell script OR get the env variable from shell script using 'FGETENV' .... the 'STATE' command worked proved sufficient in my case. OTOH, I see that all the output of the script is getting pumped into the generated HTML file in the form of comments. That helps me in figuring out what went wrong with the shell script. That ought to be enough in my case.

Thx,


WebFOCUS 5.3.3 MRE - Solaris - Sun Web Server - Weblogic
 
Posts: 85 | Registered: December 20, 2005Report This Post
Member
posted Hide Post
Make sure that you have the dot-space ". " before the shell script command. This should ensure that the environment variable is available to WebFocus.

!. scr.ksh

Robin
 
Posts: 15 | Location: New York | Registered: April 02, 2004Report This Post
Gold member
posted Hide Post
That is what I thought when I looked at the dot (current shell) in your script. Still the env var did not get updated to webfocus.

#!/bin/ksh
# scr.ksh
VAR1="MODIFY"; export VAR1
echo $VAR1 > ./out.txt
echo > /tmp/out.txt
/usr/bin/pwd >> /tmp/out.txt
echo >> /tmp/out.txt
/usr/proc/bin/ptree $$ >> /tmp/out.txt


/tmp/out.txt:

/apps/opt/webfocus/ibi/srv53/wfs/edatemp/ts000011

12707 /apps/opt/webfocus/ibi/srv53/home/bin/edapth.out 8120 /apps/opt/webfocus/
  3355  /apps/opt/webfocus/ibi/srv53/home/bin/tscom3.out pthid3 -traceoff
    3918  sh -c . /usr/webfocus/bin/scr.ksh
      3920  /usr/proc/bin/ptree 3918

From the above, it seems that webfocus is spanning "sh". I do not see how it the value of env var from scr.ksh can propogate back to webfocus.

Thx,


WebFOCUS 5.3.3 MRE - Solaris - Sun Web Server - Weblogic
 
Posts: 85 | Registered: December 20, 2005Report This Post
Member
posted Hide Post
Hmmm. In that case I'm stumped.
 
Posts: 15 | Location: New York | Registered: April 02, 2004Report This Post
Gold member
posted Hide Post
If it has really worked for somebody, may be it is because of something in their environment. May be sh/ksh. May be MRE/self-serv. Anyway, thx for the "STATE" trick.


WebFOCUS 5.3.3 MRE - Solaris - Sun Web Server - Weblogic
 
Posts: 85 | Registered: December 20, 2005Report This Post
Silver Member
posted Hide Post
This is may not help, but I will throw it out there.

FEX Code:

-*-SET &ECHO=ALL;
-*
-UNIX cd /opt/ibiqual/ibi/apps/baseapp
-UNIX ./update.sh
-*

SH Code:

#!/bin/ksh

java update > update.log


WebFOCUS 7.6.11 HF 6 Client Reporting Server/Caster
7.6.11 PDS Server on MVS DB2
1.46R Tandem
7.6.11 IWAY SQL Server 2000
Access
 
Posts: 40 | Location: OKC | Registered: January 10, 2005Report This Post
Gold member
posted Hide Post
This is how we do it running WebFOCUS on Solaris:

-UNIX yourscript
-IF &EXITRC NE 0 THEN GOTO WHATEVER;

of course, yourscript has to set the return code.


WF 7.1.6 moving to WF 7.7, Solaris 10, HTML,PDF,XL
 
Posts: 83 | Location: Dartmouth Hitchcock Medical Center | Registered: April 17, 2003Report This Post
Gold member
posted Hide Post
No luck with 'UNIX' call. EXITRC showed zero even when the script did not exist. I ran -

-UNIX somescriptsomewhere
-RUN
-TYPE EXITRC=&EXITRC


The 'SYSTEM' call is slightly better. Atleast when there is a problem in launching the child
process, it gave a non-zero return code.


WebFOCUS 5.3.3 MRE - Solaris - Sun Web Server - Weblogic
 
Posts: 85 | Registered: December 20, 2005Report This Post
Gold member
posted Hide Post
Remove the "-RUN" and you should see a valid return code, assuming your script sets it.


WF 7.1.6 moving to WF 7.7, Solaris 10, HTML,PDF,XL
 
Posts: 83 | Location: Dartmouth Hitchcock Medical Center | Registered: April 17, 2003Report This Post
Gold member
posted Hide Post
I found nothing about EXITRC in manuals, but it works!! I will take it. Thx for the tip.

fex code:
========
-UNIX /usr/webfocus/somescriptsomewhere.sh
-TYPE EXITRC=&EXITRC


/usr/webfocus/somescriptsomewhere.sh:
====================================
#!/usr/bin/ksh
# Not required to run ptree .. but just for fun to see the processes
/usr/proc/bin/ptree $$
return 33;


Output:
======
12707 /apps/opt/webfocus/ibi/srv53/home/bin/edapth.out 8120 /apps/opt/webfocus/
5444 /apps/opt/webfocus/ibi/srv53/home/bin/tscom3.out pthid3 -traceoff
12855 sh -c /usr/webfocus/somescriptsomewhere.sh > /apps/opt/webfocus
12856 /usr/bin/ksh /usr/webfocus/somescriptsomewhere.sh
12858 /usr/proc/bin/ptree 12856
EXITRC= 33


WebFOCUS 5.3.3 MRE - Solaris - Sun Web Server - Weblogic
 
Posts: 85 | Registered: December 20, 2005Report This Post
  Powered by Social Strata  

Read-Only Read-Only Topic

Focal Point    Focal Point Forums  Hop To Forum Categories  WebFOCUS/FOCUS Forum on Focal Point     Invoking a Unix Shell Script from a WebFOCUS Procedure

Copyright © 1996-2020 Information Builders