Page 1 of 2 12 LastLast
Results 1 to 10 of 17

Thread: Run script at the end of run level 3.

  1. #1

    Default Run script at the end of run level 3.

    Hello I would like to run a script after I am sure that the network interfaces are up. I was thinking that this might be the end of init 3 or init 5.

    In which file should I execute my script?

    Best Regards
    Alex

  2. #2
    Join Date
    Mar 2010
    Location
    Austin - Texas
    Posts
    10,140
    Blog Entries
    48

    Smile Re: Run script at the end of run level 3.

    I am not an expert on what scripts are allowed while in runlevel 3, but you could add a symlink to your script to be run while in rl3 like this in a terminal session:

    Code:
    sudo ln -s /path/to/script/the_script /etc/rc.d/rc3.d/the_script
    You do not copy any scripts to here. A good location for the script might be /usr/local/bin for instance. You must have root privilege to perform this function. You can test your script to make sure it works by going to rl3 in this manner:

    Code:
    su -
    password:
    init 3
    root
    password:
    script_name
    Thank You,
    My Blog: https://forums.opensuse.org/blogs/jdmcdaniel3/

    Software efficiency halves every 18 months, thus compensating for Moore's Law

    Its James again from Austin, Texas

  3. #3
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    24,982

    Default Re: Run script at the end of run level 3.

    When you create a file /etc/init.d/after.local, the commands in this file will be run at the end of any runlevel changing. Thus when you want to run your-script on reaching runlevel 5:
    Code:
    test "$RUNLEVEL" = "5" && /path/to/your-script
    must be there. I leave it to you to let it run on also on reaching runlevel 3. And of course, you may like another contruct then the old fashioned test
    Henk van Velden

  4. #4

    Default Re: Run script at the end of run level 3.

    Quote Originally Posted by hcvv View Post
    When you create a file /etc/init.d/after.local, the commands in this file will be run at the end of any runlevel changing. Thus when you want to run your-script on reaching runlevel 5:
    Code:
    test "$RUNLEVEL" = "5" && /path/to/your-script
    must be there. I leave it to you to let it run on also on reaching runlevel 3. And of course, you may like another contruct then the old fashioned test
    Thank you very much I also tried your approach but are u sure your correct is correct?

    it seems that in my system there is no $RUNLEVEL variable and that is my script does nothing as the test $RUNLEVEL always fail.

    Best Regards
    Alex

  5. #5
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    24,982

    Default Re: Run script at the end of run level 3.

    I am rather sure it is. Please do;
    Code:
    grep RUNLEVEL /etc/init.d/*
    to show yourself that it is used extentive in the scripts.

    I also used this in another case and it worked thare.

    But when you want me to look at what you did (after all you there could be something wrong), you better post what you have there:
    Code:
    ls -l /etc/init.d/after.local
    cat /etc/init.d/after.local
    Henk van Velden

  6. #6

    Default Re: Run script at the end of run level 3.

    I put some start ** to hide some characters

    c****s:/home/**** # ls -l /etc/init.d/after.local
    -rwxr-xr-x 1 root root 113 2011-01-31 14:09 /etc/init.d/after.local
    c****s:/home/a***a # cat /etc/init.d/after.local
    #! /bin/bash
    test "$RUNLEVEL" = "3" && /home/a****/mountmy****orn.sh

  7. #7
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    24,982

    Default Re: Run script at the end of run level 3.

    1) please put computer code between CODE tags (as I did for you): Posting in Code Tags - A Guide.

    2) it is up to you to make a lot of things obscure here, personaly I would only do that with passwords and thngs like e-mail addresses. Let us hope that our debugging is not hampered by reading *s everywhere.

    3) you have only a test on runlevel 3 here. I hope you do boot in runlevel 3 to test this.

    4) this also assums that /home/a****/mountmy****orn.sh is an executable file, did you check?

    5) I suppose you are aware that this will run as root. That means that a script in a place that apparently is owned by a normal user will run as root. That is not a good idea. That user can put everything there that can completely destroy your system.
    Henk van Velden

  8. #8

    Default Re: Run script at the end of run level 3.

    Hello again,
    I did some improvements. I hope it is better now
    Code:
    ls -l /etc/init.d/after.local 
    -rwxr-xr-x 1 root root 113 2011-01-31 14:09 /etc/init.d/after.local

    Code:
    cat /etc/init.d/after.local 
    #!/bin/bash
    test "$RUNLEVEL" = "5" && /root/mountmypart.sh

    Code:
     cat /root/mountmypart.sh 
    #! /bin/bash
    mount /home/myuser/Documents/Documents-Mounted
    Code:
     grep RUNLEVEL /etc/init.d/*
    /etc/init.d/after.local:test "$RUNLEVEL" = "5" && /root/mountmypart.sh
    /etc/init.d/alsasound:  if [ "$RUNLEVEL" = "6" -o "$RUNLEVEL" = "0" ]; then
    /etc/init.d/boot.cleanup:       if test "$1" = "start" -o "$RUNLEVEL" = "6" ; then
    /etc/init.d/kbd:                case "$RUNLEVEL" in
    /etc/init.d/kbd:        case "$RUNLEVEL" in
    /etc/init.d/kbd:        case "$RUNLEVEL" in
    /etc/init.d/kexec:        if [ "$RUNLEVEL" -eq 6 ] ; then
    /etc/init.d/powerfail:  test "$RUNLEVEL" != "S" && exit 0
    /etc/init.d/rc:trap 'test "$RUNLEVEL" = "1" && exit 0' SIGTERM
    /etc/init.d/rc:test "$PREVLEVEL" = "$RUNLEVEL" && exit 0
    /etc/init.d/rc:test "$PREVLEVEL" = "1" -a "$RUNLEVEL" = "S" && exit 0
    /etc/init.d/rc:runrc=/etc/init.d/rc${RUNLEVEL}.d
    /etc/init.d/rc:. /etc/rc.splash $RUNLEVEL
    /etc/init.d/rc:    if test "$RUNLEVEL" != "0" -a "$RUNLEVEL" != "6" ; then
    /etc/init.d/rc:if test "$RUNLEVEL" != "S" ; then
    /etc/init.d/rc:    if test "$RUNLEVEL" = "0" -o "$RUNLEVEL" = "6" ; then
    /etc/init.d/rc:echo -e "switching to runlevel: ${stat}${extd}${RUNLEVEL}${norm}"
    /etc/init.d/rc:splashtrigger "rlchange $RUNLEVEL"
    /etc/init.d/rc:    eval $(startpar $startopt -M stop  -P $PREVLEVEL -R $RUNLEVEL)
    /etc/init.d/rc:case "$RUNLEVEL" in
    /etc/init.d/rc:    eval $(startpar $startopt -M start -P $PREVLEVEL -R $RUNLEVEL)
    /etc/init.d/rc:splashtrigger "rlreached $RUNLEVEL"
    /etc/init.d/rc:echo -e "runlevel ${RUNLEVEL} has been ${stat}${extd}reached${norm}"
    /etc/init.d/rc:    echo -n  "Failed services in runlevel ${RUNLEVEL}: "
    /etc/init.d/rc:    echo -n  "Skipped services in runlevel ${RUNLEVEL}: "
    /etc/init.d/single:     if test -n "$RUNLEVEL" -a "$RUNLEVEL" != "S" ; then
    /etc/init.d/skeleton.compat:    if test -z "$RUNLEVEL"; then read RUNLEVEL REST < <(/sbin/runlevel); fi

  9. #9
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    24,982

    Default Re: Run script at the end of run level 3.

    Well, it was not needed to post the last output. I only gave you that one to see for yourself, I did allready know that RUNLEVEL is used in a lot of places.

    And what you have looks nice to me. Only thing is that when your mountmypart.sh script is that short, the only one statement you have can equaly go directly in after.local:
    Code:
    #!/bin/bash
    test "$RUNLEVEL" = "5" && mount /home/myuser/Documents/Documents-Mounted
    But the fact that you do not tell something like: "it works, thank you" led me to think that it still does not do what you want. Is that true?

    In that case you can do a few things:
    1) check if your script is called, by adding e.g.
    Code:
    date >/tmp/mountmypart-log
    to it. This will create the file /tmp/mountmypart-log with the date/time when the script was called last.

    2) are you sure that mount is correct. Did you check the entry in /etc/fstab that belongs to it?
    Henk van Velden

  10. #10

    Default Re: Run script at the end of run level 3.

    Quote Originally Posted by hcvv View Post
    Well, it was not needed to post the last output. I only gave you that one to see for yourself, I did allready know that RUNLEVEL is used in a lot of places.

    And what you have looks nice to me. Only thing is that when your mountmypart.sh script is that short, the only one statement you have can equaly go directly in after.local:
    Code:
    #!/bin/bash
    test "$RUNLEVEL" = "5" && mount /home/myuser/Documents/Documents-Mounted
    But the fact that you do not tell something like: "it works, thank you" led me to think that it still does not do what you want. Is that true?

    In that case you can do a few things:
    1) check if your script is called, by adding e.g.
    Code:
    date >/tmp/mountmypart-log
    to it. This will create the file /tmp/mountmypart-log with the date/time when the script was called last.

    2) are you sure that mount is correct. Did you check the entry in /etc/fstab that belongs to it?
    I would like to thank you again for your kindness to help me.
    Unfortunately it does not work. I will post back on Monday when I will be back at office

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •