Results 1 to 5 of 5
Hi all,
I have to write a program that asks the user for an account name on the system. It has to determine whether the account exists or not (it ...
- 04-04-2009 #1Just Joined!
- Join Date
- Feb 2009
- Posts
- 5
Bash scripting - modifying /etc/passwd
Hi all,
I have to write a program that asks the user for an account name on the system. It has to determine whether the account exists or not (it searches the /etc/passwd file for the account). If the account does not exist, it will display "account does not exist!" and ask for another account. If the account does exist, it will ask some informational questions about that account (i.e. a name, a location, and an extension number) and is to then add these items to that user's /etc/passwd entry.
For example:
Enter account:
admin
admin
:503:503::/home/admin:/bin/bash
Enter name:
Administrator
Enter location:
Earth
Enter number:
1234
admin
:503:503:Administrator, Earth, 1234:/home/admin:/bin/bash
So the last line is the modified /etc/passwd entry for the account 'admin'. This is what I am trying to accomplish. I have the program made, I just do not know how to modify the /etc/passwd entry (using bash scripting) for the user's information (name,location and number). Help is greatly appreciated! Thanks!
Kris
- 04-04-2009 #2
hi,
try the command vipw.
Code:man vipw
Linux and me it's a love story
- 04-04-2009 #3Just Joined!
- Join Date
- Apr 2009
- Posts
- 1
Modifying comment field
You can use the chfn command to modify the field
If the user is test1 as below
test1
:503:503:test1:/home/test1:/bin/bash
You could modify it as below
chfn -f "Test Account" -o "Earth"
The entry now looks like below:
test1
:503:503:Test Account,Earth:/home/test1:/bin/bash
If you're doing this for multiple users you can add the username at the end and run using sudo or as root.
- 04-04-2009 #4Just Joined!
- Join Date
- Feb 2009
- Posts
- 5
thanks knighster! this seems to work. however, can this only work on the current account, or am I able to change another user's finger information? I need to make it so it enters the account to be changed. can I do this? thanks!
Kris
- 04-04-2009 #5Just Joined!
- Join Date
- Feb 2009
- Posts
- 5
nevermind, i just realized you add the user to the end of the command, haha! thanks!


Reply With Quote