LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 05-13-2014, 10:56 PM   #1
tmtkobedmx8
LQ Newbie
 
Registered: Jul 2012
Posts: 6

Rep: Reputation: Disabled
Unhappy How to redirect txt file to password input in a script?


I am trying to change my /etc/hosts with /etc/hosts.template

the command i'm running is

sudo echo "/etc/hosts.template" > /etc/hosts < password.txt

I keep getting /etc/hosts : permission denied

Im not sure what I am doing wrong.

Any help will be very appreciated. Thanks
 
Old 05-13-2014, 11:23 PM   #2
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and CentOS
Posts: 6,724

Rep: Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705
Hi,

can you explain in words what you re trying to do? The command you posted makes no sense to me.

My best guess is the following
Code:
sudo cp /etc/hosts.template /etc/hosts
But this really is just a guess.

Evo2.
 
1 members found this post helpful.
Old 05-14-2014, 12:10 AM   #3
tmtkobedmx8
LQ Newbie
 
Registered: Jul 2012
Posts: 6

Original Poster
Rep: Reputation: Disabled
hi

I am trying to write a script to automate a LAN installation. It's just an experiment for a class project. So what I did was create a hosts.template file for the hosts file so that when the script runs, it replaces the hosts file with the hosts.template which holds more hosts that the default hosts file. Thanks
 
Old 05-14-2014, 12:20 AM   #4
tmtkobedmx8
LQ Newbie
 
Registered: Jul 2012
Posts: 6

Original Poster
Rep: Reputation: Disabled
Hey evo2,

I just tried
Quote:
sudo cp /etc/hosts.template /etc/hosts
and it seems to do the trick, but i get prompted for a password. I was wondering if it is possible to include the password in a file within the script so that i don't have to enter it manually?

Thanks

Tmtkobedmx8
 
Old 05-14-2014, 12:39 AM   #5
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
Quote:
Originally Posted by tmtkobedmx8 View Post
it seems to do the trick, but i get prompted for a password
hmm.
if this is an automated script to set up a lan network, it should have root access already.
so your mistake is somewhere earlier in the process.
 
Old 05-14-2014, 01:22 AM   #6
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and CentOS
Posts: 6,724

Rep: Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705
Hi,

you can configure sudo to not require a password for certain commands. Perhaps what you want to do is run your script with sudo, not each individual command.

Cheers,

Evo2.
 
Old 05-14-2014, 01:50 AM   #7
eklavya
Member
 
Registered: Mar 2013
Posts: 636

Rep: Reputation: 142Reputation: 142
You can rename it.
Quote:
sudo mv /etc/hosts.template /etc/hosts
If you want to put data of password.txt into /etc/hosts
Quote:
sudo sh -c 'cat password.txt >> /etc/hosts'
I hope you have back up of original /etc/hosts.

Please do not create duplicate threads.
http://www.linuxquestions.org/questi...pt-4175504914/
 
Old 05-14-2014, 03:11 PM   #8
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
Quote:
Originally Posted by eklavya View Post
You can rename it.
...
Please do not create duplicate threads.
http://www.linuxquestions.org/questi...pt-4175504914/
Sounds like a Virtual Host|Machine.
I wouldn't rename that file, personally
 
Old 05-15-2014, 12:16 AM   #9
eklavya
Member
 
Registered: Mar 2013
Posts: 636

Rep: Reputation: 142Reputation: 142
Quote:
Originally Posted by Habitual View Post
Sounds like a Virtual Host|Machine.
I wouldn't rename that file, personally
Ok, then copy it
Code:
sudo cp /etc/hosts.template /etc/hosts
 
Old 05-15-2014, 02:24 AM   #10
tmtkobedmx8
LQ Newbie
 
Registered: Jul 2012
Posts: 6

Original Poster
Rep: Reputation: Disabled
Thanks everyone for the suggestions.
Quote:
sudo cp /etc/hosts.template /etc/hosts
did the trick and i had to run the script as sudo so i didn't have to be prompted all the time.

Tmtkobedmx8
 
  


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] How can my script change my hosts file and fetch the password in a txt file i have tmtkobedmx8 Linux - Newbie 6 05-15-2014 12:55 PM
How to redirect output of query result txt file into tar srinu.kadem Programming 3 05-08-2014 04:24 AM
how to redirect input and output to one file dspjm Linux - Software 1 12-08-2012 09:16 PM
How to redirect to a file the dev input of the keyboard ? Xeratul Linux - General 2 09-08-2012 12:51 AM
How to redirect txt file to password input? saravkrish Linux - General 3 04-01-2006 02:23 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 05:48 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