LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Learning scripting in Fedora (https://www.linuxquestions.org/questions/linux-newbie-8/learning-scripting-in-fedora-4175578653/)

Rigue 04-29-2016 03:51 PM

Learning scripting in Fedora
 
Hi,
I am learning scripting and Linux and I'm trying to create a very simple script that goes through a series of commands that set different aspects of the laptop I am using. It sets an static IP address, loads the wi-fi driver, and it goes to different folders to run certain commands needed to startup certain apps that I need running.

My problem is that to run some of these applications I need to be as super user.
How may I build the script so when a person starts it, he logs in as "su" and then the next commands are executed? I tried placing the "su" command inside the script, and when I test the script, it asks for the password, and after typing it, the script does not execute the next commands I put in the script...

Thank you so much,
RicG

timl 04-29-2016 05:01 PM

Hi,

I think you want to use "sude" rather than "su". This takes you into superuser mode. There is a discussion here:

http://www.linuxquestions.org/questi...do-4175578489/

The only problem I see is that "sude" requires the user's password. I am not sure how to go about this.

Cheers

pintooo15 04-29-2016 08:33 PM

Learning scripting in Fedora
 
you can configure sudoers config file to allow a certain user passwordless access but preferably you should only allow your script itself to be run by that user.

suicidaleggroll 04-30-2016 05:11 PM

You can just run the script with su
Code:

su -c "/path/to/script"

Rigue 05-02-2016 09:28 AM

Thank you all for your inputs.

I tried sude and it did not work. I'm still confused with the difference between "sudo" and "su".

su -c "/path/to/script" worked.

What do I need to use inside the script so when I run it, its output shows spaces in between the steps?

Thanks again

suicidaleggroll 05-02-2016 10:57 AM

"sude" isn't a thing, he probably meant "sudo".

As for the difference between su and sudo:
http://www.howtogeek.com/111479/htg-...tween-sudo-su/

They list some of the advantages of using sudo instead of su, but don't list any of the numerous disadvantages to disabling the root account and granting a regular user unlimited sudo power using their regular password, which irks me a bit.

I don't believe Fedora enables sudo by default, which is why it didn't work. You would need to edit /etc/sudoers to grant sudo access to your user before you could use it.

As for adding blank lines between output, you can use echo:
Code:

$ cat script
echo line 1
echo
echo line 2

$ ./script
line 1

line 2


Rigue 05-02-2016 11:51 AM

It all worked. Thank you very much.
The article was quite educational.
RicG


All times are GMT -5. The time now is 11:09 AM.