Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

korn shell script in rc*.d 1

Status
Not open for further replies.

InigoMontoya

IS-IT--Management
Jun 18, 2003
51
US
I placed a korn shell script in the rc3.d directory. I restarted the workstation and noticed that the script did not run. It looks like it didn't like a set statement i had in the script. This suggests to me that the script was not run under ksh. Are rc scripts limited to bourne shell or am i missing something else?
 
The name of the script is what's important. If it's a startup script, it needs to start with a capital "S". If it's a shutdown script, it starts with a capital "K". The next two characters in the name are usually two numeric digits that control the order that the scripts are run. So, a script with the name [tt]S01myscript[/tt] will run first, or close to first, and a script with the name [tt]S99myscript[/tt] will run almost last.

Hope this helps.

 
It looks like it ran my script. It errored out on the set statement. Which I think is a ksh only command and not available to bourne. Something else is wrong I think. Also I am following the S for start K for kill convention.
 
If you have the following as the first line...
[tt]
#!/usr/bin/ksh
[/tt]
...it shouldn't matter. This will force this script to run with the Korn shell.

Also, "set" is both Bourne and Korn shell. Do a "[tt]man set[/tt]" for info. I think there are some slight differences.

Could you post your script?

P.S. Love your screen name! I love that movie.

 
Yeah it's a great movie...one of my favorites.

Vincini: "He didn't fall! Inconceivable!"
Inigo: "There's that word agen..You kee sayin tha word. I dunna think it means wat you think it means."

I love that line hehehe...:)
Anyway...

Maybe I shouldn't put it in rc3.d I don't think it belongs to any other rc directory though. I want it to be the last script to run. I've given it the name S95oracle.

here's a snippet of the set command it doesn't like:

#!/usr/bin/ksh

set -A part `cat pfile`
set -A user user1 user2 user3
set -A ouser ouser1 ouser2 ouser3
IPATH=/export/home/user/i/
HOSTNAME=`uname -n`
set -A pipe ONE TWO THREE
function usage
{
code...
}
function stop
{
code...
}
function start
{
code...
}

case $1 in
stop) stop ;;
start) start ;;
*) usage ;;
exit
****************************
Obviously i removed whole bunch of things but essentialy that's what it is. Also i've tested this script running it manually and it works (stop and start parameters).
 
set -A not available in Bourne shell

I replied to your post on Unix scripting forum.
It would be helpfull if you didn't cross post.
 
oops didn't notice the #!/usr/bin/ksh line

ksh should run this script ok

A potential source of the "set" error could be the contents of pfile.

 
I'm sorry for cross posting. I thought that perhaps this may be a solaris specific issue that's why I posted it here.
rc3.d in solaris at least i'm pretty sure /usr is mounted. which means my script should have access to ksh. I know the script works since I ran it manually.
are the rc scripts ran as root?
 
The rc3.d scripts are run as the system is coming into run level 3, which is multi user with NFS (2 is defined as multi user w/o NFS). All partitions should be mounted by run level 2, so that shouldn't be a problem.

These scripts are run by the [tt]init[/tt] process, which is run by [tt]root[/tt].

Hmmm ... [tt]pfile[/tt]? You may have something there. Why don't you try changing that first set command to...
[tt]
set -A part `/usr/bin/cat /<path-to-pfile>/pfile`
[/tt]
This may be a PATH problem. I don't think [tt]cat[/tt] is an internal command for the Korn shell. Type &quot;[tt]type cat[/tt] to see if it is or not. It's a &quot;tracked alias for /usr/bin/cat&quot; on my system.

Maybe also try putting a...
[tt]
print &quot;${0}: PATH=${PATH}&quot;
[/tt]
...before the first set and watch for it during boot.

I usually put something like this...
[tt]
echo &quot;Oracle ${1}ing&quot;
[/tt]
...as the first line (after the &quot;#!/usr/bin/ksh&quot; of course) so I can see when each script is being run during boot.

&quot;Have fun storming the castle!&quot;

 
I wrote a small ksh script(#!/usr/bin/ksh) in rc3.d and rebooted the machine. The script is supposed to echo out the current shell: echo The current shell is $SHELL

output during boot up: The current shell is

It looks like it doesn't have a shell. Does any one else find this strange?

&quot;Hello.
My name is Inigo Montoya.
You killed my father.
Prepare to die!&quot;
 
Not necessarily strange. The envirnment that init runs with is very minimal. Try the same test script with just an &quot;[tt]env[/tt]&quot; command in it. This will dump all of the environment.

I think the one that's causing the [tt]set[/tt] problem is the PATH, because if the [tt]cat[/tt] you are using.

See my previous post.

&quot;Sleep well and dream of large women&quot; <-- My favorite line!

 
I've just tried a few things...

the #!/usr... line is being ignored, probably because init is invoking your script. Probably the same reason why $SHELL is not set.

Change your S?? startup script to run the korn shell script.
 
I think this may be it...
the /sbin/rc3 script looks like it executes the scripts in the /etc/rc3.d directory as a parameter to /sbin/sh so regardless if #!/usr/bin/ksh is in the first line it will use /sbin/sh as the shell. Here's a section of /sbin/rc3
**************************
if [ -d /etc/rc3.d ]; then
for f in /etc/rc3.d/K*; do
if [ -s $f ]; then
case $f in
*.sh) . $f ;;
*) /sbin/sh $f stop ;;
esac
fi
done

for f in /etc/rc3.d/S*; do
if [ -s $f ]; then
case $f in
*.sh) . $f ;;
*) /sbin/sh $f start ;;
esac
fi
done
fi
***********************************
I'm thinking of adding another case for korn shell scripts...
***********************************
...
case $f in
*.sh) . $f ;;
*.ksh) /usr/bin/ksh $f start ;;
*) /sbin/sh $f start ;;
esac
...

Any thoughts on this? Will this screw up something? Looks pretty harmless to me.
 
yep that would work, but an OS upgrade might re-install the original script.

Personally, I would leave the rc3 as is, and get the S?? startup script call the korn shell script.

BTW, the S?? should be a sym link to the script in /etc/init.d (but you probably already knew that).
 
Yes, I second these comments!

Leave rc3 as is. This could cause problems later and you might forget you have a little &quot;tweak&quot; in the system scripts.

 
Based on your recomendations I created a short /sbin/sh script that invokes the real (ksh) script instead of tweaking the system rc3 script.
It's working fine now. Thanks for all your help on this.

********
Code:
case $1 in
start)  echo &quot;${0} is coming up...&quot;
        /etc/init.d/gripper $1 > /var/log/grpstrtup.log 2>&1
        ;;
stop)   echo &quot;${0} is coming down...&quot;
        /etc/init.d/gripper $1 > /var/log/grpstrtup.log 2>$1
        ;;
*)      ;;
esac

*******
Wesley: &quot;Really. You're that smart?..&quot;
Vincini: &quot;Have you heard of Plato? Aristotle? Socrates?&quot;
Wesley: &quot;Yes.&quot;
Vincini: &quot;Morons.&quot;
 
Great movie!!! I dug it out last night and will be watching it this weekend!

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top