I have thousands of users assigned various roles. The role header defines the GID that they should have. If I can get all the GID information into /etc/group format I can upload the output file and easily assign all users into the desired GID. Right now I can get an output file like this:
There's nothing wrong with uploading the file like this, but it's pretty big. The way I produce this is via the following function:
tmp_gid_file has a list of GID's line by line. I have to search the GID in a master file instead of getent group (it's a long story) and it returns <group_name>:<GID> so that's why I have to replace the colon with a :x:
I'd like to produce a GID file that has only 1 GID entry per line and does not duplicate. I would like it to look like this:
I started with an if statement but I have a problem appending the user's ID to the end of the line where the GID is found:
I'm using GNU/Linux (that's what I get from uname -a...not sure if it's rhel or suse or what) and my shell is bash.
If you can decompose the installed user ids and each gid into lines in a simple file, and do the same for the desired user ids and gid, then you can sort them and pass them to comm to find out what is missing. On bash, and ksh on systems with /dev/fd/[0-9]*, you can pipe it all and have less clutter and selay:
I figured it out before I was able to consider some of your suggestions I grep the destination file to see if the GID already exists in the file that I store that in a variable. If that variable is empty then I append the GID definition to the bulkload file. If the variable is not null then I remove the line that contains the GID definition and then replace it with the same thing but with the user's id appended at the end.
Probably not very efficient as DGPickett points out...I may have to try a different logic as we increase in numbers.
Yes, it is nice to avoid n^2 problems at the start! Solutions with comm are very robust and scale well, can exploit multiprocessing and such well, detect both negative (missing) and positive (wrong) problems!
I would like to get an opinion for my solution for this task and get feedback about better approach or mistakes I have made.
1. The problem statement, all variables and given/known data:
The task is to create a script which prints information about users whose names are specified in the... (2 Replies)
I need to list users in /etc/passwd with root's GID or UID or /root as home directory
If we have these entries in /etc/passwd
root:x:0:0:root:/root:/bin/bash
rootgooduser1:x:100:100::/home/gooduser1:/bin/bash
baduser1:x:0:300::/home/baduser1:/bin/bash... (6 Replies)
Hi
#Testing for file existence
if ; then
echo 'SCHOOL data is available for processing'
else
echo 'SCHOOL DATA IS NOT AVAILABLE FOR PROCESSING'
:
i wrote a script, where it begins by checking if file exists or not.
If it exists, it truncates the database... (2 Replies)
Present
/home/dsadm# id dsadm
uid=0(root) gid=0(root)
----------------------------------
needs to be
/home/dsadm> id dsadm
uid=23186(dsadm) gid=16284(gdstage)
Please provide the command/steps for the above uid, gid value change
Thanks in advance for all your support .
... (3 Replies)
Hi there,
One can easily retrieve the uid from a username :
id -u $username
But how can we easily retrieve the gid from a group name?
I mean is there a command without using sed?
sed -nr "s/^$groupname:x:(+):.*/\1/p" /etc/group
Thanks for your help
Santiago (7 Replies)
I will have to process multiple files with same name everyday.
My requirement is:
If on a certain day I see that filename.txt exists then the contents of the filename.txt would be added/append
to the former file contents.Each time it sees the file the content would be added.But the header ... (8 Replies)
rm: Unable to remove directory /mnt/users/test/logs/: File exists
ls -latr
total 191208
drwxrwxrwx 6 test echo 4096 Jul 3 22:36 ..
-rwxrwxrwx 1 test echo 97692804 Jul 3 22:36 .nfsDFA4
drwxrwxr-x 2 test echo 4096 Jul 3 23:00 .
M not able to delete... (4 Replies)
Hi,
can somebody tell me how to make directoriy in which all files will be generated as dir owner ?
I'm able to add GID for directory group and files have group id like folder , but when i do same for user files still are created as user which creates them :(
drwsrwsrwx 2 flexbul ... (2 Replies)