Modify /etc/passwd via script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Modify /etc/passwd via script
# 8  
Old 03-24-2011
Well the nawk command to do this is:
Code:
$ nawk -F:  -v OFS=: -v user="daemon" '$1 == user{$3="0"$3;} {print}' < /etc/passwd >/tmp/output

Wrapping that is a script to replace "daemon" with your particular user and move the output file should be pretty easy.
# 9  
Old 03-25-2011
excellent, thank you! I will make the username field an argument on the script itself and our app security people can use this instead of modifying the passwd file directly.
# 10  
Old 04-05-2011
Quote:
Originally Posted by Perderabo
Well the nawk command to do this is:
Code:
$ nawk -F:  -v OFS=: -v user="daemon" '$1 == user{$3="0"$3;} {print}' < /etc/passwd >/tmp/output

Wrapping that is a script to replace "daemon" with your particular user and move the output file should be pretty easy.
this is working great. One scenario I didnt anticipate is if I need to add 2 zeros, 3, etc, to make it a total of 7 digits.

I put it in a while loop and that seems to function fine, but the nawk statement doesnt want to add a zero if its already leading with a zero. I am looking into exactly what your statement does but if you can tell me how to allow it to add a 2nd or 3rd zero that would be great.
# 11  
Old 04-05-2011
If it's always supposed to be seven digits and you want to pad it with zeroes, the following should work:
Change $3="0"$3 to $3=sprintf("%07d", $3)

Regards,
Alister
This User Gave Thanks to alister For This Post:
# 12  
Old 04-05-2011
perfect. thank you very much!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Modify python script

How can I modify this so it uses Seamonkey and goes to Yahoo Advanced Web Search #!/usr/bin/python3 import os import urllib google = os.popen('zenity --entry --text="Enter what you want to google: " --title="google.py"').read() google = urllib.quote(google) os.system('firefox... (8 Replies)
Discussion started by: drew77
8 Replies

2. Shell Programming and Scripting

Modify the file by script

Hi All, I have an input file like below, 6984 1225 6989 1220 6994 1214 ... (3 Replies)
Discussion started by: Indra2011
3 Replies

3. AIX

When did AIX start using /etc/security/passwd instead of /etc/passwd to store encrypted passwords?

Does anyone know when AIX started using /etc/security/passwd instead of /etc/passwd to store encrypted passwords? (1 Reply)
Discussion started by: Anne Neville
1 Replies

4. Solaris

passwd cmd reenables passwd aging in shadow entry

Hi Folks, I have Solaris 10, latest release. We have passwd aging set in /etc/defalut/passwd. I have an account that passwd should never expire. Acheived by emptying associated users shadow file entries for passwd aging. When I reset the users passwd using passwd command, it re enables... (3 Replies)
Discussion started by: BG_JrAdmin
3 Replies

5. Shell Programming and Scripting

how can I modify this script.

hello forum members, I have a script which is used find the Uname and passwords and redirects into a output.txt file.I hardcoded a string "ciadev" but iwant search two more strings also "absdev" and "absprod" So modify this script please. I am lookinmg forward from you, please find the below... (2 Replies)
Discussion started by: rajkumar_g
2 Replies

6. Shell Programming and Scripting

script to modify /etc/shadow

Hi I am looking for script to modify /etc/shadow. For example: 1-)User enters username 2-)The line of that user is found in /etc/shadow and *LK* is added infront of the second field in /etc/shadow. How can I do this? Thanks (7 Replies)
Discussion started by: tjay83
7 Replies

7. Shell Programming and Scripting

Please help to modify my script

Hi, I have a script which connect to ATM's and pull two files from the ATM. The which i try to pull is like PIC20085200001*.JPG First 7 digit consist of year montn and date as well After todays execution i want to change the date to next date I add few lines in the script but it is not... (6 Replies)
Discussion started by: Renjesh
6 Replies

8. Shell Programming and Scripting

Modify Perl script to work with txt - Permissions script

Hi I have this code, and i want work with a ls -shalR output in .txt What i need read to do this?? Where start? #!/usr/bin/perl # Allrights- A perl tool for making backups of file permissions # Copyright (C) 2005 Norbert Klein <norbert@acodedb.com> # This program is free... (1 Reply)
Discussion started by: joangopan
1 Replies

9. UNIX for Dummies Questions & Answers

Using a script to modify the crontab

I want to add one line to the end of my crontab using a script. I have tried piping in the editor commands, but I can't get it to work. crontab -e user << EX $a This is the text I want to add. . wq EX This doesn't work. Is there an easier way to do this? (2 Replies)
Discussion started by: johnmsucpe
2 Replies

10. Shell Programming and Scripting

passwd -l script

I need to lockout about 250 user accounts on a server. I figure on putting the user accounts to be locked out in a text file and the running a script to go through the file and run the "passwd -l useraccount" against the /etc/passwd file (yes, I am root as I do this). Here is what I have so... (3 Replies)
Discussion started by: antalexi
3 Replies
Login or Register to Ask a Question