mirror of https://github.com/tildeclub/site.git
Create updateonline-users
This commit is contained in:
parent
d73b120723
commit
7a622eee6d
|
@ -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);
|
||||||
|
?>
|
Loading…
Reference in New Issue