Sponsored Content
Top Forums Shell Programming and Scripting Updating the comments field on /etc/passwd Post 302277126 by Linux Duke on Thursday 15th of January 2009 01:47:39 PM
Old 01-15-2009
I have updated the script but it's still not working please have a look below.

#!/bin/bash
FILE1=/tmp/update.txt
FILE2=/etc/passwd
cp $FILE2 /etc/passwd.$$.orig
TEST=echo

for i in `awk -F: '$1 == "'"$HOSTNAME"'" && $2 == '"${i}"' { print $2 }' $FILE1`
do
if awk -F: '$1 == "'"${i}"'" { exit(0); } END { exit(1);}' $FILE2
then
FIELD1=`awk -F: '$2 == "'"${i}"'" { print $3 }' $FILE1`
$TEST usermod -c "${FIELD1}" $i
fi
done
~
[root@server1 script]# ./scriptlinuxcom.txt
awk: $1 == "server1.localdomain" && $2 == { print $2 }
awk: ^ syntax error
[root@server1 script]#

I'm still getting syntax error's when executing the script.If you look below at the last six users
my /etc/password comment field has not been updated with the comments from the /tmp/update.txt.

/etc/passwd

sabayon:x:86:86:Sabayon user:/home/sabayon:/sbin/nologin
student1:x:500:500:student1:/home/student1:/bin/bash
web:x:100:48:Web File Owner:/home/web:/bin/bash
SINLO_R:x:501:501:SINLO ROGGER :/home/SINLO_R:/bin/bash
AVNlnx:x:502:502:LINUX Admistrator/junior:/home/AVNlnx:/bin/bash
REGGIE_P:x:503:503:REGGIE PABLO:/home/REGGIE_P:/bin/bash
STONE_P:x:504:504:STONE PANE:/home/STONE_P:/bin/bash
SINLOR:x:505:505:SINLO ROGGER :/home/SINLOR:/bin/bash
GUGU_M:x:506:506::/home/GUGU_M:/bin/bash
SANDISA:x:507:507::/home/SANDISA:/bin/bash
GCOGCO:x:508:508::/home/GCOGCO:/bin/bash
NDUMIE:x:509:509::/home/NDUMIE:/bin/bash
MANGI:x:510:510::/home/MANGI:/bin/bash
MZIZA_G:x:511:511::/home/MZIZA_G:/bin/bash

/tmp/update.txt

[root@server1 etc]# cat /tmp/update.txt
SERVER1:SINLO_R:SINLO ROGGER
SERVER1:AVNlnx:LINUX Admistrator/junior
SERVER1:nfsnobody:LINUX Admistrator
SERVER1:REGGIE_P:REGGIE PABLO
SERVER1:STONE_P:STONE PANE
SERVER1:GUGU_M:LINUX ENGINEER
SERVER1:SANDISA:SYSTEM ADMIN
SERVER1:GCOGCO:MTN OPERATOR
SERVER1:NDUMIE:MTN OPERATOR
SERVER1:MANGISmilieBA ORACLE
SERVER1:MZIZA_G:SPECIALIST ORACLE
SERVER2:SINLO_R:SINLO ROGGER
SERVER2:AVNLNX:LINUX Admistrator/junior
SERVER2:nfsnobody:LINUX Admistrator
SERVER2:REGGIE_P:REGGIE PABLO

The is another script that was created for me this script worked fine but because it was not using usermod it
updated the /etc/shadow id and then this made users when loggining on appear with out user name's.

This is the script:

FILE1=/tmp/update.txt
FILE2=/etc/passwd
cp $FILE2 /etc/passwd.orig

awk 'BEGIN{FS=OFS=":"} NR==FNR{a[$2]=$3;next}
$1 in a && $5==""{$5=a[$1]} {print}' "$FILE1" "$FILE2" > passwd_new

mv passwd_new $FILE2
~
~
[root@server1 script]# ./scriptgugu.txt
[root@server1 script]#

If you now look at the /etc/passwd the comment field has been updated but now when I loggon to the system
with the users I have problems of them logging in but after that the command prompt appears with out a username.
e.g. ReGGIE_P will logon to the system but the prompt will have " I don't have a username linked to this id 435$ "
This created problems for me as some of the accounts a used to run applications.

This is the out put of /etc/passwd asfter executing the scrip:

gdm:x:42:42::/var/gdm:/sbin/nologin
sabayon:x:86:86:Sabayon user:/home/sabayon:/sbin/nologin
student1:x:500:500:student1:/home/student1:/bin/bash
web:x:100:48:Web File Owner:/home/web:/bin/bash
SINLO_R:x:501:501:SINLO ROGGER :/home/SINLO_R:/bin/bash
AVNlnx:x:502:502:LINUX Admistrator/junior:/home/AVNlnx:/bin/bash
REGGIE_P:x:503:503:REGGIE PABLO:/home/REGGIE_P:/bin/bash
STONE_P:x:504:504:STONE PANE:/home/STONE_P:/bin/bash
SINLOR:x:505:505:SINLO ROGGER :/home/SINLOR:/bin/bash
GUGU_M:x:506:506:LINUX ENGINEER:/home/GUGU_M:/bin/bash
SANDISA:x:507:507:SYSTEM ADMIN:/home/SANDISA:/bin/bash
GCOGCO:x:508:508:MTN OPERATOR:/home/GCOGCO:/bin/bash
NDUMIE:x:509:509:MTN OPERATOR:/home/NDUMIE:/bin/bash
MANGI:x:510:510SmilieBA ORACLE:/home/MANGI:/bin/bash
MZIZA_G:x:511:511:SPECIALIST ORACLE:/home/MZIZA_G:/bin/bash

look at the last six fields the comment field has been updated.

Please asssist I hope this can give u an idea of the problem.

Thanks for all the help.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Trying to extract a field from /etc/passwd file..

Hello, was looking for some help on extracting a field from the passwd file. So far I have made a copy of the passwd file and changed my rights so I can edit it. Every user's password is coded as an :x:, and my goal was to change that x to a blank, and then try to extract any user with that field... (2 Replies)
Discussion started by: xBuRnTx
2 Replies

2. Programming

lint comments

Hi can anyone help me regarding the meaning of the following lint messages. what is the use of having such lint comments in the c program. /*lint -esym(534,cputs,fgets,cprintf) */ /*lint -efile(766,pragmas.h) */ Thanks a lot in advance. (5 Replies)
Discussion started by: axes
5 Replies

3. Shell Programming and Scripting

awk updating one file with another, comparing, updating

Hello, I read and search through this wonderful forum and tried different approaches but it seems I lack some knowledge and neurones ^^ Here is what I'm trying to achieve : file1: test filea 3495; test fileb 4578; test filec 7689; test filey 9978; test filez 12300; file2: test filea... (11 Replies)
Discussion started by: mecano
11 Replies

4. Shell Programming and Scripting

Script for updating the comments field on /etc/passwd on redhat linux

Hi there, I have more that 300 servers that I need to updated the comments field on /etc/passwd for users that have a blank comments fields. The users have accounts on different servers. I have created a list of these users on a text file called update_passwd.txt. I need a script that will... (6 Replies)
Discussion started by: Linux Duke
6 Replies

5. UNIX for Dummies Questions & Answers

Updating a field in a File without creating temp file's

Hi Experts, I have a requirement where i need to update the below items in file, 1. END TIME 2. PREV_STATUS For the first time the PREV_status and end time of all job the job will be sysdate & NULL reply as below, Session_name,Load Type,Frequency,Seesion End time,Prev_Status... (2 Replies)
Discussion started by: prabhutkl
2 Replies

6. Shell Programming and Scripting

Sed script, changing all C-comments to C++-comments

I must write a script to change all C++ like comments: // this is a comment to this one /* this is a comment */ How to do it by sed? With file: #include <cstdio> using namespace std; //one // two int main() { printf("Example"); // three }//four the result should be: (2 Replies)
Discussion started by: black_hawk
2 Replies

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

8. UNIX for Dummies Questions & Answers

Delete Comments

Hello i am back :D, i have a prolem. I want to Delete the IPs which are in Comments. Input 192.168.0.1 192.168.0.2 #192.168.0.3 #192.168.0.4 - when TAB or Space, delete too. /*192.168.0.5 192.168.0.6 192.168.0.7*\ Output 192.168.0.1 192.168.0.2 My solution is sed -e... (7 Replies)
Discussion started by: eightball
7 Replies

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

10. Solaris

Passwd -l or -u modifies lastchg field in /etc/shadow file

Hi, I have a Solaris 10 box where password aging is not functioning properly. Using the passwd command with the -l or -u options causes the lastchg field in the /etc/shadow file to be modified. Therefore, if a user's password is set to expire in 90 days and they are 1 day away, all they have... (4 Replies)
Discussion started by: cschar
4 Replies
All times are GMT -4. The time now is 03:48 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy