Sponsored Content
Top Forums Shell Programming and Scripting Save awk record field in bourne shell variable Post 302684701 by Learn4Life on Friday 10th of August 2012 01:34:06 AM
Old 08-10-2012
Save awk record field in bourne shell variable

Hello,

I am trying to write a shell script that maintains the health of the passwd file. The goal is to check for duplicate usernames, UID's etc. I am able to find and sort out the UID and login names via awk (which I would like to use), but I can't figure out how to save the record field into a `sh` variable so I can use it for further testing. The algorithm I think of is:

  1. Read in passwd file
  2. determine field seperator
  3. save the UID field ($3) in shell variable.
  4. continue and save the next UID field in another shell variable
  5. compare the two UID's
  6. if the same print user notification
  7. else, continue
Code:
echo "Check for root uid..."
 16 awk -F: '$1 ~/root/ {print "Found Root ID"}' ~/script/passwd
 17 
 18 echo "Check for duplicate user id's..."
 19 counter=0
 20 for line in  ~/script/passwd; do
 21         uidcurrent=`awk -F: '$3' ~/script/passwd`
 22         if [ $counter -eq 0 ]; then
 23                 counter=`expr $counter+1`
 24                 uidprevious=$uidcurrent
 25                 continue
 26         elif [ $uidprevious -eq $uidcurrent ]; then
 27                 echo "Duplicate UID found"
 28         else
 29                 echo "..."
 30                 uidprevious=$uidcurrent
 31         fi
 32 done
 33 echo "Duplicate UID check done"
 34 echo "Check for duplicate login names..."
 35 exit 0

I appreciate your time and effort.

-Daniel
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Read file from within AWK and save $1 to a variable

Hi I am very new to NAWK programming so this question is probably going to sound really stupid: I have a NAWK script which contains a DO loop. During each loop it runs a FORTRAN program which in turn generates two output files , each one containing 2 integer variables. I would appreciate it... (8 Replies)
Discussion started by: robbiegregg
8 Replies

2. Shell Programming and Scripting

How to assign record count output of isql to a shell variable ?

isql select count(*) from Table eof How to assign record count output of isql query to a shell variable ? (4 Replies)
Discussion started by: vikram3.r
4 Replies

3. Shell Programming and Scripting

Bourne Shell - Problem with while loop variable scope.

Hello I am having issues with a script I'm working on developing on a Solaris machine. The script is intended to find out how many times a particular user (by given userid) has logged into the local system for more than one hour today. Here is my while loop: last $user | grep -v 'sshd'... (7 Replies)
Discussion started by: DaveRich
7 Replies

4. Shell Programming and Scripting

Bourne Shell - Dynamic Variable Error

hi, I am trying to assign a value through 'read' and all works well until I have a space in the in putted value, for the life of me I cant figure out how to escape this. :wall: Any ideas? #!/bin/sh ask_question() { question_text="${1}"; question_answer=""; ... (2 Replies)
Discussion started by: redback
2 Replies

5. Shell Programming and Scripting

awk text record - prepend first field to all subsequent fields

Hello everyone, I've suddenly gotten very interested in sed and awk (and enjoying it quite a bit too) because of a large conversion project that we're working on. I'm currently stuck with a very inefficient process for processing text blocks. I'm sure someone here should be able to easily point out... (2 Replies)
Discussion started by: jameswatson3
2 Replies

6. Shell Programming and Scripting

Splitting record into multiple records by appending values from an input field (AWK)

Hello, For the input file, I am trying to split those records which have multiple values seperated by '|' in the last input field, into multiple records and each record corresponds to the common input fields + one of the value from the last field. I was trying with an example on this forum... (4 Replies)
Discussion started by: imtiaz99
4 Replies

7. Shell Programming and Scripting

SED/AWK to edit/add field values in a record

Hi Experts, I am new to shell scripting. Need some help in doing one task given by the customer. The sample record in a file is as follows: 3538,,,,,,ID,ID1,,,,,,,,,,, It needs to be the following: 3538,,353800,353800,,,ID,ID1,,,,,COLX,,,,,COLY, And i want to modify this record in... (3 Replies)
Discussion started by: sugarcane
3 Replies

8. Shell Programming and Scripting

Insert field values in a record using awk command

Hi Friends, Below is my input file with "|" (pipe) as filed delimiter: My Input File: HDR|F1|F2||||F6|F7 I want to inser values in the record for field 4 and field 5. Expected output HDR|F1|F2||F4|F5|F6|F7 I am able to append the string to the end of the record, but not in between the... (3 Replies)
Discussion started by: Ajay Venkatesan
3 Replies

9. Shell Programming and Scripting

Display combination of 4 field uniqe record and along with concatenate 5th and 6th field.

Table ACN|NAME|CITY|CTY|NO1|NO2 115|AKKK|ASH|IND|10|15 115|AKKK|ASH|IND|20|20 115|AKKK|ASH|IND|30|35 115|AKKK|ASH|IND|30|35 112|ABC|FL|USA|15|15 112|ABC|FL|USA|25|20 112|ABC|FL|USA|25|45 i have written shell script using cut command and awk programming getting error correct it and add... (5 Replies)
Discussion started by: udhal
5 Replies

10. Shell Programming and Scripting

Shell script for field wise record count for different Files .csv files

Hi, Very good wishes to all! Please help to provide the shell script for generating the record counts in filed wise from the .csv file My question: Source file: Field1 Field2 Field3 abc 12f sLm 1234 hjd 12d Hyd 34 Chn My target file should generate the .csv file with the... (14 Replies)
Discussion started by: Kirands
14 Replies
passmgmt(1M)						  System Administration Commands					      passmgmt(1M)

NAME
passmgmt - password files management SYNOPSIS
passmgmt -a options name passmgmt -m options name passmgmt -d name DESCRIPTION
The passmgmt command updates information in the password files. This command works with both /etc/passwd and /etc/shadow. passmgmt -a adds an entry for user name to the password files. This command does not create any directory for the new user and the new login remains locked (with the string *LK* in the password field) until the passwd(1) command is executed to set the password. passmgmt -m modifies the entry for user name in the password files. The name field in the /etc/shadow entry and all the fields (except the password field) in the /etc/passwd entry can be modified by this command. Only fields entered on the command line will be modified. passmgmt -d deletes the entry for user name from the password files. It will not remove any files that the user owns on the system; they must be removed manually. passmgmt can be used only by the super-user. OPTIONS
-c comment A short description of the login, enclosed in quotes. It is limited to a maximum of 128 characters and defaults to an empty field. -e expire Specify the expiration date for a login. After this date, no user will be able to access this login. The expire option argument is a date entered using one of the date formats included in the template file /etc/datemsk. See getdate(3C). -f inactive The maximum number of days allowed between uses of a login ID before that ID is declared invalid. Normal values are posi- tive integers. A value of 0 defeats the status. -g gid GID of name. This number must range from 0 to the maximum non-negative value for the system. The default is 1. -h homedir Home directory of name. It is limited to a maximum of 256 characters and defaults to /usr/name. -K key=value Set a key=value pair. See user_attr(4), auth_attr(4), and prof_attr(4). The valid key=value pairs are defined in user_attr(4), but the "type" key is subject to the usermod(1M) and rolemod(1M) restrictions. Multiple key=value pairs may be added with multiple -K options. -k skel_dir A directory that contains skeleton information (such as .profile) that can be copied into a new user's home directory. This directory must already exist. The system provides the /etc/skel directory that can be used for this purpose. -l logname This option changes the name to logname. It is used only with the -m option. The total size of each login entry is limited to a maximum of 511 bytes in each of the password files. -o This option allows a UID to be non-unique. It is used only with the -u option. -s shell Login shell for name. It should be the full pathname of the program that will be executed when the user logs in. The maxi- mum size of shell is 256 characters. The default is for this field to be empty and to be interpreted as /usr/bin/sh. -u uid UID of the name. This number must range from 0 to the maximum non-negative value for the system. It defaults to the next available UID greater than 99. Without the -o option, it enforces the uniqueness of a UID. FILES
/etc/passwd /etc/shadow /etc/opasswd /etc/oshadow ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWcsu | +-----------------------------+-----------------------------+ |Interface Stability |Evolving | +-----------------------------+-----------------------------+ SEE ALSO
passwd(1), rolemod(1M), useradd(1M), userdel(1M), usermod(1M), auth_attr(4), passwd(4), prof_attr(4), shadow(4), user_attr(4), attributes(5) EXIT STATUS
The passmgmt command exits with one of the following values: 0 Success. 1 Permission denied. 2 Invalid command syntax. Usage message of the passmgmt command is displayed. 3 Invalid argument provided to option. 4 UID in use. 5 Inconsistent password files (for example, name is in the /etc/passwd file and not in the /etc/shadow file, or vice versa). 6 Unexpected failure. Password files unchanged. 7 Unexpected failure. Password file(s) missing. 8 Password file(s) busy. Try again later. 9 name does not exist (if -m or -d is specified), already exists (if -a is specified), or logname already exists (if -m -l is speci- fied). NOTES
Do not use a colon (:) or RETURN as part of an argument. It is interpreted as a field separator in the password file. The passmgmt command will be removed in a future release. Its functionality has been replaced and enhanced by useradd, userdel, and usermod. These commands are currently available. This command only modifies password definitions in the local /etc/passwd and /etc/shadow files. If a network nameservice such as NIS or NIS+ is being used to supplement the local files with additional entries, passmgmt cannot change information supplied by the network name- service. SunOS 5.10 9 Mar 2004 passmgmt(1M)
All times are GMT -4. The time now is 03:42 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy