943,771 Members | Top Members by Rank

Ad:
You are currently viewing page 1 of this multi-page discussion thread
Apr 12th, 2006
0

Change Password In A Shell Script

Expand Post »
Hi All,

I have a problem.

I need to write a shell script to change the password. The user may want to change his own password by this script.

He will have to provide the required 3 parameters i.e. old password, new password and retype new password as arguments in command line.

like, ./pass.sh old new new

How do I do it. I am in a fix.

I am not allowed to use expect etc.

Please help me.

Thanks.
Asimananda
Reputation Points: 10
Solved Threads: 0
Newbie Poster
captor is offline Offline
1 posts
since May 2005
Apr 19th, 2006
0

Re: Change Password In A Shell Script

You shouldn't have to do it. Linux has this built in with

passwd
TKS
Reputation Points: 108
Solved Threads: 18
Posting Pro in Training
TKS is offline Offline
470 posts
since Jan 2004
May 9th, 2006
0

Re: Change Password In A Shell Script

i am using a shell script which changes the password of all the servers in the network and also of the host server (as per your requirement) but it uses except.

Earlier i had a perl script to change the password.

If you want i can give you both the scripts and you can modify them as per your requirement.

Amit
Reputation Points: 10
Solved Threads: 0
Newbie Poster
kamitsin is offline Offline
16 posts
since Apr 2006
May 12th, 2006
0

Re: Change Password In A Shell Script

Sounds like a class asignment.
try a here document
Shell Scripting Syntax (Toggle Plain Text)
  1. oldpw="$1"
  2. newpw="$2"
  3. passwd <<EOF
  4. "$1"
  5. "$2"
  6. "$2"
  7. EOF
Reputation Points: 62
Solved Threads: 10
Junior Poster
jim mcnamara is offline Offline
179 posts
since May 2004
May 31st, 2006
0

Re: Change Password In A Shell Script

Quote originally posted by kamitsin ...
i am using a shell script which changes the password of all the servers in the network and also of the host server (as per your requirement) but it uses except.

Earlier i had a perl script to change the password.

If you want i can give you both the scripts and you can modify them as per your requirement.

Amit
Amit,

I would be very interested in your scripts. Would you mind sending them to me at . This sounds exactly what I am needing.
Thanks

PS
Last edited by 'Stein; Aug 14th, 2006 at 2:32 am.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
webtrekker is offline Offline
1 posts
since May 2006
Jun 1st, 2006
0

Re: Change Password In A Shell Script

I have attached the modified script beacuse the original script is for changing the password across multiple servers and i guess this is not what you require.

You need to execute the script from root user. It will create a log file in the directory from which you are executing the script.

You can change the password for root and a user but you can do a small modification and the script will change the password for root and any user.

Amit
Attached Files
File Type: txt ChangePassword.exp.txt (2.7 KB, 4046 views)
Reputation Points: 10
Solved Threads: 0
Newbie Poster
kamitsin is offline Offline
16 posts
since Apr 2006
Jun 21st, 2006
0

Re: Change Password In A Shell Script

Quote originally posted by kamitsin ...
I have attached the modified script beacuse the original script is for changing the password across multiple servers and i guess this is not what you require.

You need to execute the script from root user. It will create a log file in the directory from which you are executing the script.

You can change the password for root and a user but you can do a small modification and the script will change the password for root and any user.

Amit




Hi Amit,

Do you have a similar script (only ChangePasswd) in Perl? If you do can you please share it.

Thanks,
Vivek.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
vivekp is offline Offline
1 posts
since Jun 2006
Jul 7th, 2006
0

Re: Change Password In A Shell Script

Hi Amit,

I am looking for a script just like yours: I have many servers and I need to change their root psw.
Could you post the entire script?
thanks a lot

Ezra

Quote originally posted by kamitsin ...
I have attached the modified script beacuse the original script is for changing the password across multiple servers and i guess this is not what you require.

You need to execute the script from root user. It will create a log file in the directory from which you are executing the script.

You can change the password for root and a user but you can do a small modification and the script will change the password for root and any user.

Amit
Reputation Points: 10
Solved Threads: 0
Newbie Poster
ezradibiase is offline Offline
1 posts
since Jul 2006
Aug 14th, 2006
0

Re: Change Password In A Shell Script

Quote originally posted by kamitsin ...
I have attached the modified script beacuse the original script is for changing the password across multiple servers and i guess this is not what you require.

You need to execute the script from root user. It will create a log file in the directory from which you are executing the script.

You can change the password for root and a user but you can do a small modification and the script will change the password for root and any user.

Amit
Hi Amit,

Im looking for the script which you have for changing password on multiple servers. Would you mind sending them to me at.

Thanks and regards,
VinodKumar
Last edited by 'Stein; Aug 14th, 2006 at 2:33 am.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
VinodKumar is offline Offline
1 posts
since Aug 2006
Sep 6th, 2006
0

Re: Change Password In A Shell Script

Click to Expand / Collapse  Quote originally posted by kamitsin ...
I have attached the modified script beacuse the original script is for changing the password across multiple servers and i guess this is not what you require.

You need to execute the script from root user. It will create a log file in the directory from which you are executing the script.

You can change the password for root and a user but you can do a small modification and the script will change the password for root and any user.

Amit
Hello Amit,

I am trying to get a perl script to communicate with the passwd program. I do not have access to the modules expect or IO:ty. I also do not have access to the expect utility.

So far I have found a free pty/tty pair and opened them and set them to autoflush. Then I fork.

In the child I close stdin, stdout and stderr to reopen them associated to the new tty handle and exec passwd.

In the parent I want to read and write to the pty to interact with passwd. This is not working. The passwd direct access to the tty is not reaching my tty.

Maybe I need to set the controling tty in the child before doing the exec? How do I do that?

Cheers,
sut
sut
Reputation Points: 20
Solved Threads: 1
Light Poster
sut is offline Offline
30 posts
since Sep 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Shell Scripting Forum Timeline: Problem printing string
Next Thread in Shell Scripting Forum Timeline: How to copy and paste (with changes)





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC