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
JOIN(1) 							   User Commands							   JOIN(1)

NAME
join - join lines of two files on a common field SYNOPSIS
join [OPTION]... FILE1 FILE2 DESCRIPTION
For each pair of input lines with identical join fields, write a line to standard output. The default join field is the first, delimited by whitespace. When FILE1 or FILE2 (not both) is -, read standard input. -a FILENUM also print unpairable lines from file FILENUM, where FILENUM is 1 or 2, corresponding to FILE1 or FILE2 -e EMPTY replace missing input fields with EMPTY -i, --ignore-case ignore differences in case when comparing fields -j FIELD equivalent to '-1 FIELD -2 FIELD' -o FORMAT obey FORMAT while constructing output line -t CHAR use CHAR as input and output field separator -v FILENUM like -a FILENUM, but suppress joined output lines -1 FIELD join on this FIELD of file 1 -2 FIELD join on this FIELD of file 2 --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 --header treat the first line in each file as field headers, print them without trying to pair them -z, --zero-terminated end lines with 0 byte, not newline --help display this help and exit --version output version information and exit Unless -t CHAR is given, leading blanks separate fields and are ignored, else fields are separated by CHAR. Any FIELD is a field number counted from 1. FORMAT is one or more comma or blank separated specifications, each being 'FILENUM.FIELD' or '0'. Default FORMAT outputs the join field, the remaining fields from FILE1, the remaining fields from FILE2, all separated by CHAR. If FORMAT is the keyword 'auto', then the first line of each file determines the number of fields output for each line. Important: FILE1 and FILE2 must be sorted on the join fields. E.g., use "sort -k 1b,1" if 'join' has no options, or use "join -t ''" if 'sort' has no options. Note, comparisons honor the rules specified by 'LC_COLLATE'. If the input is not sorted and some lines cannot be joined, a warning message will be given. GNU coreutils online help: <http://www.gnu.org/software/coreutils/> Report join translation bugs to <http://translationproject.org/team/> AUTHOR
Written by Mike Haertel. COPYRIGHT
Copyright (C) 2013 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
comm(1), uniq(1) The full documentation for join is maintained as a Texinfo manual. If the info and join programs are properly installed at your site, the command info coreutils 'join invocation' should give you access to the complete manual. GNU coreutils 8.22 June 2014 JOIN(1)
All times are GMT -4. The time now is 02:56 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy