The who
command in FreeBSD knows a file
argument from where read informations about the logged-in users, the default is /var/run/utx.active
- and the file is usually world-readable...
Probably will be enough the next script:
#!/usr/local/bin/bash
while read jpath
do
echo JWHO: ${jpath:-$(hostname)}
who "${jpath}/var/run/utx.active"
done < <( jls -h path | sed '1s:.*::' )
example output:
JWHO: marvin.example.com
smith pts/0 7 nov 20:55 (adsl2343-some-another.example.com)
JWHO: /jails/jail1
JWHO: /jails/testjail
root pts/2 7 nov 20:55 (someother.example.com)
JWHO: /jails/dbjail
steps:
- show the path to "root filesystem" for all running jails
- run the who for the
/var/run/utx.active
for the given jail
- skip the header line from the jls, - so the 1st output will be the host.
Maybe someone know much simpler solution, e.g. by sorting the ps
output or something like...
Comments: you usually don't want to use constructions like command | while read
- the pipe forks new shell and you losing values of the variables set inside of the loop, the done < <( commands )
is usually better...