LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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-26-2016, 10:30 AM   #1
giant45man
LQ Newbie
 
Registered: Sep 2015
Posts: 4

Rep: Reputation: Disabled
Change my own password on multiple servers (Redhat)


Hello All,

I need a bash script (that doesn't use EXPECT) to change my password on multiple servers. Any assistance will be greatly appreciated.

Thanks,

Kenneth
 
Old 04-26-2016, 10:49 AM   #2
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,636

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
Quote:
Originally Posted by giant45man View Post
Hello All,
I need a bash script (that doesn't use EXPECT) to change my password on multiple servers. Any assistance will be greatly appreciated.
We'll be glad to assist....so post what you've written/tried so far, and tell us where you're stuck. We will NOT write scripts for you, though...read the "Question Guidelines" link in my posting signature.
 
Old 04-26-2016, 10:58 AM   #3
giant45man
LQ Newbie
 
Registered: Sep 2015
Posts: 4

Original Poster
Rep: Reputation: Disabled
Here is the script I tried:
#!/bin/bash
host_name="MYSERVERNAME"
#file_name="server_list.csv"
echo -n "Enter username you want to change the password on the list of server : "
read username
echo -n " The username you entered is "$username". Is it correct (y/n)?"
read answer
if [ $answer = y ]
then
#for i in $(cat $file_name);
#do
hostname=$hostname
ssh $username@$hostname 'passwd'
echo ">>>>>>>>> SUCCESSFULLY CHANGED THE PASSWORD >>>>>>>>>>"
#done
else
echo "!!!!!!!!! your answer does not match to continue. Thank you!!!!!!!!!!!!"
exit 1
fi
exit 0



Here is where I am stuck:
ssh: Could not resolve hostname : Name or service not known
 
Old 04-26-2016, 11:32 AM   #4
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,702

Rep: Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895
Your defined variable is host_name not hostname.
 
Old 04-26-2016, 11:33 AM   #5
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,636

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
Quote:
Originally Posted by giant45man View Post
Here is the script I tried:
Code:
#!/bin/bash
host_name="MYSERVERNAME"
#file_name="server_list.csv"
echo -n "Enter username you want to change the password on the list of server : "
read username
echo -n " The username you entered is "$username". Is it correct (y/n)?"
read answer
if [ $answer = y ]
then
#for i in $(cat $file_name);
#do
hostname=$hostname
ssh $username@$hostname 'passwd'
echo ">>>>>>>>> SUCCESSFULLY CHANGED THE PASSWORD >>>>>>>>>>"
#done
else
echo "!!!!!!!!! your answer does not match to continue. Thank you!!!!!!!!!!!!"
exit 1
fi
exit 0
Here is where I am stuck: ssh: Could not resolve hostname : Name or service not known
Thanks..please use CODE tags when posting code, to make things easier to read.

The reason is, you've got lines commented out..specifically, the ones where you open the file, then where you read it. You're never defining the $hostname variable....but on the second line, you're defining host_name...which is different.
 
  


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
Need help in creating a script which will change password of user on multiple servers linux_neophyte Linux - Newbie 5 09-07-2013 03:04 AM
Remote password change of Servers and Client on RHEL 5.5 [root@localhost ~]# Linux - Newbie 8 01-18-2013 07:45 AM
Change password of linux servers remotely linux_bud Programming 2 11-26-2009 04:55 AM
Changing root password on multiple servers user_lnx Linux - Enterprise 3 07-27-2006 01:16 PM
Password Changes on Multiple Servers? Teejeaux Linux - Enterprise 5 04-20-2006 11:11 AM

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

All times are GMT -5. The time now is 06:07 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
Open Source Consulting | Domain Registration