This commit is contained in:
Bozhidar Slaveykov 2023-11-27 15:36:50 +02:00
parent 92723c59a5
commit b831e6f464
3 changed files with 33 additions and 9 deletions

View file

@ -1 +1,5 @@
crontab -u phyreweb -l
# Replace 'username' with the actual username you want to retrieve cron jobs for
username=$1
# Get the user's crontab entries and convert them to JSON
crontab -u $username -l | grep -v -e '^#' -e '^\s*$' | awk '{print "{\"schedule\":\"" $1 " " $2 " " $3 " " $4 " " $5 "\", \"command\":\"" substr($0, index($0,$6)) "\"}"}' | jq -s .

View file

@ -31,7 +31,16 @@ class CronJobResource extends Resource
{
return $table
->columns([
//
Tables\Columns\TextColumn::make('schedule')
->searchable()
->sortable(),
Tables\Columns\TextColumn::make('command')
->searchable()
->sortable(),
Tables\Columns\TextColumn::make('user')
->searchable()
->sortable(),
])
->filters([
//

View file

@ -13,14 +13,25 @@ class CronJob extends Model
public function getRows()
{
exec('/usr/local/phyre/bin/list-cron-jobs.sh', $output);
$user = shell_exec('whoami');
$cronList = shell_exec('/usr/local/phyre/bin/list-cron-jobs.sh ' . $user);
dd($output);
$rows = [];
if (!empty($cronList)) {
$cronList = json_decode($cronList, true);
if (!empty($cronList)) {
foreach ($cronList as $cron) {
if (isset($cron['schedule'])) {
$rows[] = [
'schedule' => $cron['schedule'],
'command' => $cron['command'],
'user' => $user,
];
}
}
}
}
return [
['id' => 1, 'label' => 'admin'],
['id' => 2, 'label' => 'manager'],
['id' => 3, 'label' => 'user'],
];
return $rows;
}
}