update
This commit is contained in:
parent
b831e6f464
commit
98b25b8e93
3 changed files with 58 additions and 2 deletions
17
bin/add-cron-job.sh
Normal file
17
bin/add-cron-job.sh
Normal file
|
@ -0,0 +1,17 @@
|
|||
username=$1
|
||||
schedule=$2
|
||||
command=$3
|
||||
|
||||
# Create a temporary file to hold the existing user's crontab
|
||||
crontab -u $username -l > /tmp/temp_crontab
|
||||
|
||||
# Add a new cron job to the temporary file
|
||||
echo "$schedule $command" >> /tmp/temp_crontab
|
||||
|
||||
# Install the modified crontab from the temporary file
|
||||
crontab -u $username /tmp/temp_crontab
|
||||
|
||||
# Remove the temporary file
|
||||
rm /tmp/temp_crontab
|
||||
|
||||
echo "done!"
|
|
@ -23,7 +23,16 @@ class CronJobResource extends Resource
|
|||
{
|
||||
return $form
|
||||
->schema([
|
||||
//
|
||||
Forms\Components\TextInput::make('schedule')
|
||||
->autofocus()
|
||||
->required()
|
||||
->label('Schedule'),
|
||||
Forms\Components\TextInput::make('command')
|
||||
->required()
|
||||
->label('Command'),
|
||||
Forms\Components\TextInput::make('user')
|
||||
->required()
|
||||
->label('User'),
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
|
@ -10,9 +10,38 @@ class CronJob extends Model
|
|||
{
|
||||
use Sushi;
|
||||
|
||||
protected $fillable = [
|
||||
'schedule',
|
||||
'command',
|
||||
'user',
|
||||
];
|
||||
|
||||
protected $schema = [
|
||||
'schedule' => 'string',
|
||||
'command' => 'string',
|
||||
'user' => 'string',
|
||||
];
|
||||
|
||||
public static function boot()
|
||||
{
|
||||
parent::boot();
|
||||
|
||||
static::creating(function ($model) {
|
||||
$args = escapeshellarg($model->user) .' '. escapeshellarg($model->schedule) . ' ' . escapeshellarg($model->command);
|
||||
$addCron = shell_exec('/usr/local/phyre/bin/add-cron-job.sh ' . $args);
|
||||
if (empty($addCron)) {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected function sushiShouldCache()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getRows()
|
||||
{
|
||||
|
||||
$user = shell_exec('whoami');
|
||||
$cronList = shell_exec('/usr/local/phyre/bin/list-cron-jobs.sh ' . $user);
|
||||
|
||||
|
@ -26,6 +55,7 @@ class CronJob extends Model
|
|||
'schedule' => $cron['schedule'],
|
||||
'command' => $cron['command'],
|
||||
'user' => $user,
|
||||
'time'=> time(),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue