Results 1 to 3 of 3

Thread: running a shell script as root from inside another script

  1. #1
    Join Date
    Nov 2011
    Beans
    30

    running a shell script as root from inside another script

    Hi,

    I designed a plugin for our machine at work. The requirements for the plugin were it had to have a 'launch.sh' file and a file that would do the work (most the time it would be a perl or python script). The plugin works great, but the resulting file of the plugin needs to be moved to a shared windows server.

    For that I've written the following.
    Code:
    #!/bin/bash
    
    mount -t cifs //server/share /mnt -o user=domain/user,password=pass
    cp /file /mnt/destination
    unmount.cifs /mnt
    I decided to attach the code above at the end of launch.sh to move the resulting file from the plugin to windows, but it gave me permission errors. Only 'mount' can be used with the root user.

    So, I created a separate file called 'mount' with the code above in it and placed it in /usr/local/bin and gave it the permissions chmod 755.
    At the bottom of 'launch.sh' I inserted the line...
    Code:
    sudo -u ionadmin mount
    The error I get this time, isn't about permission issues it is...
    Code:
    sudo: no tty present and no askpass program specified
    I realize this means that I didn't provide a password and therefore it couldn't do anything. I didn't mention this earlier, but the reason this process is so important is because the entire pipeline needs to be automated. (I can't run scripts as data comes off the machine...one input, one output)

    I started to do some research on 'sudoers'. I'm not sure if I took this in the right direction, but I went into the sudoer file /etc/sudoers (using visudo) and wrote at the bottom ...
    Code:
    admin ALL=(ALL) NOPASSWD: /usr/local/bin/mount
    I re-ran the script and ...
    Code:
    sudo: no tty present and no askpass program specified
    the same error.

    How can I automate this process? More specifically, how can I run mount as a root user within launch.sh?

    Thanks in advance.
    Last edited by cheerPuncH; September 4th, 2012 at 10:08 PM.

  2. #2
    Join Date
    Apr 2011
    Location
    Maryland
    Beans
    1,461
    Distro
    Kubuntu 12.04 Precise Pangolin

    Re: running a shell script as root from inside another script

    Another Ion Torrent user...nice!

    I don't know if this will specifically help or not, but have a look at the code for the new Ion Cloud Plugin. I think their strategy is to input the password as a variable in the parameters when you launch the plugin. That password can then be passed to the script from there. I really don't know if there's a better, more secure way of doing it, but maybe that's a start?

  3. #3
    Join Date
    Nov 2011
    Beans
    30

    Re: running a shell script as root from inside another script

    Thanks for responding drmrgd!

    It looks like the easiest way to do this is mount from fstab 'noauto' and set 'users' in the options. This way anyone can mount and unmount.

Tags for this Thread

Bookmarks

Posting Permissions

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