LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Other *NIX Forums > Solaris / OpenSolaris
User Name
Password
Solaris / OpenSolaris This forum is for the discussion of Solaris and OpenSolaris.
General Sun, SunOS and Sparc related questions also go here.

Notices

Reply
 
Search this Thread
Old 11-12-2004, 04:24 PM   #1
desbyleo
Member
 
Registered: Feb 2002
Location: Erie, CO
Distribution: Red Hat 7.1
Posts: 81

Rep: Reputation: 15
Using a Korn shell in rc scripts


Hey Guys,

I have an rc script (for example: /etc/rc3.d/myscript) that I wrote in Korn shell. For example:

#!/bin/ksh

export MYVAR=hello
....


When I reboot the server, I see that it gets an error. In this case, it says that MYVAR=hello is not a valid identifier. This is a consistent error when you are in Born shell.

My question is, why does this script appear to ran in Born shel even when the header has "#!/bin/ksh" ??

Are rc scripts forced to run in Born?
 
Old 11-12-2004, 05:36 PM   #2
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris10, Solaris 11, Mint, OL
Posts: 9,522

Rep: Reputation: 365Reputation: 365Reputation: 365Reputation: 365
This is the expected behaviour, all rc scripts are run by /sbin/sh, which is a statically linked version of bourne shell, one reasong being /usr may not having been mounted yet. The interpreter syntax (#!) is ignored there.
If you need to use ksh or another shell, you can have the rc script calling your own script.
 
Old 11-12-2004, 06:00 PM   #3
desbyleo
Member
 
Registered: Feb 2002
Location: Erie, CO
Distribution: Red Hat 7.1
Posts: 81

Original Poster
Rep: Reputation: 15
Thank you very much!

After looking at this closer, I also found the reason to what you're saying (just incase for others who are wondering):

If you look at the rc scripts, for example: /sbin/rc2
...there's a segment in that scripts that goes like this:

Code:

for f in /etc/rc2.d/S*; do
  if [ -s $f ]; then
    case $f in
      *.sh)   .        $f ;;
      *)      /sbin/sh $f start ;;
    esac
  fi
done
As you can see, things that end in .sh are sourced in /sbin/rc2's /sbin/sh instance, and files that don't are force executed with /sbin/sh.

It now makes sense that you'd have to use a Born script to call a Korn script from rc#.d directories. So in my case, I simply moved my korn script (/etc/rc3.d/S99myscript) to /etc/init.d/myscript and created a new /etc/rc3.d/S99myscript that had this line in it:

Code:
/etc/init.d/myscript
 
Old 11-12-2004, 06:27 PM   #4
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris10, Solaris 11, Mint, OL
Posts: 9,522

Rep: Reputation: 365Reputation: 365Reputation: 365Reputation: 365
By the way, all this is slightly going to be obsoleted with Solaris 10 new service management facility, see
http://www.sun.com/bigadmin/content/...uickstart.html
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Korn shell and Arrays jpc82 Programming 1 06-28-2005 03:27 AM
Arrays in Korn Shell...? vous Programming 1 03-26-2005 02:35 AM
Korn shell script Muzica Solaris / OpenSolaris 4 09-06-2004 01:47 PM
install korn shell namgor Linux - Newbie 1 07-12-2004 03:52 PM
a t&t korn shell 93 shook Linux - Software 4 02-01-2003 02:54 PM


All times are GMT -5. The time now is 09:05 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration