I have to provide a listing of all usernames and group assignments on Linux servers running SLES 12 SP 3. I am trying to automate this via a #for loop. It is not doing as desired and could use a little assistance. Here is the code:
I am still very new to UNIX but have a mild programming background. Just not sure where I am failing here. In the file I am hoping to have the $uname variable then the output from the #groups command followed by a new line input.
I think you're very nearly there, but perhaps have just over-complicated things a bit. You can do all this with just the one input file, the one output file, and the groups command.
Here's my proposed solution. I've assumed that the input file simply contains usernames listed one per line (since there's no sample input to go on in your post) Other than that, I believe this should do what you need.
So the basic idea is that for each username we run the groups command to get the list of UNIX groups for that user, then use awk to just print out the part of the output of the groups command that we need. We then write the username and our list of groups to a single line in the output file, and move on to the next user until there is no input left to read.
Hope this helps ! If not, then if you can clarify what aspects of this script don't fit with your expectations in terms of behaviour or output, then we can take things from there.
I'm not quite sure what could have gone wrong, since I'm not seeing any sign of you having run the script or the output file being created here. If you run the version of the script that I supplied in the previous response, what exactly do you get as the output in your terminal ? Does the format of the input conform to my assumptions ? If not, then you'd need to modify the script accordingly to fit whatever format your input is actually in.
This would to me indicate that something has gone wrong when you copied-and-pasted the script code into your terminal. The ^M character is used by Windows to mark the end of lines in a file, and is not used by UNIX-style OS's by and large. So you've somehow ended up with Windows-style EOL characters embedded in the script here, which your server is treating as part of the shell filename. If you can strip those out or get this script onto your server in a different way it should work (if, as i say, the input assumptions I've made are correct).
Experts,
I am writing a script and able to write only small piece of code and not able to collect logic to complete this task.
In input file have to look for name like like this (BGL_HSR_901_1AG_A_CR9KTR10) before sh iss neors. Record this (BGL_HSR_901_1AG_A_CR9KTR10) in csv file
Now have to... (0 Replies)
Linux System having all Perl, Python, PHP (and Ruby) installed
From a Shell script, can call a Perl, Python, PHP (or Ruby ?) file
eg
eg
a Shell script run in a case statement call to run a php file, also Perl or/and Python file???
Like
#!/usr/bin/bash
....
....
case $INPUT_STRING... (1 Reply)
Hi all. I need a shell script that can, in short, read through a text file line by line and create a new user in Ubuntu, as well as assign that user to a group. The format of the text file is not important but preferably: 'username:group'. I don't have much programming knowledge no matter shell... (3 Replies)
Hi,
how do I read in a file which includes a list of workstations and then run a command for each workstation ?
I am unclear which command to use to read in , or is this not possible ?
Thanks, (3 Replies)
Hi,
I am just new to scripting but got to write a complex scipt please help. i need a shell script which can check the list of data listed in a txt doc and see if they belong to any of the groups that are listed in other list file.... (5 Replies)
how to run an already developed script run against a list of ip addresses solaris 8 question.
the script goes away and check traffic information, for example
check_GE-VLANStats-P3 1.1.1.1
and returns the results ok.
how do I run this against an ip list? i.e a list of 30 ip addresses (26 Replies)
Hi all,
I am trying to create a shell script from solaris 10 server to run a command into multiple specific value in one file. The command is related to Oracle/Sun JES2005Q4 directory server.
#this is the command,
#from path /jes/ds/slapd-rldap1
./ns-inactivate.pl -h mldap1 -p 389 -D... (12 Replies)
Hi
Please help me to resolve.
Question:
I can run this command to change the mode of a device with id=500 as below
dbc "select device mode=3 where id=500;"
How can i run the same query with a file contaning n number of ids ?
file1.txt
12
234
34
500
34
45
Thanks in... (3 Replies)
Hi. Thanks for any help with this. I'm not new to programming but I am new to shell programming. I need a script that will
1. execute 'df -k' and return the volume names with specific text
2. surround each line of the above results in opening and closing xml tags
3. insert the results of step... (5 Replies)