1. Go to this page and download the library: Download tourze/server-shell-bundle library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
use ServerShellBundle\Service\ShellScriptService;
use ServerNodeBundle\Entity\Node;
// Inject the service
public function __construct(
private ShellScriptService $shellScriptService
) {}
// Create a new script
$script = $this->shellScriptService->createScript(
name: 'System Update',
content: "#!/bin/bash\napt update && apt upgrade -y",
workingDirectory: '/tmp',
useSudo: true,
timeout: 300,
tags: ['system', 'update'],
description: 'Updates system packages'
);
// Execute script on a node
$node = $this->nodeRepository->find(1);
$execution = $this->shellScriptService->executeScript($script, $node);
// Check execution status
echo "Status: " . $execution->getStatus()->value;
echo "Result: " . $execution->getResult();
// Schedule script for async execution
$execution = $this->shellScriptService->scheduleScript($script, $node);
// The script will be executed asynchronously via Symfony Messenger
// Check status later using the execution ID
$execution = $this->shellScriptService->findExecutionById($execution->getId());