This discussion is archived
10 Replies Latest reply: Dec 1, 2012 6:16 AM by NorbertB RSS

Solaris 11 - run a simple BASH script on computer startup

user9368043 Newbie
Currently Being Moderated
I need to have a simple BASH script run on my Solaris 11 machine automatically whenever the computer (re)starts. It should be run with root permissions and after the computer has fully booted. What is the easiest way to do that?

Thank you
Dusan
  • 1. Re: Solaris 11 - run a simple BASH script on computer startup
    DarrenMoffat Explorer
    Currently Being Moderated
    Create an SMF service that depends on the svc:/milestone/multi-user-server milestone service.

    In Solaris 11.1 you can use the svcbundle tool to greatly simplify the creation and deployment of the SMF service around your script.
  • 2. Re: Solaris 11 - run a simple BASH script on computer startup
    800381 Explorer
    Currently Being Moderated
    It'd be a a lot easier to place a script in one of the /etc/rc?.d directories that calls the bash script.

    Note that you can't just put a bash script in those directories as the init process will run them as a source of commands for a sh process.
  • 3. Re: Solaris 11 - run a simple BASH script on computer startup
    user9368043 Newbie
    Currently Being Moderated
    Does that mean that I should just put another bash script (which would just call my original bash script) into the /etc/rcX.d folder? Could I place just a link to my original script in there? And which rcX.d folder should I choose (e.g. what number)?

    Thanks a lot.
    Dusan
  • 4. Re: Solaris 11 - run a simple BASH script on computer startup
    DarrenMoffat Explorer
    Currently Being Moderated
    I very strongly recommend you use SMF not a legacy rc script.

    Since you already have the script it is a simple one line command invocation with svcbundle(1M) to get it installed and activated with proper dependencies. Unlike on Solaris 10 and Solaris 11, with svcbundle in Solaris 11.1 you don't have to create an XML manifest file for an SMF service it is really just a simple single run of svcbundle.

    While an rc script can still work using SMF ensures you get better notification should your script fail - you can get an SMTP message or SNMP trap sent if the script fails - so the service will be in maintenance. The buildin dependency system in SMF ensures you can run your script at the correct point in the start up graph - with legacy rc scripts you are guessing where the correct place is.
  • 5. Re: Solaris 11 - run a simple BASH script on computer startup
    user9368043 Newbie
    Currently Being Moderated
    Unfortunately it seems like I've got Solaris 11.0 installed.

    uname -a

    returns

    SunOS NAS 5.11 11.0 i86pc i386 i86pc

    What do I do to install the script as a SMF service? Or is there an easy way to upgrade to 11.1?

    Thank you
    Dusan
  • 6. Re: Solaris 11 - run a simple BASH script on computer startup
    800381 Explorer
    Currently Being Moderated
    user9368043 wrote:
    Does that mean that I should just put another bash script (which would just call my original bash script) into the /etc/rcX.d folder? Could I place just a link to my original script in there? And which rcX.d folder should I choose (e.g. what number)?

    Thanks a lot.
    Dusan
    You wouldn't use a bash script at all. Look at what's already in, for example, /etc/rc2.d

    It'd be a sh script

    See "man init.d"
  • 7. Re: Solaris 11 - run a simple BASH script on computer startup
    800381 Explorer
    Currently Being Moderated
    darrenm wrote:
    I very strongly recommend you use SMF not a legacy rc script.

    Since you already have the script it is a simple one line command invocation with svcbundle(1M) to get it installed and activated with proper dependencies. Unlike on Solaris 10 and Solaris 11, with svcbundle in Solaris 11.1 you don't have to create an XML manifest file for an SMF service it is really just a simple single run of svcbundle.

    While an rc script can still work using SMF ensures you get better notification should your script fail - you can get an SMTP message or SNMP trap sent if the script fails - so the service will be in maintenance. The buildin dependency system in SMF ensures you can run your script at the correct point in the start up graph - with legacy rc scripts you are guessing where the correct place is.
    Why?

    Just because SMF provides dependency capabilities doesn't mean the OP needs to use them.

    Having a hammer doesn't make every problem a nail.
  • 8. Re: Solaris 11 - run a simple BASH script on computer startup
    user9368043 Newbie
    Currently Being Moderated
    The following command:

    who -r

    returns the following result:

    *. run-level 3 Nov 22 17:50 3 0 S*

    e.g. the run-level at which the computer normally runs should be 3.

    I have therefore put a script named S01UPDATECRON with the following content:

    *#!/usr/sbin/sh*

    source /usr/local/bin/util/setup_cron.sh

    into the */etc/rd3.d* directory and made it executable.

    Is that right?

    Thank you
    Dusan
  • 9. Re: Solaris 11 - run a simple BASH script on computer startup
    NorbertB Newbie
    Currently Being Moderated
    Hi user9368043
    Yes, that should be right, and be intended this way.
    See /etc/rc3.d/README and the following part from smf(5):
    ----------
    Legacy Startup Scripts
    Startup programs in the /etc/rc?.d directories are executed
    as part of the corresponding run-level milestone:
    /etc/rcS.d milestone/single-user:default
    /etc/rc2.d milestone/multi-user:default
    /etc/rc3.d milestone/multi-user-server:default
    ----------
    Your question concerning upgrading to Solaris 11.1:
    In the Gnome menus, you should look for (and start)
    System --> Administration --> Update Manager
    Let it do its work. It will give you a new boot environment, containing Solaris 11.1. Possibly, you have to perform upgrading twice. With "beadm activate", see beadm(1M), you can go back to Solaris 11.0 whenever you want.
    "Local" parts of your zfs root pool, like /usr/local, home directories, /root, and so on, should be in separated file systems, and be mounted outside the root pool before upgrading. They are availlable then from any boot environment, and will not be duplicated. See more in zfs(1M), zpool(1M).
    I strongly recommend upgrading. Solaris 11.1 is great.
  • 10. Re: Solaris 11 - run a simple BASH script on computer startup
    NorbertB Newbie
    Currently Being Moderated
    Correction:
    Since Solaris 11 you have to upgrade from a terminal with pkg, due to necessity of "--accept". Become root, then
    pkg update --accept
    Follow the instructions.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points