mirror of https://github.com/tildeclub/site.git
18 lines
562 B
PHP
Executable File
18 lines
562 B
PHP
Executable File
#!/usr/bin/php
|
|
<?php
|
|
// Define the path to the JSON file
|
|
$jsonFile = '/usr/share/nginx/html/online-users.json';
|
|
|
|
// Run the `who` command to get the list of active users
|
|
$activeUsers = shell_exec("who | awk '{print $1}' | sort | uniq");
|
|
|
|
// Convert the output into an array, filtering out any empty lines
|
|
$activeUsersArray = array_filter(explode("\n", $activeUsers));
|
|
|
|
// Convert the array to JSON format
|
|
$activeUsersJson = json_encode($activeUsersArray, JSON_PRETTY_PRINT);
|
|
|
|
// Write the JSON data to the file
|
|
file_put_contents($jsonFile, $activeUsersJson);
|
|
?>
|