Run command as root at startup

Hello
I would need to learn how to run a command at startup as root. Like :
sudo lxterminal --command="sudo powertop"
to run powertop at startup so that i can keep an eye on it. (it's the only example i think of right now, but there are some other)
I've seen some things about tmpfiles.d, but I didn't find anything about running a command. So any help would be very welcome
thanks,
Quentin

Hello,
As I said, there are many commands I would like to run as root at startup, so I have found a more convenient way. I'm "auto-responding", just in case someone needs it and search this topic:
http://askubuntu.com/questions/155791/h … a-password
which consists in creating a script, setting root as owner so that user can't "just run it", and configuring the sudoers not to ask a password for this script, as cris said. Then I can just call the script from the autostart file of LXDE.

Similar Messages

  • [SOLVED] Help, run commands as root in a script

    I was playing with some installs from AUR recently, got tired of compiling and installing all the time. Since I don't do much config,  I decided to make a small script to automate the process
    #!/bin/bash
    makepkg -f PKGBUILD &&
    app=$(ls *.pkg.*) &&
    echo mypass | su -s 'pacman -U $app &'
    the thing is "su -s" do not work and prints out "standard in must be a tty", while I've been using the same script to recompile and install from source and it did work always.
    What should I do to get it running?
    p.s: I don't want any password prompts, nor do I want to make some additional aliases or modify the sudoers file. All I need is this script to execute a command as root and install the app.
    Last edited by tasty_minerals (2011-09-16 09:41:14)

    Mr.Elendig wrote:
    tasty_minerals wrote:
    Ok, I did it. To install a package with "pacman" without any prompts for passwords and yes/no questions.
    #!/bin/bash
    makepkg -f PKGBUILD
    app=$(ls *.pkg.*)
    echo mypass | sudo -S pacman -U --noconfirm $app
    Of course you can do makepkg --install, but I don't want to mess with sudo.
    But your script is messing with sudo in a way worse way than makepkg does...
    People are doing even worse things every single day^^

  • SOLVED: php shell_exec() run command as root?

    is there a way for me to execute a command as root from the php shell_exec() command?  I am trying to create a simple web interface for my phone to preform simple server operations such as restart deamons. 
    in my php file im calling
    $output = shell_exec('/path/to/my/script.py');
    my script will do a /etc/rc.d/insert_daemon restart so it needs to be ran as root
    I have tried to add
    nobody=ALL :/path/to/my/script.py   
    to my sudoers file.  i have also tried using
    chmod 4755 script.py
    chown root   script.py
    on the script.  nothing seems to work for me. 
    I realize this is probably a security risk.  anyone have any suggestions?
    Last edited by murfMan (2010-04-11 17:09:48)

    solved it:
    added
    http ALL=NOPASSWD :/path/to/script.py
    to sudoers
    Last edited by murfMan (2010-04-11 17:13:43)

  • [SOLVED] [sudo] allow user to run commands as root

    Hello,
    I want to run programs like netctl and vpnc as normal user without typing in my password. This is what I've come up with for /etc/sudoers:
    myusername ALL = (root) NOPASSWD: /usr/bin/netctl, /usr/bin/vpnc, /usr/bin/vpnc-disconnect
    But running e.g. "netctl start someprofile" fails because access to the file `someprofile' is denied -- the file is owned by root and only root may read it.
    Doesn't running programs as root also mean that these programs can read files owned by root? Or is this a misconception and I should change permissions to the corresponding files?
    Thanks & Regards
    Edit:
    I just realized, that, with the setup above, "sudo netctl start someprofile" does work without demanding a password. This is nice. But can it be tuned further so that I don't have to prepend "sudo"?
    Last edited by ball (2013-05-23 19:22:17)

    @qinohe:
    I am in group wheel and I already have
    %wheel ALL=(ALL) ALL
    myusername ALL=NOPASSWD: /usr/bin/netctl, /usr/bin/vpnc, /usr/bin/vpnc-disconnect
    So this would be same, wouldn't it?
    I just realized, that "sudo netctl start someprofile" does work without demanding a password. This is nice. But can it be tuned further so that I don't have to prepend "sudo"?
    Last edited by ball (2013-05-23 18:50:46)

  • [Solved]Run shell script as root on startup

    Hi
    How to start shell script as root on startup?
    When i search online it is all about an rc.local, but I do not have a rc.local, and when I make one myself it does not run the shell script.
    Regards
    Frederik
    Last edited by Fred7109 (2015-05-26 20:13:04)

    Thankyou for the answers, I went into problems so could first answer now. The script is supposed to delete sandboxes I have created with the sandfox script, and also start a new sandbox with sandfox.
    Regards
    Frederik

  • [SOLVED]Home directory confusion when running Emacs as root

    Hi, just set up my first Arch system.  I've installed emacs-nox, and it insists on using the .emacs file of the one normal user I have set up, even when I'm not logged in as that user.  Bits in that .emacs file which use a tilde to signify $HOME do point to /root when I'm logged in as root, causing various weirdnesses.
    Here's what --debug-init says when I run emacs as root; if there's anything apart from the complaint about the "missing" (not in /root) haskell-mode files, I'm afraid it means nothing to me
    edit: nope, all of that junk really was about the haskell-mode stuff, so I'm deleting it since that's "fixed" by copying that stuff to /root/.emacs.d.  Now --debug-init tells me nothing and I still have no idea why emacs insists on using the dotfile in /home/j
    Last edited by cuns (2011-12-25 23:21:06)

    I have this issue, too if starting emacs after doing a "su" - when logging in as root it works as expecte. Googling brought the emacs changelog:
    1987-05-12  Richard M. Stallman  (rms at prep)
        * startup.el (command-line): If running under `su',
        use user's original login name to get init file.
        Otherwise use $HOME.
    A workaround would be to define an alias like
    alias emacs='emacs -u root'
    in your root's ".bashrc" (/root/.bashrc).
    Hope that helps,
    greetings
    matse

  • Rc.local, run command as regular user?

    I want to run a command at startup that can't safely be run as root (and I don't want it to be anyway).  The only way I know of to execute a command at startup is rc.local, but that will run the command as root.  I know sudo can be used to run commands as other users.  If I use sudo to change what user the startup command is running as, will that be safe?  In other words, will that effectively make it as if it was being run by a regular user instead of root?  Or is there a better way of doing this?  Thanks.

    You can also put it in your .bashrc, so it will be executed every time you log in. For example, I have it set to mount my external disc if it's plugged but not mounted:
    if [[ -r /dev/disk/by-label/disco-externo && `mount | grep disco-externo | wc -l` -eq 0 ]]
    then
    sudo mount /dev/disk/by-label/disco-externo /mnt/disco-externo
    fi
    If you put the sudo away you can start any command as a regular user under certain circumstances.

  • Danger of running EmelFM2 as root: configuration blown away!

    Say you have a customized EmelFM2 configuration in /home/user/.config/emelfm2/ running as an ordinary user. Close EmelFM2, open up a root terminal and issue the 'emelfm2' command. Then close EmelFM2 and you'll see that the files within /home/user/.config/emelfm2/ are now owned by root! Run EmelFM2 as an ordinary user after this and these files will be overwritten with the default EmelFM2 configuration files, owned again by user rather than root. Your original customized configuration is lost forever ...
    I think I've pinned down where the problem lies in the source: lines 305-307 in 'config/e2_cl_option.c' read:
    if (e2_cl_options.config_dir == NULL)
    usedir = g_getenv ("XDG_CONFIG_HOME");
    If a configuration location isn't specified on the EmelFM2 command line, it defaults the location using $XDG_CONFIG_HOME which will still be set to the user's configuration directory even within a root terminal.
    Any ideas about this, or is it really an upstream bug?

    knopwob wrote:
    how did you open the root terminal? It sounds, like you are using
    su
    instead of
    su -
    Ah yes, yes ... you are so right. Using the latter (forcing a login shell?) indeed works as expected, using /root/.config/emelfm2/ by default.
    So, if I want to run EmelFM2 as root from (say) a keyboard shortcut, Gmrun or an Openbox menu item, what would be the safe way to do this? (I tried gksudo with the -l option, but it doesn't seem to work.)
    Edit: Of course, just 'gksudo emelfm2' should, and seems to, work okay.
    Last edited by ninian (2010-12-23 00:35:42)

  • I get error when I run Terminal /bin/bash: Please run this as root.

    Help!
    Every time I open Terminal I get:
    /bin/bash: Please run this as root.
    [Process completed]
    Any suggestions?

    FLYFI5H wrote:
    Help!
    Every time I open Terminal I get:
    /bin/bash: Please run this as root.
    [Process completed]
    Any suggestions?
    I wonder if there's a permissions problem with your /bin/bash. If you go to the /bin directory (presumably with the Finder's Go -> Go to Folder command, as Terminal isn't working for you), then do a "Get Info" on bash, what do you see as the permissions? Mine shows "system: Read & Write", "wheel: Read only", and "everyone: Read only".
    If you can't run Terminal, your diagnostic options may be limited. Do you have a second Mac that you could use to investigate the problem with this Mac in "target disk mode"?

  • Error running command: /usr/java/bin/java: error execing process: Not enoug

    Error running command: /usr/java/bin/java: error execing process: Not enough space
    In a whole root zfs zone the webconsole service fails to start. This is what I get:
    svc:/system/webconsole:console (java web console)
    State: maintenance since Fri Aug 27 14:32:41 2010
    Reason: Start method exited with $SMF_EXIT_ERR_FATAL.
    See: http://sun.com/msg/SMF-8000-KS
    See: man -M /usr/share/man -s 1M smcwebserver
    See: /var/svc/log/system-webconsole:console.log
    Impact: This service is not running.
    # more /var/svc/log/system-webconsole:console.log
    ^C# more /var/svc/log/system-webconsole:console.log
    [ Aug  6 09:30:40 Disabled. ]
    [ Aug  6 09:30:40 Rereading configuration. ] [ Aug  6 09:30:52 Enabled. ] [ Aug  6 11:32:50 Enabled. ] [ Aug  6 11:33:02 Executing start method ("/lib/svc/method/svc-webconsole start"
    Starting Sun Java(TM) Web Console Version 3.1 ...
    The console is running.
    [ Aug  6 11:33:25 Method "start" exited with status 0 ] [ Aug 27 14:32:15 Enabled. ] [ Aug 27 14:32:28 Executing start method ("/lib/svc/method/svc-webconsole start"
    Error running command: /usr/java/bin/java: error execing process: Not enough spa ce [ Aug 27 14:32:41 Method "start" exited with status 95 ] # df -k
    Filesystem kbytes used avail capacity Mounted on
    / 0 4341506 3761710 54% /
    /dev 8103216 4341506 3761710 54% /dev
    proc 0 0 0 0% /proc
    ctfs 0 0 0 0% /system/contract
    mnttab 0 0 0 0% /etc/mnttab
    objfs 0 0 0 0% /system/object
    swap 2498344 360 2497984 1% /etc/svc/volatile
    /platform/SUNW,T5240/lib/libc_psr/libc_psr_hwcap2.so.1
    8103216 4341506 3761710 54% /platform/sun4v/lib/libc_psr.so.1
    /platform/SUNW,T5240/lib/sparcv9/libc_psr/libc_psr_hwcap2.so.1
    8103216 4341506 3761710 54% /platform/sun4v/lib/sparcv9/libc_psr.so.1
    fd 0 0 0 0% /dev/fd
    swap 2497984 0 2497984 0% /tmp
    swap 2498024 40 2497984 1% /var/run
    Grp-MFNY/billables/RV
    20514816 22 3761710 1% /RV
    Grp-MFNY/billables/TT_DB
    20514816 28 3761710 1% /TT_DB
    Grp-MFNY/billables/tab

    You need to find the java exceptions - most likely in the logs in the /var/log/webconsole/console directory.
    A wild guess is you don't have enough swap space to perform a fork.
    -- Ken

  • How to run commands upon system boot as user?

    How can I as a user run commands upon system boot? In Vixie's cron, one can use the @reboot syntax in a crontab, and the job is ran every time the cron daemon starts. Arch however, uses Dillon's cron which seems not support this feature.

    bwalk wrote:Hmm, does not work, because root owns init, so everything requires root. stb's version is valid, the -s parameter drops privileges to <USER>, spawns a shell and executes <COMMAND>. So, no security problem whatsoever.
    So there is nothing like @reboot in vixiecron?

  • Run script as root

    I want to uninstall Mono and need to run this script:
    #!/bin/sh -x
    #This script removes Mono from an OS X System. It must be run as root
    rm -r /Library/Frameworks/Mono.framework
    rm -r /Library/Receipts/MonoFramework-*
    for dir in /usr/bin /usr/share/man/man1 /usr/share/man/man3 /usr/share/man/man5; do
    (cd ${dir};
    for i in `ls -al | grep /Library/Frameworks/Mono.framework/ | awk '{print $9}'`; do
    rm ${i}
    done);
    done
    I went http://support.apple.com/kb/HT1528?viewlocale=en_US to enable root, but the script still doesn't work.
    I'm not familiar with Unix commands. Please advise.

    To run a Terminal command as root, just preface the command with sudo.
    Example: sudo rm -r /Library/Frameworks/Mono.framework
    or:
    sudo (hit spacebar, drag script file into Terminal window, press return)
    You have to be logged in to an admin account to use sudo. Authenticate with the admin password after entering the first sudo command.

  • Run command when (un)plugging (in) Xbox Controller

    Hey,
    I recently got a USB Xbox 360 Controller and set it up using antimicro and the kernel's xpad driver. Now, I want to start antimicro in the background, when I plug the controller in and stop antimicro when I unplug it.
    Is there a more elegant way than running a bash script at startup which periodically checks lsusb's output and acts accordingly?
    ## command to run when plugged in
    /usr/bin/antimicro --no-tray --hidden
    ## command to run when unplugged
    /usr/bin/pkill antimicro
    [klemens@arch-pc ~]$ lsusb | grep Xbox
    Bus 003 Device 012: ID 045e:028e Microsoft Corp. Xbox360 Controller

    OK, I got the reason why not to use the RUN key, but also got confused using a systemd unit. So far, this is it:
    [klemens@arch-pc ~]$ cat /etc/udev/rules.d/60-xbox-controller.rules /etc/systemd/system/dev-xbox-{in,out}.device
    SUBSYSTEMS=="usb", ATTRS{idVendor}=="045e", ATTRS{idProduct}=="028e", ACTION=="add", SYMLINK+="xbox", ENV{SYSTEMD_WANTS}=="dev-xbox-in.device"
    SUBSYSTEMS=="usb", ATTRS{idVendor}=="045e", ATTRS{idProduct}=="028e", ACTION=="remove", SYMLINK-="xbox", ENV{SYSTEMD_WANTS}=="dev-xbox-out.device"
    [Unit]
    Description=Xbox Controller
    [Service]
    ExecStart=/usr/bin/antimicro --no-tray --hidden
    [Unit]
    Description=Xbox Controller
    [Service]
    ExecStart=/usr/bin/pkill antimicro
    Do I have to use service units? (How) can I put this into a single unit with ExecStart and ExecStop? Obviously, this way it's not working...

  • Running commands as normal user

    Hi.
    Is it possible to do these things?
    Run audio without sudo...
    (Un)mount partitions without sudo...
    Poweroff, or reboot, without sudo...
    For instance, If I run:
    adduser myusername audio
    I'm told that the user already exists. I'm pretty sure nobody would design a system where everything you do needs to be sudo'ed. What am I doing wrong?

    I use pmount/pumount for mounting/unmounting as user.
    I've edited my sudoers file to give my user account access (only on this computer) to issue certain commands without a password. As far as I'm concerned, system commands such as shutdown should only be allowed to run as root. It's just a convenience for me not to have to type my password when using sudo.
    # less /etc/sudoers
    # sudoers file.
    # This file MUST be edited with the 'visudo' command as root.
    # Failure to use 'visudo' may result in syntax or file permission errors
    # that prevent sudo from running.
    # See the sudoers man page for the details on how to write a sudoers file.
    # Host alias specification
    # User alias specification
    # Cmnd alias specification
    # Defaults specification
    # Runas alias specification
    # User privilege specification
    root ALL=(ALL) ALL
    tom ALL=(ALL) ALL
    # Uncomment to allow people in group wheel to run all commands
    # %wheel ALL=(ALL) ALL
    # Same thing without a password
    # %wheel ALL=(ALL) NOPASSWD: ALL
    # Samples
    # %users ALL=/sbin/mount /cdrom,/sbin/umount /cdrom
    # %users localhost=/sbin/shutdown -h now
    tom kiwi = NOPASSWD: /sbin/halt
    tom kiwi = NOPASSWD: /sbin/reboot
    tom kiwi = NOPASSWD: /usr/bin/eject
    tom kiwi = NOPASSWD: /usr/sbin/pm-suspend
    tom kiwi = NOPASSWD: /home/tom/bin/backup
    tom kiwi = NOPASSWD: /etc/rc.d/httpd
    Which says: For the user tom on the computer kiwi allow him to run command /sbin/halt without a password.
    Last edited by BaconPie (2011-01-05 14:43:09)

  • Running commands at boot time (ex: amixer mute)

    Alright, this is out of curiosity (and also a good reference for newbies)
    What are the places you can put commands to run commands on startup, the respective init levels for that place, and whats the "right" way to do it?
    thx

    Just a side question since this topic is here...can that be used to actually run a normal program? There's an interesting PowerPC emulator for the x86 architecture that I found that can successfully run OSX, and I was curious that if I installed it, whether or not I could possibly boot it on startup...

Maybe you are looking for