LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
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, 03: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, 05:01 PM   #2
timl
Member
 
Registered: Jan 2009
Location: Sydney, Australia
Distribution: Fedora,CentOS
Posts: 750

Rep: Reputation: 156Reputation: 156
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, 08:33 PM   #3
pintooo15
Member
 
Registered: May 2004
Location: India
Distribution: openSUSE Tumbleweed
Posts: 94

Rep: Reputation: Disabled
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, 05:11 PM   #4
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142
You can just run the script with su
Code:
su -c "/path/to/script"
 
Old 05-02-2016, 09: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, 10:57 AM   #6
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142
"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, 11:51 AM   #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



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 03:52 PM
need help in learning shell scripting usmansamad Linux - Newbie 4 07-30-2009 04:01 AM
Where would a good place to start learning basic programing and scripting? Game Pro Programming 10 03-04-2008 07:06 PM
help me in learning scripting fool_inteligent Linux - General 2 08-20-2002 08:12 PM
Is scripting worth learning ChimpFace9000 Linux - General 3 07-05-2001 04:02 AM

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

All times are GMT -5. The time now is 07:44 AM.

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
Open Source Consulting | Domain Registration