Sponsored Content
Top Forums Shell Programming and Scripting Updating the comments field on /etc/passwd Post 302279536 by Linux Duke on Friday 23rd of January 2009 03:23:25 AM
Old 01-23-2009
Hi there,

The script is still not working it just execute and does nothing to /etc/passwd and it gives no errors this time. Please check below I have attached my /etc/passwd output before executing the script then the content of the script and output produced after execution check /etc/passwd work nothing has been updated. I actually tested it on two servers which are server1 and server2 same output nothing updated.

ntp:x:38:38::/etc/ntp:/sbin/nologin
haldaemon:x:68:68:HAL daemon:/:/sbin/nologin
apache:x:48:48:Apache:/var/www:/sbin/nologin
distcache:x:94:94Smilieistcache:/:/sbin/nologin
postgres:x:26:26:PostgreSQL Server:/var/lib/pgsql:/bin/bash
mysql:x:27:27:MySQL Server:/var/lib/mysql:/bin/bash
dovecot:x:97:97:dovecot:/usr/libexec/dovecot:/sbin/nologin
webalizer:x:67:67:Webalizer:/var/www/usage:/sbin/nologin
squid:x:23:23::/var/spool/squid:/sbin/nologin
xfs:x:43:43:X Font Server:/etc/X11/fs:/sbin/nologin
named:x:25:25:Named:/var/named:/sbin/nologin
gdm:x:42:42::/var/gdm:/sbin/nologin
sabayon:x:86:86:Sabayon user:/home/sabayon:/sbin/nologin
student2:x:500:500:student2:/home/student2:/bin/bash
web:x:100:48:Web File Owner:/home/web:/bin/bash
SINLO_R:x:501:501::/home/SINLO_R:/bin/bash
AVNLNX:x:502:502::/home/AVNLNX:/bin/bash
REGGIE_P:x:503:503::/home/REGGIE_P:/bin/bash
STONE_P:x:504:504::/home/STONE_P:/bin/bash
GCOGCO:x:505:505::/home/GCOGCO:/bin/bash
NDUMIE:x:506:506::/home/NDUMIE:/bin/bash
MANGI:x:507:507::/home/MANGI:/bin/bash
MZIZA_G:x:508:508::/home/MZIZA_G:/bin/bash
[root@server2 script]# date
Thu Jan 22 21:49:49 SAST 2009

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

for i in `awk -F: '$1 == "'"$HOSTNAME"'" { print $2 }' $FILE1`
do
if awk -F: '$1 == "'"${i}"'" { found=1; exit; } END { exit(!found);}' $FILE2
then
FIELD1=`awk -F: '$1 == "'"$HOSTNAME"'" && $2 == "'"${i}"'" { print $3;exit; }' $FILE1`
$TEST usermod -c "${FIELD1}" $i
fi
done
~
~
[root@server2 script]# ls
unixscript.txt
[root@server2 script]# ./unixscript.txt
[root@server2 script]#

nfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
pcap:x:77:77::/var/arpwatch:/sbin/nologin
ntp:x:38:38::/etc/ntp:/sbin/nologin
haldaemon:x:68:68:HAL daemon:/:/sbin/nologin
apache:x:48:48:Apache:/var/www:/sbin/nologin
distcache:x:94:94Smilieistcache:/:/sbin/nologin
postgres:x:26:26:PostgreSQL Server:/var/lib/pgsql:/bin/bash
mysql:x:27:27:MySQL Server:/var/lib/mysql:/bin/bash
dovecot:x:97:97:dovecot:/usr/libexec/dovecot:/sbin/nologin
webalizer:x:67:67:Webalizer:/var/www/usage:/sbin/nologin
squid:x:23:23::/var/spool/squid:/sbin/nologin
xfs:x:43:43:X Font Server:/etc/X11/fs:/sbin/nologin
named:x:25:25:Named:/var/named:/sbin/nologin
gdm:x:42:42::/var/gdm:/sbin/nologin
sabayon:x:86:86:Sabayon user:/home/sabayon:/sbin/nologin
student2:x:500:500:student2:/home/student2:/bin/bash
web:x:100:48:Web File Owner:/home/web:/bin/bash
SINLO_R:x:501:501::/home/SINLO_R:/bin/bash
AVNLNX:x:502:502::/home/AVNLNX:/bin/bash
REGGIE_P:x:503:503::/home/REGGIE_P:/bin/bash
STONE_P:x:504:504::/home/STONE_P:/bin/bash
GCOGCO:x:505:505::/home/GCOGCO:/bin/bash
NDUMIE:x:506:506::/home/NDUMIE:/bin/bash
MANGI:x:507:507::/home/MANGI:/bin/bash
MZIZA_G:x:508:508::/home/MZIZA_G:/bin/bash
[root@server2 script]# date
Thu Jan 22 21:52:19 SAST 2009
[root@server2 script]#

Thanks
 

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
chsh(1) 						      General Commands Manual							   chsh(1)

NAME
chsh - change login shell SYNOPSIS
chsh [-D binddn] [-P path] [-s shell] [-l] [-q] [-u] [-v] [user] DESCRIPTION
chsh is used to change the user login shell. A normal user may only change the login shell for their own account, the super user may change the login shell for any account. If a shell is not given on the command line, chsh operates in an interactive fashion, prompting the user with the current login shell. Enter the new value to change the field, or leave the line blank to use the current value. Enter none to remove the current value. The current value is displayed between a pair of [ ] marks. The only restrictions placed on the login shell is that the command name must be listed in /etc/shells, unless the invoker is the super- user, and then any value may be added. An account with a restricted login shell may not change their login shell. This version of chsh is able to change the shell of local, NIS, NIS+ and LDAP accounts , if the permissions allow it. OPTIONS
-D, --binddn binddn Use the Distinguished Name binddn to bind to the LDAP directory. The user will be prompted for a password for simple authentica- tion. -P, --path path The passwd file is located below the specified directory path. chsh will use this files, not /etc/passwd. This is useful for exam- ple on NIS master servers, where you do not want to give all users in the NIS database automatic access to your NIS server and the NIS map is build from special files. -s, --shell Specify your login shell. -l, --list-shells Print the list of shells listed in /etc/shells and exit. -q, --quite Don't be verbose. -u, --usage Print a usage message and exit. --help Print a more verbose help text and exit. -v, --version Print version information and exit. FILES
/etc/passwd - user account information /etc/shells - list of valid login shells SEE ALSO
chfn(1), passwd(5), shells(5) AUTHOR
Thorsten Kukuk <kukuk@suse.de> pwdutils February 2004 chsh(1)
All times are GMT -4. The time now is 02:47 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy