Files
Scheduler/app/Bots/BashScript.php
Oskar-Mikael 378355ad5b
All checks were successful
Deploy App / deploy (push) Successful in 11s
Add bot logs
2025-08-31 21:54:18 +02:00

47 lines
1.1 KiB
PHP

<?php
namespace App\Bots;
use Illuminate\Support\Facades\Log;
class BashScript implements BotContract
{
protected array $config;
public function __construct(array $config = [])
{
$this->config = $config;
}
public function run(): void
{
if (!empty($this->config['script'])) {
// Execute the bash script
$script = $this->config['script'];
$output = [];
$returnVar = null;
exec($script, $output, $returnVar);
if ($returnVar !== 0) {
// Log error if the script failed
\Illuminate\Support\Facades\Log::error("Bash script execution failed: " . implode("\n", $output));
} else {
Log::info("Bash script executed successfully: " . implode("\n", $output));
}
}
}
public static function configSchema(): array
{
return [
'script' => [
'type' => 'textarea',
'label' => 'Bash Script',
'rules' => [
'required',
]
],
];
}
}