exécution d'un shell à partir de php
salut et merci d'avance :)
je veux exécuter un shell à partir d'un formulaire en php ce shell fait l'ajout dans hôte dans nagios dans le switch.cfg
le scripte php marche correctement et je reçois le message que l'hôte ajoute mais quand j'ouvre switch.cfg rien a été ajouté
le script php
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| #!/bin/bash
#if [ $# -ne 5 ] ;then
# echo "5 parametres attendu [NOM] [IP] [PARENT] [NOM GROUP] [CONTACT]"
#else
echo "
##########################
define host{
use generic-host
host_name $1
parents $2
alias $3
address $4
event_handler update-nagex-host
hostgroups $5
}
" >> /etc/nagios3/switches/switch.cfg
/etc/init.d/nagios3 restart 1>/dev/null
#fi |
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| <?php
if(isset($_POST['btCreer']))
{
$a=$_POST['nom'];
$b=$_POST['ip'];
$c=$_POST['parent'];
$d=$_POST['groupe'];
$e=$_POST['contact'];
exec("/usr/local/nagios/share/script.sh",$a,$b,$c,$d,$e);
echo'Machine Ajoutee
<META HTTP-EQUIV="refresh" CONTENT="2;URL=ajout.php">';
}
else {
echo'<form action="ajout.php" method="post">
Ajout d\' une nouvelle machine<br /><br /><br />';
echo'Nom de la machine: <input type="text" id="nom" name=nom">
<br /><br />
Adresse IP: <input type="text" id="ip" name="ip">
<br /><br />
Parent: <input type="text" id="parent" name="parent">
<br /><br />
Groupe: <input type="text" id="groupe" name="groupe">
<br /><br />
Contact: <input type="text" id="contact" name="contact">
<br /><br />
<input type="submit" value="Creer" id="btCreer" name="btCreer" onclick="return confirmjs();" />
</form>';
}
?> |
Merci