Есть проблема на Ubuntu 11.10, при запуске sh скриптов, без активной консоли, команда who не отображает активных пользователей, а в скрипте необходимо знать, какой пользователь активен сейчас. Кто нибудь сталкивался?
(Google Translate's courtesy)
There is a problem on Ubuntu 11.10, when you run the sh script, without the active console, the team who does not show active users, but the script needs to know which user is active right now. Who ever came across?
By the way acpi package has a bug related to my problem, its script is also used by the command who.
$ dpkg -l | grep acpi | awk '{print $2 "_" $3}'
acpi_1.5-3ubuntu1
acpi-support_0.138
acpid_1:2.0.10-1ubuntu2.3
$ grep who /usr/share/acpi-support/*
/usr/share/acpi-support/power-funcs: user=$(who | awk "/:$displaynum)/ { print \$1; exit }")
/usr/share/acpi-support/power-funcs: user=$(who | awk "/:$displaynum/ { print \$1; exit }")
I think this can be fixed:
user=$(users | sed 's | |\n|g' | uniq)
____ Updated 12.01.2012
The problem is not solved!
Small amusing experiment:
for the test with who and user commands, I run the terminal, and add the following lines to /etc/crontab:
* * * * * root echo 'who: '`who` >> /123
* * * * * root echo 'users: '`users` >> /123
* * * * * root echo 'users /var/run/utmp: '`users /var/run/utmp` >> /123
* * * * * root echo 'users /var/log/wtmp: '`users /var/log/wtmp` >> /123
And check the /123 file when terminal is running:
users /var/log/wtmp: administrator administrator...
who: administrator pts/3 2012-01-12 14:59 (:0.0)
users: administrator
users /var/run/utmp: administrator
when terminal is closed:
who:
users:
users /var/run/utmp:
users /var/log/wtmp: administrator administrator ...
Again, the question of how to get a list of users logged on to the system (X session), from the console as root.
Until I see only one solution:
user=$(users /var/log/wtmp | sed 's| |\n|g' | uniq)`
Who knows a more elegant solution? Or is this just an option?
Or maybe it's still a bug?