IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Langage PHP Discussion :

exécuter un scipt php en ligne de commande sous freebsd


Sujet :

Langage PHP

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Nouveau candidat au Club
    Homme Profil pro
    Administrateur systèmes et réseaux
    Inscrit en
    Janvier 2016
    Messages
    2
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Alpes Maritimes (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Administrateur systèmes et réseaux

    Informations forums :
    Inscription : Janvier 2016
    Messages : 2
    Par défaut exécuter un scipt php en ligne de commande sous freebsd
    Bonjour,

    Sur une serveur pfsense, un script php peut être lancé manuellement via l'interface web:
    https://192.168.200.1:999/status_services.php?mode=startservice&service=captiveportal&zone=wifi

    Je souhaiterais lancer ce même script en ligne de commande.
    chemin du fichier "status_services.php": /usr/local/www/status_services.php
    chemin du fichier php: /usr/local/bin/php

    contenu du fichier "status_services.php": voir ci-dessous

    Je ne fais pas de développement donc lancer un script simple, y'aurait pas eu de problème, mais avec les arguments en plus, ça va au delà de mes compétences.
    Si quelqu'un peut me dire quelle est la ligne de commande qui va bien ?

    Merci par avance



    ---------------------------------------------------------------------------------------
    contenu du fichier "status_services.php":
    ---------------------------------------------------------------------------------------
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
     
    <?php
    /*
    	status_services.php
    	Copyright (C) 2004, 2005 Scott Ullrich
    	Copyright (C) 2013-2015 Electric Sheep Fencing, LP
    	All rights reserved.
    
    	Redistribution and use in source and binary forms, with or without
    	modification, are permitted provided that the following conditions are met:
    
    	1. Redistributions of source code must retain the above copyright notice,
    	   this list of conditions and the following disclaimer.
    
    	2. Redistributions in binary form must reproduce the above copyright
    	   notice, this list of conditions and the following disclaimer in the
    	   documentation and/or other materials provided with the distribution.
    
    	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
    	INClUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
    	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
    	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
    	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
    	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
    	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
    	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
    	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    	POSSIBILITY OF SUCH DAMAGE.
    */
    /*	
    	pfSense_BUILDER_BINARIES:	/usr/local/sbin/openvpn	/usr/bin/killall	/bin/ps
    	pfSense_MODULE:	services
    */
     
    ##|+PRIV
    ##|*IDENT=page-status-services
    ##|*NAME=Status: Services page
    ##|*DESCR=Allow access to the 'Status: Services' page.
    ##|*MATCH=status_services.php*
    ##|-PRIV
     
    require_once("guiconfig.inc");
    require_once("service-utils.inc");
    require_once("shortcuts.inc");
     
    $service_name = '';
    if (isset($_GET['service']))
    	$service_name = htmlspecialchars($_GET['service']);
     
    if (!empty($service_name)) {
    	switch ($_GET['mode']) {
    		case "restartservice":
    			$savemsg = service_control_restart($service_name, $_GET);
    			break;
    		case "startservice":
    			$savemsg = service_control_start($service_name, $_GET);
    			break;
    		case "stopservice":
    			$savemsg = service_control_stop($service_name, $_GET);
    			break;
    	}
    	sleep(5);
    }
     
    /* batch mode, allow other scripts to call this script */
    if($_GET['batch'])
    	exit;
     
    $pgtitle = array(gettext("Status"),gettext("Services"));
    include("head.inc");
     
    ?>
     
    <body link="#0000CC" vlink="#0000CC" alink="#0000CC">
    <?php
    include("fbegin.inc");
    ?>
    <form action="status_services.php" method="post">
    <?php if ($savemsg) print_info_box($savemsg); ?>
     
    <div id="boxarea">
    <table class="tabcont sortable" width="100%" border="0" cellpadding="0" cellspacing="0" summary="status services">
    	<thead>
    	<tr>
    		<td class="listhdrr" align="center"><?=gettext("Service");?></td>
    		<td class="listhdrr" align="center"><?=gettext("Description");?></td>
    		<td class="listhdrr" align="center"><?=gettext("Status");?></td>
    	</tr>
    	</thead>
    	<tbody>
    <?php
     
    $services = get_services();
     
    if (count($services) > 0) {
    	uasort($services, "service_name_compare");
    	foreach($services as $service) {
    		if (empty($service['name']))
    			continue;
    		if (empty($service['description']))
    			$service['description'] = get_pkg_descr($service['name']);
    		echo "<tr><td class=\"listlr\" width=\"20%\">" . $service['name'] . "</td>\n";
    		echo "<td class=\"listr\" width=\"55%\">" . $service['description'] . "</td>\n";
    		// if service is running then listr else listbg
    		$bgclass = null;
    		if (get_service_status($service))
    			$bgclass = "listr";
    		else
    			$bgclass = "listbg";
    		echo "<td class=\"" . $bgclass . "\" align=\"center\">" . get_service_status_icon($service, true, true) . "</td>\n";
    		echo "<td valign=\"middle\" class=\"list nowrap\">" . get_service_control_links($service);
    		$scut = get_shortcut_by_service_name($service['name']);
    		if (!empty($scut)) {
    			echo get_shortcut_main_link($scut, true, $service);
    			echo get_shortcut_status_link($scut, true, $service);
    			echo get_shortcut_log_link($scut, true);
    		}
    		echo "</td></tr>\n";
    	}
    } else {
    	echo "<tr><td colspan=\"3\" align=\"center\">" . gettext("No services found") . " . </td></tr>\n";
    }
     
    ?>
    </tbody>
    </table>
    </div>
    </form>
    <?php include("fend.inc"); ?>
    </body>
    </html>

  2. #2
    Modérateur
    Avatar de kolodz
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2008
    Messages
    2 209
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 38
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Produits et services télécom et Internet

    Informations forums :
    Inscription : Avril 2008
    Messages : 2 209
    Billets dans le blog
    52
    Par défaut
    Bonjour,

    Logiquement la commande suivante devrait fonctionné :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    /usr/local/bin/php -f /usr/local/www/status_services.php
    Comme indiqué dans la documentation PHP officiel :
    Utilisation des lignes de commande

    Cordialement,
    Patrick Kolodziejczyk.

    Note : Peu-x tu éditer ton message et ajouter la balise CODE à ton script ? (Bouton # dans l'interface)
    Si une réponse vous a été utile pensez à
    Si vous avez eu la réponse à votre question, marquez votre discussion
    Pensez aux FAQs et aux tutoriels et cours.

  3. #3
    Nouveau candidat au Club
    Homme Profil pro
    Administrateur systèmes et réseaux
    Inscrit en
    Janvier 2016
    Messages
    2
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Alpes Maritimes (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Administrateur systèmes et réseaux

    Informations forums :
    Inscription : Janvier 2016
    Messages : 2
    Par défaut
    Merci pour la réponse.
    Jusque là je savais faire. C'est après où je bloque.

    Comment ajouter les arguments suivants?
    mode=startservice
    service=captiveportal
    zone=wifi

    j'ai bien essayé la commande suivante
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    /usr/local/bin/php -f /usr/local/www/status_services.php?mode=startservice&service=captiveportal&zone=wifi
    mais j'ai comme réponse

    /usr/local/bin/php: no match
    service=captiveportal: command not found
    zone=wifi: commande not found

  4. #4
    Modérateur
    Avatar de kolodz
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2008
    Messages
    2 209
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 38
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Produits et services télécom et Internet

    Informations forums :
    Inscription : Avril 2008
    Messages : 2 209
    Billets dans le blog
    52
    Par défaut
    /usr/local/bin/php: no match
    Est-tu sur que le binaire php se trouve à cette emplacement ?

    Pour le reste :
    Va lire la documentation !
    Si une réponse vous a été utile pensez à
    Si vous avez eu la réponse à votre question, marquez votre discussion
    Pensez aux FAQs et aux tutoriels et cours.

Discussions similaires

  1. exécuter un script php en ligne de commande sous windows
    Par zemzoum89 dans le forum Langage
    Réponses: 4
    Dernier message: 03/02/2011, 18h38
  2. Exécution de php en ligne de commande
    Par tiamat59 dans le forum Administration système
    Réponses: 2
    Dernier message: 29/09/2010, 11h09
  3. exécuter un url php en ligne de commande
    Par MedNaceur dans le forum EDI, CMS, Outils, Scripts et API
    Réponses: 4
    Dernier message: 11/12/2009, 22h32
  4. Exécuter un script PHP en ligne de commande
    Par sami_c dans le forum Unix
    Réponses: 4
    Dernier message: 09/05/2009, 15h28
  5. Réponses: 6
    Dernier message: 29/05/2008, 12h22

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo