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.
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:
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?
Also, since the first line has a space in front of the shebang on the first line, it would not work even if you call the script without specifying a shell when calling the script. The shebang only works if the first two bytes of the file are #!
If you want to call the shell without using the shebang, you need to use the same shell as part of the command to use the script as argument, which in this case is ksh for all scripts. ksh is a different shell than sh.
Last edited by Scrutinizer; 12-08-2017 at 08:58 AM..
Hi,
The line magic number is not considered when the script is calling with a particular shell.
And, in the case of sh, errors seems to be a variable that is empty.
Regards.
Thank you for the reply. That is a useful piece of the puzzle. So in this case, when I was calling script2 with the sh it was ignoring the #!/bin/ksh and using sh to run it.
I'm still unclear why it worked correctly when executing the kicker script from the command line, but not through the scheduler. Both ways it would be explicitly calling the subscripts using sh. I would have expected it to fail in both cases. I think there must be something else at play besides the difference between ksh and sh. I agree that the errors are due to the variable it's trying to compare being empty, but not sure why the variable would be empty when running it with sh through the scheduler, but not with sh from the command line and not with ksh from the scheduler. At this point it's working, so I'll just move on.
Thanks again!
Oh - and to Scrutinizer, thank you also for the reply. In the actual script there isn't the space before the shebang, I must have inadvertently added that while copying and pasting to the post.
Last edited by derndingle; 12-06-2017 at 03:36 PM..
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)
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)
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)
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)
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)
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)
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)
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)
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)