0
I have been trying to write a command (Solaris server) that adds a user to a specific group. It's a pretty long command so I'll post the whole command here and then break it down.
USER=myUser && sudo /usr/sbin/usermod -G `awk -v delim="," -F: '/[:,]'$USER'/ { groups = groups $1 delim; } END { groups = groups "myGroup"; print groups}' /etc/group` myUser
The inner awk command compiles a comma-delimited list of current groups and the outer command takes this list in the -G parameter.
Both awk and usermod are giving me syntax errors (near line 1, but there's only one line), but I have a feeling one error is caused by the other.
Are there any glaring syntax errors here that I'm missing? Could this be caused by a shell issue? As a disclaimer, I am using the && construct instead of a semicolon due to some higher-level text processing issues but that should not affect the execution, in my opinion (I have tested it).
Rather than asking us to fix your broken code, it would be best to give sample input and desired output. It is highly likely that the best answer may not be the way you're trying to do it. – SiegeX – 2012-01-26T22:49:29.570
I should've explained more clearly in my question that I am absolutely bound to using this pattern due to its use in a larger application. Also, I described the input and output if you read the post carefully: "The inner awk command compiles a comma-delimited list of current groups and the outer usermod command takes this list in the -G paramter." Given this information, I expect the usermod command to work as anyone would expect given those parameters. – Mark – 2012-01-27T15:01:57.740