Sponsored Content
Top Forums Shell Programming and Scripting Script for updating the comments field on /etc/passwd on redhat linux Post 302269914 by Linux Duke on Friday 19th of December 2008 05:10:15 AM
Old 12-19-2008
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 compare this file with /etc/passwd first backup the passwd database and update the comment field on /etc/passwd with the details on the text file if it's blank.

I have a script that I have created not sure if it will do the job as I have not worked a lot with scripts.

Below is my script and attached is my text file:

#!/usr/bin/bash
FILE1=/tmp/update_passwd.txt
FILE2=/etc/passwd
cp $FILE2 /etc/passwd.orig
for i in `cat $FILE1 | awk -F":" '{ print $2 }'`
do
FIELD1=`cat $FILE1 | grep ${i} |awk -F":" '{ print $3 }'`
grep $i ${FILE2}
if [ $? -eq 0 ]
then
usermod -c "${FIELD1}" $i
fi
done

I will highly appreciate your assistance.Smilie
 

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Updating Kernels and video drivers in Redhat 8.0

Hi. I have a few "newbie" questions. This is a 2 part question which I was unable to find an answer. First, I have recently installed the kernel patch and video driver from Nvidia for my GeForce Ti 4800 video card for 3d on a fresh install of Redhat 8.0. I need to do all of the updates for Redhat.... (1 Reply)
Discussion started by: jeremiebarber
1 Replies

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

3. Shell Programming and Scripting

Updating the comments field on /etc/passwd

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.txt check below. I need a script that... (11 Replies)
Discussion started by: Linux Duke
11 Replies

4. Shell Programming and Scripting

simple CSH Script behaves differently on Solaris and RedHat Linux

I have a simple csh-script on a Solaris Workstaion which invokes the bc calculator: #!/bin/csh set shz=2 set zshift=5 set shzp=`bc -l <<END \ scale = 3 \ -1. * $shz + $zshift \ END` echo $shzp The result ($shzp) in this case is 3 (-1*2+5). It works fine on Solaris 8. ... (2 Replies)
Discussion started by: two reelers
2 Replies

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

6. Red Hat

Updating RedHat 5.1

Hi all, Can any one tell me how I can update RedHat 5.1 without it getting upgraded to 5.5? Thanks (1 Reply)
Discussion started by: Obi-Wan
1 Replies

7. Shell Programming and Scripting

How to make a command same as PICO in linux but with comments

Hello, i need to make a linux command but i dont know how.. my proposal is to make a command same as pico but with comments.. for example if i enter picoc, it will run like pico but with this comments.. #================================== #Script Name: #By: #Date: #Purpose: ... (2 Replies)
Discussion started by: jrdncchr
2 Replies

8. Red Hat

Redhat Cluster updating kernel setting

hello, I was going through clustering documentation for Redhat, it says "Enable IP Aliasing support in the kernel by setting the CONFIG_IP_ALIAS kernel option to y. When specifying kernel options, under Networking Options, select IP aliasing support", I knew I should update /etc/sysctl.conf with... (1 Reply)
Discussion started by: bobby320
1 Replies

9. 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
COMM(1) 							   User Commands							   COMM(1)

NAME
comm - compare two sorted files line by line SYNOPSIS
comm [OPTION]... FILE1 FILE2 DESCRIPTION
Compare sorted files FILE1 and FILE2 line by line. When FILE1 or FILE2 (not both) is -, read standard input. With no options, produce three-column output. Column one contains lines unique to FILE1, column two contains lines unique to FILE2, and column three contains lines common to both files. -1 suppress column 1 (lines unique to FILE1) -2 suppress column 2 (lines unique to FILE2) -3 suppress column 3 (lines that appear in both files) --check-order check that the input is correctly sorted, even if all input lines are pairable --nocheck-order do not check that the input is correctly sorted --output-delimiter=STR separate columns with STR --total output a summary -z, --zero-terminated line delimiter is NUL, not newline --help display this help and exit --version output version information and exit Note, comparisons honor the rules specified by 'LC_COLLATE'. EXAMPLES
comm -12 file1 file2 Print only lines present in both file1 and file2. comm -3 file1 file2 Print lines in file1 not in file2, and vice versa. AUTHOR
Written by Richard M. Stallman and David MacKenzie. REPORTING BUGS
GNU coreutils online help: <http://www.gnu.org/software/coreutils/> Report comm translation bugs to <http://translationproject.org/team/> COPYRIGHT
Copyright (C) 2017 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>. This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. SEE ALSO
join(1), uniq(1) Full documentation at: <http://www.gnu.org/software/coreutils/comm> or available locally via: info '(coreutils) comm invocation' GNU coreutils 8.28 January 2018 COMM(1)
All times are GMT -4. The time now is 11:16 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy