Sponsored Content
Top Forums UNIX for Beginners Questions & Answers Calling subscript with sh vs. ksh Post 303008766 by derndingle on Tuesday 5th of December 2017 04:00:22 PM
Old 12-05-2017
Calling subscript with sh vs. ksh

I ran into an issue today that I was able to resolve, but I don't quite understand why the resolution worked. I'm wondering if anyone can help me make sense of it.

I have a "kicker" script that calls 4 subscripts on a RHEL 6.9 server. It calls the scripts in sequence checking for a 0 exit code from each before running the next.

Both the kicker script and each of the subscripts were written in kornshell and all start with #!/bin/ksh as the first line.

Code:
 #!/bin/ksh 
 sh /opt/scripts/script1.ksh
 rc=$?
 if [[ ${rc} -gt 0 ]]; then
   exit
fi
sh /opt/scripts/script2.ksh
 etc.

This worked fine and as expected when running it from the command line, but generated syntax errors from the subscripts when run via a scheduler (Control-M). The syntax errors were like the following:

Code:
 /opt/scripts/script2.ksh: line 252: [: -eq: unary operator expected
 /opt/scripts/script2.ksh: command substitution: line 288: unexpected EOF while looking for matching `''
 /opt/scripts/script2.ksh: command substitution: line 289: syntax error: unexpected end of file
 /opt/scripts/script2.ksh: command substitution: line 291: unexpected EOF while looking for matching `''
 /opt/scripts/script2.ksh: command substitution: line 292: syntax error: unexpected end of file

The errors made me suspect that it was running using the wrong shell, so I changed the kicker script to call the subscripts using "ksh /opt/scripts/script2.ksh" instead of "sh /opt/scripts/script2.ksh".

The next time the job ran, it ran successfully (both from the command line and through the job scheduler.)

So, while I'm glad my issue is fixed, I'm trying to understand why what I did fixed it.

script2.ksh
has #!/bin/ksh at the top. How does that interact with invoking the script using "sh script" vs "ksh script"? Does one override the other? Am I barking up the wrong tree entirely?

Thanks!

Last edited by rbatte1; 12-06-2017 at 05:56 AM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Calling subscript but sleep halts the main script

Ok, I have written a main script which checks a directory contents every 30 secs then sleeps. The subscript does a usermod, if the user is logged on, it sleeps for 30 secs and then trys again over and over again. Here's the problem. when the subscript is called ./subscript.sh or exec... (1 Reply)
Discussion started by: doublejz
1 Replies

2. Shell Programming and Scripting

calling a PL/SQL stored procedure from KSH

Hi I have a stored procedure which should be called from KSH. Could ayone please help me with this. Thanks (1 Reply)
Discussion started by: BlAhEr
1 Replies

3. Shell Programming and Scripting

calling csh script from ksh shell

hi, I have a csh script, which has setenv X xyz etc My shell is korn Is there some way I can "source" this to have the variables in my current korn shell? thanks (3 Replies)
Discussion started by: JamesByars
3 Replies

4. Shell Programming and Scripting

Get return value from PERL script calling from KSH

All: I am calling a PERL script from KSH. I need specific codes to be returned by the PERL Script. For ex: Ksh ----- result=`test.pl $FILE` My idea is to get the value of result from the test.pl, by specifically making the test.pl to print the return code. Since I had some other print... (1 Reply)
Discussion started by: ucbus
1 Replies

5. Shell Programming and Scripting

calling expect script in ksh is failing via cron

I'm calling an expect script via a ksh script in cron and it is failing. The script runs fine if i run it manually. Does anyone know if it is an issue with compatibilty and if there is a way around it? (2 Replies)
Discussion started by: bhatia
2 Replies

6. Shell Programming and Scripting

calling two procedures from one ksh ???

Hi to all, This is first posting in this forum. I quite new to this KSH....i guess i ll have some fun...:) Well, I have two indivdual korn shell scripts. i m calling PL/SQL stored procedure from korn shell script. It works absolutely fine. Once its completed the log is updated and data is... (5 Replies)
Discussion started by: shashi369
5 Replies

7. Shell Programming and Scripting

calling jar file from ksh

Hi, I have a below command in ksh .... $JAVA_HOME/bin/java -cp "/usr/orabase/product/10.2.0/lib:/usr/java/javajar/common/sched.jar:/usr/orabase/product/10.2.0/jdbc/lib/ojdbc14_g.jar:/usr/orabase/product/10.2.0/jdbc/lib/classes12.jar" com.abrt.smart.Smart I want to know where the... (1 Reply)
Discussion started by: PRKS
1 Replies

8. Shell Programming and Scripting

Calling Function in KSH

I have a script with 2 functions 1) show_menu 2) create Ths show_menu function works fine....... Sort of.... When I select option 2 of the menu the code does a few commands and then calls another function called create. It's at this point that I get "create: not found"..... However,... (2 Replies)
Discussion started by: hxman
2 Replies

9. UNIX for Dummies Questions & Answers

Calling commands with ksh

Hi, I am not able to run below command on linux, it however works on solaris. If anyone knows the reason and a solution for it can you please let me know ? Linux ----- $> ksh 'echo hi' ksh: echo hi: No such file or directory $> which ksh /usr/bin/ksh Solaris ------ $> ksh 'echo... (2 Replies)
Discussion started by: krishnaux
2 Replies

10. Shell Programming and Scripting

Calling Oracle stored procedure from ksh script

Friends, I'm newbie with ksh so wanting some help.... 1. I'm trying to call oracle stored procedure from ksh script by taking variable value from runtime, feed into script and execute procedure. 2. Put name1 and name2 value from script run replacing $3 & $4 I'm trying to put name1 in... (4 Replies)
Discussion started by: homer4all
4 Replies
times(1)							   User Commands							  times(1)

NAME
times - shell built-in function to report time usages of the current shell SYNOPSIS
sh times ksh times DESCRIPTION
sh Print the accumulated user and system times for processes run from the shell. ksh Print the accumulated user and system times for the shell and for processes run from the shell. On this man page, ksh(1) commands that are preceded by one or two * (asterisks) are treated specially in the following ways: 1. Variable assignment lists preceding the command remain in effect when the command completes. 2. I/O redirections are processed after variable assignments. 3. Errors cause a script that contains them to abort. 4. Words, following a command preceded by ** that are in the format of a variable assignment, are expanded with the same rules as a variable assignment. This means that tilde substitution is performed after the = sign and word splitting and file name genera- tion are not performed. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWcsu | +-----------------------------+-----------------------------+ SEE ALSO
ksh(1), sh(1), time(1), attributes(5) SunOS 5.11 15 Apr 1994 times(1)
All times are GMT -4. The time now is 06:36 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy