LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Execute different commands at startup (https://www.linuxquestions.org/questions/linux-general-1/execute-different-commands-at-startup-594784/)

lucazorzi 10-26-2007 09:23 AM

Execute different commands at startup
 
Hi everyone,
I'd like to know if it's possible to run different commands at startup, choosing them through GRUB.
I mean, I'd like to have a GRUB entry like "Kubuntu - Normal Boot" and another one "Kubuntu - MythTV".
I'd like "Kubuntu - MythTV" not to launch kdm but just mythtv and another command, which I need to enable bluetooth remote controlling.
I thought I could set up a different runlevel to do so, but it seems a bit complicated.

How can I do that?

jschiwal 10-26-2007 09:49 AM

Check if Ubuntu supports scpm.

lucazorzi 10-26-2007 10:15 AM

It dosn't seem to, as I can't find anything like scpm in the packets.

jschiwal 10-26-2007 02:26 PM

I found this howto posted on one the Ubuntu forum.
http://ubuntuforums.org/showthread.php?t=296808

Another option is to have a variable defined in the "kernel " line of the menu.lst stanza. I think I remember that options not recognized are defined in the environment of the INIT program. Scripts started subsequently may have that variable defined in their environment which could allow for conditional execution in scripts at boot time. I'm not 100% certain. I think there is a howto in the www.tldp.org website on grub or lilo that may verify this, but I wasn't able to find this info scanning the "kernel-parameters.txt" file in the kernel source.

lucazorzi 10-30-2007 10:22 AM

Quote:

Originally Posted by jschiwal (Post 2938000)
I found this howto posted on one the Ubuntu forum.
http://ubuntuforums.org/showthread.php?t=296808

Looks a bit too complicated, it hope there's something easiear to do...
Quote:

Originally Posted by jschiwal (Post 2938000)
Another option is to have a variable defined in the "kernel " line of the menu.lst stanza. I think I remember that options not recognized are defined in the environment of the INIT program. Scripts started subsequently may have that variable defined in their environment which could allow for conditional execution in scripts at boot time. I'm not 100% certain. I think there is a howto in the www.tldp.org website on grub or lilo that may verify this, but I wasn't able to find this info scanning the "kernel-parameters.txt" file in the kernel source.

How can I set it?

nx5000 10-31-2007 10:08 AM

Maybe reading /proc/cmdline from a script and acting accordingly?

lucazorzi 11-01-2007 06:22 AM

Great idea! Thank you!
I'm working on that.

lucazorzi 11-02-2007 07:46 AM

It worked!
I added a new OS in /boot/grub/menu.lst with the 'elisa' parameter, then I put this script in /etc/init.d/ and made a symlink in /etc/rc2.d/ (Ubuntu's default runlevel)
Code:

#!/bin/bash
# This scripts checks /proc/cmdline and looks for the 'elisa' parameter
# If it's found, then it changes KDM's and X's config files to the needed options
# if not, it sets the default settings
#
# Author: Luca Zorzi < luca AT tutto e niente [WITHOUT-SPACES] [DOT] net >
# License: GNU/GPL v2
case "$1" in
  start)
    if [[ `grep elisa /proc/cmdline` != '' ]]
        then
        cd /etc/kde3/
        tar xzf kdm.elisa.tar.gz
        cp /etc/X11/xorg.conf.elisa /etc/X11/xorg.conf
        touch /tmp/elisa
        else
        cd /etc/kde3/
        tar xzf kdm.noelisa.tar.gz
        cp /etc/X11/xorg.conf.elisa /etc/X11/xorg
        touch /tmp/noelisa
        fi
    ;;
  *)
    echo "Usage: /etc/init.d/$NAME {start}" >&2
    exit 2
    ;;
esac

exit 0

I saved in /etc/X11/ 2 xorg.conf, with 2 different settings, with or without the TV enabled, and also tarred the KDM's config dir with and without the autologin for the elisa-only user.

Hope this helps someone.


All times are GMT -5. The time now is 04:16 PM.