46 lines
1.1 KiB
TypeScript
46 lines
1.1 KiB
TypeScript
import { exec } from "child_process"
|
|
|
|
const remoteCommand =
|
|
process.env.DISK_REMOTE_COMMAND ||
|
|
"ssh malio-b@192.168.0.179 'cd /home/malio-b/Scripts-Serveur && bash check_storage.sh && exit'"
|
|
|
|
const localCommand =
|
|
process.env.DISK_LOCAL_COMMAND ||
|
|
"bash /home/kevin/check_storage.sh"
|
|
|
|
function runCommand(command: string): Promise<string> {
|
|
return new Promise((resolve, reject) => {
|
|
exec(command, (error, stdout, stderr) => {
|
|
if (error) {
|
|
reject(stderr || error.message)
|
|
return
|
|
}
|
|
resolve(stdout)
|
|
})
|
|
})
|
|
}
|
|
|
|
export default defineEventHandler(async () => {
|
|
const [remoteResult, localResult] = await Promise.allSettled([
|
|
runCommand(remoteCommand),
|
|
runCommand(localCommand)
|
|
])
|
|
|
|
return {
|
|
remote: {
|
|
ok: remoteResult.status === "fulfilled",
|
|
output:
|
|
remoteResult.status === "fulfilled"
|
|
? remoteResult.value
|
|
: `Erreur: ${String(remoteResult.reason)}`
|
|
},
|
|
local: {
|
|
ok: localResult.status === "fulfilled",
|
|
output:
|
|
localResult.status === "fulfilled"
|
|
? localResult.value
|
|
: `Erreur: ${String(localResult.reason)}`
|
|
}
|
|
}
|
|
})
|