Page 4 of 4 FirstFirst ... 234
Results 31 to 33 of 33

Thread: Make executable bash script run with sudo privileges?

  1. #31
    Join Date
    Mar 2010
    Location
    Squidbilly-Land
    Beans
    Hidden!
    Distro
    Ubuntu Mate 16.04 Xenial Xerus

    Re: Make executable bash script run with sudo privileges?

    Something else you should notes is that Catkiller and I come at the problem from slightly different ways. This is because we have different backgrounds, I'd bet. I'm trained as an ASE, worked in that area for about 5 yrs before transitioning more into software. I come from a Unix admin, programming, huge organization background. We tried to be consistent with management of all the different systems. So I will always prefer the more cross-platform technique to solve issues. sudo is cross-platform. I've never heard of pkexec on anything except Linux. If you can use the Linux-specific solutions, it can work.

    Also, I've been burned a few times in scripts when I was lazy and didn't fully specify the path to every command. Someone can change the PATH and bam - a completely different program gets used than the one intended.

    In a script, I'd never use this:
    Code:
    pkexec systemctl reboot --boot-loader-entry=windows
    though I might be tempted to use:
    Code:
    /usr/bin/pkexec  /bin/systemctl  reboot --boot-loader-entry=windows
    When you finally get to the point of automating many things via cron, you'll appreciate this slight difference. It is both for security and to avoid future failures. Using the full path so that the PWD/CWD aren't important for any input to a script is a design best practice. We see people NOT doing that here all the time and they have problems with their scripts. Windows allowed end-users not to really know about PWD, which is critical for anyone doing scripting or programming.

    Anyways, we've beaten this topic enough. Good luck.

  2. #32
    Join Date
    Jan 2020
    Beans
    21

    Re: Make executable bash script run with sudo privileges?

    Thanks, I figured that you two come from different backgrounds. Both of you have lots of history on this forum (I cautiously equate this to knowledge and trustworthiness), and you both proposed different approaches. From an outside/novice perspective, what you describe definitely seems more future proof and logical. But, I'm sure catkiller's way is able to achieve the same end result as defined by me, which is to just get it working. Anyway, I'll consider all of this should I revisit this, but I think I need to take a step back and do some reading and learning via research. Then I will use a raspberry pi as mentioned to attempt some of this stuff as a sandbox.
    Last edited by bingbong6; 1 Week Ago at 06:56 PM.

  3. #33
    Join Date
    Jan 2020
    Beans
    21

    Re: Make executable bash script run with sudo privileges?

    @TheFu

    you don't allow direct messages so I thought I'd ask it here: I don't remember where I found it, but at some point you linked this (your?) website https://blog.jdpfu.com/2014/12/28/learning-linux

    Is there a contact section on there somewhere? Or comment section? On the about page it mentions something about leaving comments.
    Last edited by bingbong6; 1 Day Ago at 07:27 PM.

Page 4 of 4 FirstFirst ... 234

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
  •