FedoraForum.org - Fedora Support Forums and Community
Results 1 to 7 of 7
  1. #1
    Join Date
    Sep 2013
    Location
    Norway
    Posts
    5

    Run script(s) at boot as sudo

    I have two scripts I want executed at boot. One of them is used for mounting some folders from a local file server, and therefore require sudo/root privileges, while the other one doesn't require anything special and could maybe be added to /etc/rc.local?

    In short, how do I get the system to run 3 x "sudo mount -t cifs //localip/examplefolder /mnt/examplefolder -o username=lameuser,password=lamepassword,nounix,rw, noserverino,file_mode=0777,dir_mode=0777" at boot?

  2. #2
    Join Date
    Jul 2011
    Location
    Birmingham, UK
    Age
    35
    Posts
    2,761

    Re: Run script(s) at boot as sudo

    Scripts run at boot will run as root unless you explicitly tell them not to.

    As for where to add them, that depends on what they do. File-system mounts should normally be added to /etc/fstab, rather than scripted. More general commands go in configuration files in /etc/systemd/system/*. There are other more specialized locations too, e.g. /etc/udev/rules.d/* for commands relating to hardware devices.

  3. #3
    Join Date
    Sep 2013
    Location
    Norway
    Posts
    5

    Re: Run script(s) at boot as sudo

    Well, I have no experience in any boot scripting, so I would love some guidance as to where to put my two current scripts listed below (usernames and passwords removed of course)

    This is the mount/root script, and if it's run more than once it doesn't seem to **** up anything (years ago I had this one in yum.daily because of ****** fileserver).
    #!/bin/bash
    mount -t cifs //10.0.0.100/video /mnt/video1812 -o username=lameUser,password=lamePassword,nounix,rw, noserverino,file_mode=0777,dir_mode=0777
    mount -t cifs //10.0.0.101/video /mnt/video509 -o username=lameUser,password=lamePassword,nounix,rw, noserverino,file_mode=0777,dir_mode=0777

    This is the regular user script that should only be executed once (at boot), since I don't want multiple SABnzbd+ & SickBeards running.
    #!/bin/bash
    ./SABnzbd-0.7.16/SABnzbd.py -d
    ./Sick-Beard-development/SickBeard.py -d

  4. #4
    Join Date
    May 2011
    Location
    Confoederatio Helvetica (Swissh)
    Age
    38
    Posts
    4,277

    Re: Run script(s) at boot as sudo

    May i assume the machine of concern has a GUI?
    You could place them in /etc/xdg/autostart... well, a .desktop -file to 'Exec=' them.
    See the examples in that folder.

    Not sure if they are execute as root, thought...

    As already stated by Gareth Jones, the mounts sh/could be done in /etc/fstab.
    EFI Cheatsheet :: http://forums.fedoraforum.org/showthread.php?t=298546
    Video Handler Script (VHS) (mass re-encode videos, screenrecorder, console music/webradio player, ...) :: http://forums.fedoraforum.org/showthread.php?t=299182
    Windows 8+ & Fedora 20+ Dualboot :: http://forums.fedoraforum.org/showthread.php?t=298161

  5. #5
    Join Date
    Sep 2013
    Location
    Norway
    Posts
    5

    Re: Run script(s) at boot as sudo

    The machine has always been headless, so no autologin, and I was really hoping not having to start using a gui just for the sake of starting everything automatically in the event of power/ups failure and unexpected reboot.

  6. #6
    Join Date
    Jul 2011
    Location
    Birmingham, UK
    Age
    35
    Posts
    2,761

    Re: Run script(s) at boot as sudo

    As for the cryptically-named scripts, do they need to be run as a specific user? You can still run them on boot, with
    Code:
    su username -c "/path/to/script ARGS…"
    You could put that in /etc/rc.local, if it is still used. I’m not sure about that.

    The best place is to put the command above in a Systemd configuration file in /etc/systemd/system. There are examples of the syntax in /lib/systemd/system/*, but maybe someone more knowledgeable about Systemd can chime in.

  7. #7
    Join Date
    Sep 2013
    Location
    Norway
    Posts
    5

    Re: Run script(s) at boot as sudo

    Quote Originally Posted by Gareth Jones
    As for the cryptically-named scripts, do they need to be run as a specific user? You can still run them on boot, with
    Code:
    su username -c "/path/to/script ARGSÖ"
    You could put that in /etc/rc.local, if it is still used. Iím not sure about that.

    The best place is to put the command above in a Systemd configuration file in /etc/systemd/system. There are examples of the syntax in /lib/systemd/system/*, but maybe someone more knowledgeable about Systemd can chime in.
    The system in question only has one regular user, nothing in particular, I just didn't want SABnzbd+ and SickBeard to run as root when I set it up years and years ago, but the mounts required root/sudo, so I just made two scripts I could run quickly via ssh from my cellphone in the event of a unplanned reboot. I guess I could have used one script if the regular user didn't require password prompt when using sudo, but since I anyways had to do something after a reboot, I went with two separate scripts to start SABnzbd and SickBeard after mounting the fileservers.

Similar Threads

  1. How to run sudo command in the script?
    By borispr in forum Using Fedora
    Replies: 2
    Last Post: 4th July 2012, 03:24 PM
  2. [SOLVED]
    How to Run (not Run in Terminal) bash script with sudo in it?
    By premudriy in forum Using Fedora
    Replies: 2
    Last Post: 6th July 2010, 06:56 PM
  3. Run a script as root at boot
    By charlespierre in forum Using Fedora
    Replies: 2
    Last Post: 27th November 2009, 07:13 PM
  4. run script at boot not as root
    By wijszman in forum Using Fedora
    Replies: 6
    Last Post: 19th August 2005, 10:01 AM
  5. How to run script at boot
    By scorbel in forum Using Fedora
    Replies: 3
    Last Post: 2nd July 2004, 05:11 PM

Tags for this Thread

Posting Permissions

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