Visit Our UNIX and Linux User Community

script to modify /etc/shadow

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting script to modify /etc/shadow
# 1  
Old 09-15-2008
script to modify /etc/shadow


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?

# 2  
Old 09-15-2008
nawk -v user="$user" 'BEGIN{FS=":"}
}' /etc/shadow

# 3  
Old 09-16-2008
And here is the sed solution:
sed -i "/$user/s/\([^:]*:\)\{1\}/&*LK/" /etc/shadow

You can build the script from here.
# 4  
Old 09-16-2008
the nawk solutions need to be slightly modified. the requirements asked for a *LK* to be prepended to the second field - not replace the entire field.

the sed solution should use ^$user: for the pattern to ensure that only one account gets modified.
# 5  
Old 09-16-2008
thanks a lot, I will work on them
# 6  
Old 09-16-2008
one last thing;
after user enters username
I want to check the username with the usernames in the /etc/shadow.
If the entered username doesnt exist, I will return error,
else I will lock the account with
sed -i "/$user/s/\([^:]*:\)\{1\}/&*LK/" /etc/shadow

How can I do that?
# 7  
Old 09-16-2008
This should work.
test $(grep -c $user /etc/shadow) -gt 0 && sed -i "/$user/s/\([^:]*:\)\{1\}/&*LK/" /etc/shadow || echo ERROR

Previous Thread | Next Thread
Test Your Knowledge in Computers #929
Difficulty: Medium
Vernor Vinge's novel A Deepness in the Sky describes a spacefaring trading civilization thousands of years in the future that still uses the Unix epoch.
True or False?

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=""').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. Shell Programming and Scripting

Modify sed script

I'm trying to take out strings from log files and add them to a csv. For example, in the directory now, there are 2 log files. I get the following results: sed -e '/custodian/b' -e '/packaged by/b' -e '/package name/b' -e '/Total Data (MB) Read/b' -e '/Begin Time/b' -e d * packaged by =... (10 Replies)
Discussion started by: chipperuga
10 Replies

4. Shell Programming and Scripting

Help me to modify my script in stdout

please help me to modify my script #! /bin/bash while read line do echo "$line" >>/tmp/result && mysql -ss -e "use $line; select count(*) from users where type='admin' and deleted = 0;" > /tmp/result; done < /tmp/db_data cat result alan_hardwsdefs 2 bgrmods 2 claudiatdsefs 1... (2 Replies)
Discussion started by: unimaxlin
2 Replies

5. HP-UX

Password Aging script non-shadow non-trusted

basically there are several different versions of hpux, this script is for particular version that is non-trusted but also does not use any shadow files.This one is a little harder to do. Usually the time stamp of the last password change is stored as an epoch number in the shadow file, for... (3 Replies)
Discussion started by: sparcguy
3 Replies

6. 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

7. Solaris

Need help with script when trying to modify user

The script get a csv file with 2 colls for example: 123456,UNIX 963852,Microsoft the script supose to put the number in the Description of the user in this case UNIX or Microsoft the error i get is does not exist.OR: UNIX does not exist.OR: Microsoft but the users exist so i do not... (7 Replies)
Discussion started by: shatztal
7 Replies

8. 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

9. 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 <> # This program is free... (1 Reply)
Discussion started by: joangopan
1 Replies

10. 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

Featured Tech Videos