[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^^

Similar Messages

  • 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)

  • 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.

  • [SOLVED] Trouble Running Ksniffer as root

    so i installed ksniffer on my kde desktop... if i run ksniffer it runs fine however when i run sudo ksniffer i get this message and it crashes.
    kdeinit: Can't connect to the X Server.
    kdeinit: Might not terminate at end of session.
    No protocol specified
    kded: cannot connect to X server :0
    DCOP aborting call from 'anonymous-3509' to 'kded'
    kded: ERROR: Communication problem with kded, it probably crashed.
    No protocol specified
    ksniffer: cannot connect to X server :0
    DCOP aborting call from 'anonymous-3500' to 'ksniffer'
    ksniffer: ERROR: Communication problem with ksniffer, it probably crashed
    not sure how to fix it and have been googleing it all day with no luck i assume its a simple fix but dont know how to
    Last edited by nijani (2012-09-27 21:58:25)

    well that worked for it to get started... thank you. i still cant seem to get packets from wlan0 but let me make sure its the same problem before i decide its working

  • [SOLVED] Help needed with suspend2ram with acpid lid script

    Hello
    I'm hoping someone can help with this, I'm obviously configuing something incorrectly.
    I wish to have my machine suspend to ram upon closing the lid, which I've managed to acomplish with pm-utils and acpid.
    Here's my lm-lid.sh from /etc/acpi/actions:
    #! /bin/sh
    # lid button pressed/released event handler
    #/usr/sbin/laptop_mode auto
    /usr/sbin/pm-suspend
    As you can see; I have commented out the penultimate line, this is what was present in the file as default, this didn't cause the machine to do anything, so I added the bottom line to call pm-suspend.
    My machine suspends fine, however, upon waking again, it resumes for about 3 seconds, then suspends again... after which it wakes up fine.
    So esentially I have to wake it up twice.
    I'm sure it's probably something stupid I'm doing, I'd just appreciate any words on this that may help!
    Last edited by Starfall (2012-06-23 23:31:00)

    LoBo3268715 wrote:
    Hi Starfall, I'm no expert here but what does your /etc/acpi/handler.sh look like? I never had to add "/usr/sbin/pm-suspend" to my lm_lid.sh
    #!/bin/sh
    # Default acpi script that takes an entry for all actions
    minspeed=`cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_min_freq`
    maxspeed=`cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq`
    setspeed="/sys/devices/system/cpu/cpu0/cpufreq/scaling_setspeed"
    set $*
    case "$1" in
    button/power)
    #echo "PowerButton pressed!">/dev/tty5
    case "$2" in
    PBTN|PWRF)
    logger "PowerButton pressed: $2"
    poweroff
    logger "ACPI action undefined: $2"
    esac
    button/sleep)
    case "$2" in
    SLPB|SBTN)
    echo -n mem >/sys/power/state
    logger "ACPI action undefined: $2"
    esac
    ac_adapter)
    case "$2" in
    AC|ACAD|ADP0)
    case "$4" in
    00000000)
    echo -n $minspeed >$setspeed
    #/etc/laptop-mode/laptop-mode start
    00000001)
    echo -n $maxspeed >$setspeed
    #/etc/laptop-mode/laptop-mode stop
    esac
    logger "ACPI action undefined: $2"
    esac
    battery)
    case "$2" in
    BAT0)
    case "$4" in
    00000000)
    logger 'Battery online'
    00000001)
    logger 'Battery offline'
    esac
    CPU0)
    *) logger "ACPI action undefined: $2" ;;
    esac
    button/lid)
    case "$3" in
    close)
    logger 'LID closed'
    /usr/sbin/pm-suspend <<<<<<<<<<<<<<<<<<<<<< I put it here
    open)
    logger 'LID opened'
    logger "ACPI action undefined: $3"
    esac
    logger "ACPI group/action undefined: $1 / $2"
    esac
    # vim:set ts=4 sw=4 ft=sh et:
    Awesome! It works perfectly!
    Thanks very much LoBo3268715!

  • [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

  • Please help: Running a java script form the windows command line.

    Hello forum,
    I'm trying to run a java script from the command line on
    windows but I always get the "Failed to open document" alert.
    I typed the following in the run command line:
    "flash.exe" C:\Documents and Settings\Hasan.Atieh\My
    Documents\science\java scripts\testing jsfl\get_files_mx2004.jsfl
    now I copied and pasted the path of my java script file from
    the windows explorer address bar so I'm sure that the java script
    file exists in the specified path.
    Any thoughts why am I getting the message!!

    :oops: never mind... issue resolved. I didn't quote the java
    script file path but thats because the help documents on flash
    didn't say that.
    this is what flash help say:
    To run a script from the command line on Windows:
    Use the following syntax (add path information as required):
    "flash.exe" myTestFile.jsfl

  • Installed iTunes on a 1TB drive designated H:. Bought a 3TB drive designated G:. Downloaded iTunes update. On "Run" command, it will not let me change the destination drive, so it registers an error, and will not update. Help

    Installed iTunes on a 1TB drive designated H:. Bought a 3TB drive designated G:. Downloaded iTunes update. On "Run" command, it will not let me change the destination drive, so it registers an error, and will not update. App freezes, windows says to upgrade it.

    I went to Edit>Preferences>Advanced, G: is showing as the destination drive.

  • Su vs sudo : run dolphin as root[SOLVED]

    Hi,
    I am trying to understand the difference in how su and sudo work.
    I tried to run dolphin as root to add a mount point at /media/drivex
    with su :
    I type dolphin at the prompt
    and I get this error
    <unknown program name>(2348)/: KUniqueApplication: Cannot find the D-Bus session server: "Did not receive a reply. Possible causes include: the remote application did not send a reply, the message bus security policy blocked the reply, the reply timeout expired, or the network connection was broken."
    <unknown program name>(2347)/: KUniqueApplication: Pipe closed unexpectedly.
    dolphin doesnt work
    however,
    when I use sudo dolphin from a regular user,
    dolphin works even though I get a number of errs
    Error: "/var/tmp/kdecache-myx" is owned by uid 1000 instead of uid 0.
    kdeinit4: preparing to launch /usr/lib/libkdeinit4_kbuildsycoca4.so
    kbuildsycoca4 running...
    this is repeated a few times, as though it keeps retrying.
    1.Anyway why does su not work when sudo does?
    2. So when does one use su vs sudo?
    3. I did this yesterday and was able to add a mnt point for my esata drive. Today, I had to do it again. The mount point had disappeared. what may have happened?
    thanks
    Last edited by myxolam (2009-10-16 11:27:15)

    The only reason I use "su" (as "su -") is to create a new, clean session, just as logging in with that user.
    Using "sudo", or "su" without the dash creates a new environment inheriting the session variables from the current user, thus GUI apps can work fine (as they have inherited the $DISPLAY, $DBUS_SESSION_BUS_ADDRESS and other variables used by X applications).
    Anyway, as an alternative to "su", you could use "sudo -i".
    Another difference which is applicable to Ubuntu and maybe Arch, is that "su"ing to root you are asked for the root password, while using "sudo" you are asked for your password, not the "root" one.

  • [solved] hook to run commands when user logs in? (before bash profile)

    Is there any way to run commands when a user logs in but before the bash profile is sourced?
    For example, I have a user account with a home directory on /tmp. When the user logs in, the home directory might not exist so there will be no .bash_profile to source. I want to run a script to create the directory if necessary and copy some files into it. How can that be done?
    I thought of putting something in /etc/profile or /etc/profile.d/, but I would like to run something before the user's shell and environment become active.
    I can use /etc/rc.local to do what I want, but I would prefer a hook to ensure that everything is set right when the user logs in.
    Any ideas?
    *edit*
    Solution
    In my case, I found that I could write my own shell script and set it as a login shell. In the script, I can configure everything I need before launching the interactive shell, then clean up anything after it exits.
    Last edited by Xyne (2011-12-10 19:34:07)

    Thanks, dammannj. PAM could probably do what I need but I think I have found a simpler solution (see original post).

  • 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"?

  • [SOLVED]Help with sudoers file?

    I haveing alot of trouble with my sudoers file. I would like to run the utility rkhunter as a cron job. But it must be run as root. So i wont to give myself the privledge to use it without a passwd. But when i us the line "%wheel ALL=(ALL) NOPASSWD: /usr/bin/rkhunter" it does not work. Out of curiosity i put the ALL parameter and that did not work either o,0 Either something has gone very wrong or Im in need of a lesson in sudo'ing. Can someone help? btw i looked at tutorials on the web and from what i can see im doing everything right. and before you suggest i checked that rkhunter is in /usr/bin/. here is my sudoers file.
    EDIT: removed the comment in the first line i did not have that there when i ran it.
    # 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
    generic 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
    Last edited by generic_ (2009-06-11 13:38:41)

    rkhunter is not is /usr/sbin i checked specifically for that before i tried doing it in sudo. Its output is
    bash:/usr/bin/rkhunter: Permission Denied
    I tried your suggestion xyne with no luck. I double checked and im in the wheel group. The problem is, it is important I see the output the of rkhunter, if i didn't it would be pointless, and annoying to check the log. Also rkhunter has breaks in its output that require me to press enter to continue. So it will never finish if i dont see it. My plan is to have pop up in a terminal in front of me do its job, finish, and thats it. I was thinking I can use a simple shell script with the command. "urxvt -e rkhunter -c" Then run that shell script as a cron job. Can I get the results I want in the root crontab? Im also new to cron as well. Ive been using linux for while and I have little experience with both of these programs. Its time to learn them.
    Thanks for your effort so though,
    Last edited by generic_ (2009-06-11 11:35:41)

  • [SOLVED]kexec into arch fails : root device not found

    Hello,
    I have a fresh arch install with only base, base-devel and openssh.
    I boot on penbuntu, at this point I can see my devices in /dev.
    Then I mount my root arch partition on /mnt/rootfs and do :
    kexec --load /mnt/rootfs/boot/vmlinuz-linux --initrd=/mnt/rootfs/boot/initramfs-linux.img --command-line="root=/dev/sda3 ro vesa video=vesafb"
    which returns :
    setup_linux_vesafb: 1280x720x32 @ 10028000 +708000
    I then do kexec -e, It seems to start loading the kernel since the screen is cleared and each time it does
    [0.845500] i8042: No controller found
    :: running early hook [udev]
    :: running hook [udev]
    :: Triggering uevents...
    Waiting 10 seconds for device /dev/sda3 ...
    ERROR: device '/dev/sda3' not found. Skipping fsck.
    ERROR: Unable to find root device '/dev/sda3' /
    You are being dropped to a recovery shell
    Type 'exit' to try and continue booting
    sh: can't access tty: job control turned off
    [rootfs /]#
    I tried everything as root in the kexec --command-line, root=LABEL, root=UUID but it always do exactly the same thing, waits for 10s for device and then ERROR and drops to the recovery shell.
    Any idea of what's going on ? Why can't it see devices ?
    EDIT : If that can help, the kernel from which I am kexecing is 2.6.24.3 and If I try to just chroot I notice :
    mount -t proc proc proc/
    mount -t sysfs sys sys/
    Works but when I :
    mount -o bind /dev dev/
    It returns :
    mount: mounting /dev on dev/ failed: Invalid argument
    So somehow I think when the kernel loads it has trouble passing the /dev along and therefore sees no devices. But I still can't figure out what to do.
    Thanks in advance
    Last edited by Nolhian (2012-07-28 17:47:30)

    I can't because I'm booting on penbuntu and not arch linux. Anyways the command used in the wiki is similar to the one I'm using.

  • [SOLVED] cannot run Conky on KDE4

    I cannot start Conky on KDE4.
    Arch Linux Conky Manual says FEH must be installed and ~/.kde/share/autostart/fehconky must be created as follows:
    #!/bin/bash
    feh --bg-scale `dcop kdesktop KBackgroundIface currentWallpaper 1`
    I have installed FEH. Then I have created the links into .kde4 directory, because KDE4 supports this one. However Arch Linux installation with KDE4 does not include dcop but dbus. And there is no web link / information I could find, which states that how dbus must be started accordingly.
    I have also created a symlink (as stated in the page above):
    ln -s /usr/bin/conky ~/.kde4/share/autostart/conkylink
    , however when I reboot or relogin, KDE does not seem to start these programs. As a root I have not found any log file in /var/log containing why these programs cannot be started.
    For experiment, I have copied both files into ~/.kde4/Autostart, but in this case KDE4 cannot find dcop and Desktop Environment aborts to login prompt again.
    How can I start feh? Do I need it in KDE4? DBUS daemons seem to be running
    [arutku@hostarchlinux ~]$ ps -ef | grep dbus
    dbus 2999 1 0 Sep05 ? 00:00:01 /usr/bin/dbus-daemon --system
    root 3715 1 0 Sep05 ? 00:00:00 /usr/bin/dbus-daemon --fork --print-pid 5 --print-address 7 --session
    root 3716 1 0 Sep05 ? 00:00:00 dbus-launch --autolaunch 559d1c801aa546c24bf5f91048c00573 --binary-syntax --close-stderr
    arutku 3764 1 0 Sep05 ? 00:00:00 /usr/bin/dbus-daemon --fork --print-pid 5 --print-address 7 --session
    arutku 3765 1 0 Sep05 ? 00:00:00 dbus-launch --sh-syntax --exit-with-session
    arutku 4104 3870 0 00:29 pts/1 00:00:00 grep dbus
    [arutku@hostarchlinux ~]$
    Do I really need to start FEH then?
    Any help appreciated because there is no information in web I could find.
    dbus is not in DAEMONS list in /etc/rc.conf. And, maybe it helps:
    [arutku@hostarchlinux ~]$ uname -a
    Linux hostarchlinux 2.6.26-ARCH #1 SMP PREEMPT Tue Aug 26 21:15:43 UTC 2008 i686 AMD Athlon(tm) XP 2800+ AuthenticAMD GNU/Linux
    EDIT: Fixed typos
    Last edited by pencuse (2008-09-06 00:07:07)

    I have solved the problem by running
    update-desktop-database
    both for the user and the root. I don't know for which user solved this utility the problem but it solved. I think it corrected MIME settings of the operating system. Before I had run this utility, icons for the files could not be shown, files could not be associated and KDE complained inode/* MIME types in /usr/share/packages/kde.xml.
    However this utility solved the problems. Without any FEH installation/scripting stated in Conky Wiki of Arch Linux, Conky runs automatically now.
    ~/.kde4/Autostart for KDE4 is the correct directory now to autostart Conky or any other application.
    HTH.

Maybe you are looking for

  • How  to get the value of multi-select in the   Dashboard Prompt

    I have a multi-select prompt in the Dashboard Prompt,  what I want is,   how do I know that user has choose one value, for examle,  for some reasons,  if user didn't choose any value,  then I will set one column in answer as "customer office" , if us

  • GR/IR account issue

    friends, we have a one gr/ir account which is showing hefty amounts in debir side and credit side, afterr exploring the all documents we found that it is having some documents where debit entry and credit entry is posting the same gl account, these d

  • How do I reinstall firefox on iPhone 3GS

    I lost firefox during sync

  • Audio-visual synching

    im just getting to grips with my new macbook pro and final cut express. have a fairly basic problem with the latter as when i capture video, the video and audio are not in synch when played back. the video runs about four five seconds after the audio

  • Creative Cloud download problem: asking to verify an email that is not mine

    Hello, I'm trying to download adobe creative cloud but a box keeps coming up saying that you've sent a verification email to an email address that is not mine. My email address is [email protected] and it is already verified. Please help. I'm trying