Bash script as root problem

Bill K. Dengler billkd2008 at gmail.com
Sat Mar 16 22:27:45 UTC 2013


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

A little hacky but what about
sudo command_0
sudo command_1
sudo command_2
sudo command_3
sudo command_4
sudo command_5
sudo command_6
su -c "command_7" $USER
sudo command_8
sudo command_9

Bill
On 03/16/2013 06:23 PM, Johnny Rosenberg wrote:
> 2013/3/16 Amichai Rotman <amichai at iglu.org.il>:
>> Maybe by tweaking sudo: create a user, add it to sudoers and
>> allow him to run only the commands you want.
> 
> I'm not sure how that is going to solve the problem, but maybe
> that's because I am not very good at this.
> 
> This is what my problem looks like:
> 
> MyScript.sh: #!/bin/bash
> 
> Command_0 Command_1 Command_2 Command_3 Command_4 Command_5 
> Command_6 Command_7 Command_8 Command_9 # End of script
> 
> Run the script: sudo ./MyScript.sh
> 
> Now all of the ten commands runs as root, right? But let's assume
> that I want Command_7 to run as user. Like this: MyScript.sh: 
> #!/bin/bash
> 
> sudo Command_0 sudo Command_1 sudo Command_2 sudo Command_3 sudo
> Command_4 sudo Command_5 sudo Command_6 Command_7 sudo Command_8 
> sudo Command_9 # End of script
> 
> Run the script: ./MyScript.sh
> 
> I heard somewhere, though, that running commands with sudo in a
> script is not the recommended way to do it. So I guess I need
> something like this (written in some kind of pseudo code): 
> MyScript.sh: #!/bin/bash
> 
> Command_0 Command_1 Command_2 Command_3 Command_4 Command_5 
> Command_6 sudonot Command_7 # don't run this command as root 
> Command_8 Command_9 # End of script
> 
> Run the script: sudo ./MyScript.sh
> 
> 
> Johnny Rosenberg
> 
>> 
>> Amichai.
>> 
>> Sent from my Android Smartphone
>> 
>> On Mar 16, 2013 11:35 PM, "Johnny Rosenberg"
>> <gurus.knugum at gmail.com> wrote:
>>> 
>>> I have a bash script that I am going to run as root (sudo 
>>> script_name), but in that script there is a line that I want to
>>> be executed as a regular user. Is that possible or do I need to
>>> do it the other way around, that is enter sudo at the beginning
>>> of every line except the one that I need to be run as a user?
>>> 
>>> 
>>> Johnny Rosenberg
>>> 
>>> -- ubuntu-users mailing list ubuntu-users at lists.ubuntu.com 
>>> Modify settings or unsubscribe at: 
>>> https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
>> 
>> 
>> -- ubuntu-users mailing list ubuntu-users at lists.ubuntu.com Modify
>> settings or unsubscribe at: 
>> https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
>> 
> 

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (GNU/Linux)
Comment: Using GnuPG with undefined - http://www.enigmail.net/

iQIcBAEBAgAGBQJRRPHhAAoJEE15pHlYNXW//cgP/R9xtQNpo1EhObQr4K2FtL0R
eDeNJvdpM6JrquRVQCWFGBmo9e2mWzaGlwTjDGVVXc0SgRYRZxhxWUilo3APRwpb
vmvUkTZvzJ43F2A8UkXart0IMzbAXv2pKgdmdD4h7Ri723YXKgqmzeDKvukhrXut
INVZ6N/VELw0T6YNgCPFIBnJr4qdlXGfmqSLmgEzH4pwj/mUziGq+ZBLBgiMJOkd
dqbbwCIZzRyo2FSgH1UkAv2r+fyMtLl0c+CqzMRbR5jTv/yK3uPGQoG1QwDbtHwV
HMLcpNXm+2ID+IsQ0BqvE1Pjxo4L/NYm6YK7hQvOLpN+Jc9kREUk4R/SLGGDjyNY
g21HqcyL58aEojFb36yvG+9x2rvCTaKBMZUlsxcqty3alWj+nqzmVh6lg/EEYCP1
nM+Tl5SKsL8+7CVj/8L5aSPKhqiiq/pCt73zAQb9ig/tPQdPRJROA+BWDWJDIMFd
xrHmr9soEqTK9MKudnROvYVBCDjN59EzBjGNxgT5u+KiD854FdXpwjL0VCtDSqcT
/PWKCmux5gGxni0QX/PZg3QZIANk7zkPK4CcQxDw4UMcqhsfhGm78M4AFiKmz8qS
lpEpnnCIUZSRDqhjZsLASfaaN3/HS9A0TA001V16wSABR1jlAwmVphkvXDx7UIlK
+otTIRnnOFKYHOc8Z2E+
=Gmr4
-----END PGP SIGNATURE-----




More information about the ubuntu-users mailing list