Execute bash scripts from inside Natural Programs?

We’re at that part of the conversion where we are looking at our RJE submits (IBM/VSE to Suse Linux) and I was trying to execute bash scripts from inside of natural. I am trying to figure out how to change the path to where the script exists, to be able to ./ the bash script, keeps telling me ‘No such file or directory’.
And, I have the permissions set to -rwxrwxrwx , So hopefully that is not the problem. Anyone else execute (bash)scripts from inside of Natural where you have to change the path?

thanks in advance
John

Let’s say you want to execute the script test.bash which is located in the directory /my/dir. You got 2 possiblilities.

#1:

call 'shcmd' '/my/dir/test.bash'

This means: Always work with absolute paths. But then you have to ensure, that your script also uses absolute paths.

#2:
At the moment, the regarding Linux-command is regarded as a spam-word by this forum (See http://natural.forums.softwareag.com/viewtopic.php?p=3023#3023 ). So I’m not able to post it. Maybe I’ll add it later, if the word is removed from the spam-list…

yes, of course.

it depends.
Most of our central-Scripts are located in a central folder and the name of the folder is part of the PATH-Variable. Therefore the script is simply started by its name:


os-command := 'adarep2excel.bsh'
callnat 'USR1052N' usr1052l   
if Response ne 0 
	...
end-if

if it is not a central script one can specify the full path name, as mathias wrote.

some remarks on starting scripts from natural:

  1. use USR1052N instead of SHCMD.
  2. start the script with the nohup-command. otherwise the execution of the script is terminated if the parent process comes to an end.
  3. use the ampersand (&) to indicate that this script has to be executed in batch.
  4. in addition you can specify the keyword [NO]SCREENIO. (see description of USER1052N)

os-command := 'nohup veryLongRunningScript.bsh & NOSCREENIO'
callnat 'USR1052N' usr1052l   
if Response ne 0 
	...
end-if

hth

Why? I cannot find a remark in the Natural documentation that SHCMD should be avoided. http://techcommunity.softwareag.com/ecosystem/documentation/natural/nat623win/pg/pg_furth_syscom.htm

Good hints! By default Natural waits until the shell command terminates. nohup and ampersand are only neccessary, if you want to submit a shell command and you don’t want to wait for its termination.

It seems to be a matter of opinion: if i have the choice to use a “call” or a “callnat” i will always decide to use the callnat.

btw: there are some other things, that should be avoided, not mentioned in the Natural documentation :lol:

Here’s #2:

call 'shcmd' 'cd /my/dir && ./test.bash'

The double-ampersand means: If the change-directory-command was successfull, execute test.bash. This is a suitable solution, if you want to work with relative paths inside your script.

Okay, thanks for all the input.
Let me see if I can get it to work.

Mathias, Still there?? haha, I know its been a few months, but hey such is the nature of this project. Here is what I tried :
Logged in as sag,
call ‘shcmd’ ‘cd Batch && ./NatBatch.bsh’
Then: call ‘shcmd’ 'pwd > /usr/sag/test_path
then I read the file test_path as a work file. What I am getting is /usr/sag as the
current path. I expected to see /usr/sag/Batch but I did not. Seems as though it will only do one shcmd, any subsequent shcmd do not seem to have any effect.
The NatBatch.bsh didnt run either. I cleared out the test_path file so I can tell where my current path is, but it’s always only usr/sag, and I would expect it to be
usr/sag/Batch.
Any thots?

I guess you do the pwd to “debug” the first shcmd.

Every “call ‘shcmd’” starts a new Unix-process. And every Unix-process starts on the home directory.

NatBatch.bsh only starts if the preceding “cd Batch” was successful. Maybe you mistyped the directory name…

Please try the following:

call 'shcmd' 'cd Batch; pwd > /usr/sag/test_path' 

The semicolon means: pwd is executed regardless if “cd Batch” was successful or not.

Mathias,
:lol: Thanks for taking time to show me the correct way, You are the Man…
When I tried your sample I received the correct path in my work file, then I added ./NatBatch.bsh to that same call and it worked perfectly.
Thank you

If a script starts with the command

cd ${0%/*}

it will change the directory to where the script is located.

It looks a bit odd, but the $0 contains the full path and name of the script,
and the %/* strips away the script name leaving only the full path.

From my point of view, this is not completely correct (if we’re talking about the bash). $0 contains the name of the shell. This could be simply “bash” or if you call a script without creating a subshell the name of the initial script.
Please try out the following:

content of ~/test.bash

#!/bin/bash
echo $0
. ~/testdir/test2.bash

content of ~/testdir/test2.bash

#!/bin/bash
echo $0

If you execute ~/test.bash, your output is the following:

~/test.bash
~/test.bash

Ok, thanks again for all the help .

Now that I can submit a script with an absolute value,
I was thinking if I can set up variables which contain the script,
for example:
An online program with a list of reports, that the user will just put an ‘X’ in the first column of the row, where:
Row 1 = __ Report 1
Row 2 = __ Report 2… etc
When user puts an ‘X’ to select a report… My program will put a value to the report name and then submit the ‘shcmd’ .
So I would set up the variable to contain the script like:
Local
1 Report1 (a25) init “/path1/path2/Script1.bsh”
1 Report2 (a25) init “/path1/path2/Script2.bsh”
I Then would do call ‘shcmd’ ‘Report1’ ??
Probably too simple, but that’s what I envisioned,
anyone doing something similar…
I will try and see what happens anyway.
If you have suggestions, as always I appreciate the help…

Results:
I setup a local with initial values equal to the scripts…
when I call USR1052N in order to execute the selected script
It returns an error 127…

[/b]

Delete the quotes around Report.

call 'shcmd' Report1

Of course you can do more complex shcmd-calls. Like that:

define data local
1 #command (A) dynamic const <'ls'>
1 #parameter (A) dynamic const <'-l'>
1 #files (A/1:10) dynamic const <'/etc/hosts','/etc/passwd'>
1 #output-file (A) dynamic const <'/tmp/shcmd-test.txt'>
*
1 #shcmd (A) dynamic
end-define
compress #command #parameter #files(*) ">" #output-file into #shcmd
display #shcmd (AL=78)
call 'shcmd' #shcmd
end

Thanks again Matthias, Looks like I need to check out the documentation on ‘dynamic’ variables… that is exactly what I needed.

The trick is to use a Natural-Alpha-Field which contains the OS-command.

Unfortunately, the Natural for Unix documentation doesn’t mention that.

http://techcommunity.softwareag.com/ecosystem/documentation/natural/nat631unx/pg/pg_furth_syscom.htm

But the documentation for windows does:

http://techcommunity.softwareag.com/ecosystem/documentation/natural/nat631win/pg/pg_furth_syscom.htm

The next thing is to create an OS-command by compressing some components into a target field. Of course you can do this without using dynamic variables…

Thanks for all the pointers/clues but none of the URL’s in these discussions work any more ( The Software AG documentation URL pointers but it’s better than nothing at all )

Anton

:smiley:

To get the links to work you have to insert the latest Natural version.

i.e.

http://techcommunity.softwareag.com/ecosystem/documentation/natural/nat639unx/pg/pg_furth_syscom.htm

http://techcommunity.softwareag.com/ecosystem/documentation/natural/nat639win/pg/pg_furth_syscom.htm

Thanks Matthias for responding because I looked at the “dates of last posts” on all these discussions and it looked a little “dead” to me…

a) Yes, the URL’s to Natural documentation could be adapted , as yuo suggested but
2) URL pointers back into these discussions, can not be “adapted” , such as this URL at the top of these discussions… and my point was :

“What is the point in having these Software AG archive of discussions if the URL’s become obsolete because of documents being moved around on the Software AG server. If you have a plain/vanilla Windows 2000 Server, with NO Tamino, the users can do the same and the documents on the server, will stay in place” :

http://natural.forums.softwareag.com/viewtopic.php?p=3023#3023 )

Note: Information is knowledge/ power but not if you have kids managing it all