LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-29-2016, 04:51 PM   #1
Rigue
LQ Newbie
 
Registered: Dec 2014
Posts: 9

Rep: Reputation: Disabled
Post 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
 
Old 04-29-2016, 06:01 PM   #2
timl
Member
 
Registered: Jan 2009
Location: Sydney, Australia
Distribution: Fedora,CentOS
Posts: 628

Rep: Reputation: 144Reputation: 144
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
 
Old 04-29-2016, 09:33 PM   #3
pintooo15
Member
 
Registered: May 2004
Location: India
Distribution: openSUSE Tumbleweed and SLED 12 SP2
Posts: 94

Rep: Reputation: 31
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.
 
Old 04-30-2016, 06:11 PM   #4
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,556

Rep: Reputation: 2116Reputation: 2116Reputation: 2116Reputation: 2116Reputation: 2116Reputation: 2116Reputation: 2116Reputation: 2116Reputation: 2116Reputation: 2116Reputation: 2116
You can just run the script with su
Code:
su -c "/path/to/script"
 
Old 05-02-2016, 10:28 AM   #5
Rigue
LQ Newbie
 
Registered: Dec 2014
Posts: 9

Original Poster
Rep: Reputation: Disabled
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
 
Old 05-02-2016, 11:57 AM   #6
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,556

Rep: Reputation: 2116Reputation: 2116Reputation: 2116Reputation: 2116Reputation: 2116Reputation: 2116Reputation: 2116Reputation: 2116Reputation: 2116Reputation: 2116Reputation: 2116
"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
 
Old 05-02-2016, 12:51 PM   #7
Rigue
LQ Newbie
 
Registered: Dec 2014
Posts: 9

Original Poster
Rep: Reputation: Disabled
It all worked. Thank you very much.
The article was quite educational.
RicG
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Question about learning scripting petrus4 Programming 5 05-05-2010 04:52 PM
need help in learning shell scripting usmansamad Linux - Newbie 4 07-30-2009 05:01 AM
Where would a good place to start learning basic programing and scripting? Game Pro Programming 10 03-04-2008 08:06 PM
help me in learning scripting fool_inteligent Linux - General 2 08-20-2002 09:12 PM
Is scripting worth learning ChimpFace9000 Linux - General 3 07-05-2001 05:02 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:47 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration