Reputation:
I have a bash script that is gathering active users on a machine and then I am going to curl away the data. The issue is that the first item in the list won't show up, it is gathering everything after the first. Can anyone explain why?
#!/bin/bash
users=$(ps -eo ruser,rgroup | grep users | sort | uniq | cut -d ' ' -f1)
while read -r users
do
newVar=$newVar$(awk '{print "user_name{name=\""$users"\"}", 1.0}');
done <<< "$users"
Then I curl newVar which should be a concatenation of all users in the format that is required.
Upvotes: 0
Views: 160
Reputation: 780818
There's no need for the users
variable or the while read
loop. Just pipe the output of the ps
pipe directly to awk
.
You don't need cut
, since awk
can select the first column with $1
. And sort | uniq
can be combined into sort -u
.
newVar=$(ps -eo ruser,rgroup | grep users | sort -u | awk '{printf ("username{name=\"%s\"} 1.0", $1)
Upvotes: 0