Всем привет.
Подскажите как лучше всего (вывод стандартной комадны, не открывание и парсинг файлов) получить список пользователей из primary group.
Через id -gn я могу получить имя группы. Мне нужно наоборот - по названию этой группы получить список пользователей.
id указывает gid, но getent group <NAME> возвращает пустой список, т.е. получается что пользователь относится к пустой группе (с количеством пользователей 0). Я хочу узнать кто еще относится к этой группе.
спискок пользоаателей из primary group (id, getent, ...)
Модератор: /dev/random
-
- Сообщения: 2041
- Статус: ☮ PEACE ☮
- ОС: открытая и свободная
спискок пользоаателей из primary group
Labor omnia vincit
"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.” (Brian Kernighan)
"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.” (Brian Kernighan)
-
- Модератор
- Сообщения: 21115
- Статус: nulla salus bello
- ОС: Debian GNU/Linux
Re: спискок пользоаателей из primary group
getent passwd | grep "^[^:]*:[^:]*:[^:]*:$gid:" | cut -d: -f1
Пишите правильно:
в консоли вку́пе (с чем-либо) в общем вообще | в течение (часа) новичок нюанс по умолчанию | приемлемо проблема пробовать трафик |
-
- Сообщения: 2041
- Статус: ☮ PEACE ☮
- ОС: открытая и свободная
Re: спискок пользоаателей из primary group
Не показывает никого.
Labor omnia vincit
"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.” (Brian Kernighan)
"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.” (Brian Kernighan)
-
- Модератор
- Сообщения: 21115
- Статус: nulla salus bello
- ОС: Debian GNU/Linux
Re: спискок пользоаателей из primary group
В $gid должен быть GID (числовой).
Пишите правильно:
в консоли вку́пе (с чем-либо) в общем вообще | в течение (часа) новичок нюанс по умолчанию | приемлемо проблема пробовать трафик |
-
- Сообщения: 2041
- Статус: ☮ PEACE ☮
- ОС: открытая и свободная
Re: спискок пользоаателей из primary group
У меня ничего не возвращает. Ни в Kubuntu, ни в openSUSE.
Labor omnia vincit
"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.” (Brian Kernighan)
"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.” (Brian Kernighan)
-
- Модератор
- Сообщения: 21115
- Статус: nulla salus bello
- ОС: Debian GNU/Linux
Re: спискок пользоаателей из primary group
Shell
% getent passwd | grep "^[^:]*:[^:]*:[^:]*:65534:" | cut -d: -f1
sync
nobody
statd
sshd
gitlog
gitdaemon
miredo
dnsmasq
_apt
debianfdm
%
Пишите правильно:
в консоли вку́пе (с чем-либо) в общем вообще | в течение (часа) новичок нюанс по умолчанию | приемлемо проблема пробовать трафик |
-
- Модератор
- Сообщения: 4823
- Статус: фанат консоли (=
- ОС: GNU/Debian, RHEL
Re: спискок пользоаателей из primary group
Как страшно (:
Проще же через awk: getent passwd | awk -F: '{if($4=='$gid')print $1}'
UNIX is basically a simple operating system, but you have to be a genius to understand the simplicity. © Dennis Ritchie
The more you believe you don't do mistakes, the more bugs are in your code.
The more you believe you don't do mistakes, the more bugs are in your code.
Спасибо сказали:
-
- Модератор
- Сообщения: 21115
- Статус: nulla salus bello
- ОС: Debian GNU/Linux
Re: спискок пользоаателей из primary group
Не люблю awk. ☺
Пишите правильно:
в консоли вку́пе (с чем-либо) в общем вообще | в течение (часа) новичок нюанс по умолчанию | приемлемо проблема пробовать трафик |
-
- Сообщения: 2041
- Статус: ☮ PEACE ☮
- ОС: открытая и свободная
Re: спискок пользоаателей из primary group
Апостроф 4 раза используется

Bizdelnick писал(а): ↑09.02.2018 22:52Shell
% getent passwd | grep "^[^:]*:[^:]*:[^:]*:65534:" | cut -d: -f1 sync nobody statd sshd gitlog gitdaemon miredo dnsmasq _apt debianfdm %
Спасибо. Да, если подставлять вручную, то работает. Теперь осталось только придумать как подставлять динамически этот числовой gid...
Я вот что понять не могу. Почему нет стандарного метода получить этот список и обязательно надо самому парсить?
Labor omnia vincit
"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.” (Brian Kernighan)
"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.” (Brian Kernighan)
-
- Модератор
- Сообщения: 4823
- Статус: фанат консоли (=
- ОС: GNU/Debian, RHEL
Re: спискок пользоаателей из primary group
Stauffenberg писал(а): ↑10.02.2018 03:12Теперь осталось только придумать как подставлять динамически этот числовой gid
gid=$(id -g "имя_группы")
getent passwd | grep "^[^:]*:[^:]*:[^:]*:$gid:" | cut -d: -f1
getent passwd | grep "^[^:]*:[^:]*:[^:]*:$gid:" | cut -d: -f1
должно работать.
Видимо это не такая популярная операция. Но никто не мешает отправить pull request ;)Stauffenberg писал(а): ↑10.02.2018 03:12Почему нет стандарного метода получить этот список и обязательно надо самому парсить?
UNIX is basically a simple operating system, but you have to be a genius to understand the simplicity. © Dennis Ritchie
The more you believe you don't do mistakes, the more bugs are in your code.
The more you believe you don't do mistakes, the more bugs are in your code.
-
- Модератор
- Сообщения: 21115
- Статус: nulla salus bello
- ОС: Debian GNU/Linux
Re: спискок пользоаателей из primary group
Апострофофобия?
Пишите правильно:
в консоли вку́пе (с чем-либо) в общем вообще | в течение (часа) новичок нюанс по умолчанию | приемлемо проблема пробовать трафик |
-
- Сообщения: 2041
- Статус: ☮ PEACE ☮
- ОС: открытая и свободная
Re: спискок пользоаателей из primary group
SLEDopit писал(а): ↑10.02.2018 10:27Stauffenberg писал(а): ↑10.02.2018 03:12Теперь осталось только придумать как подставлять динамически этот числовой gidgid=$(id -g "имя_группы")
getent passwd | grep "^[^:]*:[^:]*:[^:]*:$gid:" | cut -d: -f1
должно работать.
Нет, не должно... т.к. id ожидает имя_пользователя как аргумент, а не имя_группы
Labor omnia vincit
"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.” (Brian Kernighan)
"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.” (Brian Kernighan)
-
- Сообщения: 2041
- Статус: ☮ PEACE ☮
- ОС: открытая и свободная
Re: спискок пользоаателей из primary group
Да и так и так не работает если данные идут из LDAP, к примеру

Labor omnia vincit
"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.” (Brian Kernighan)
"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.” (Brian Kernighan)