Create updateonline-users

This commit is contained in:
deepend-tildeclub 2024-08-17 11:19:37 -06:00 committed by GitHub
parent d73b120723
commit 7a622eee6d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 17 additions and 0 deletions

17
updateonline-users Normal file
View File

@ -0,0 +1,17 @@
#!/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);
?>