Bonjour à tous
Je tourne un peu en rond avec un script qui pourtant me semble tout bête mais qui me pose problème, j'arrive pas à dépanner
Il s'agit d'un script PHP qui appelle un script Shell (expect) et qui est sensé loguer la console dans un fichier de log
Voici le fichier PHP "testmicro.php"
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6 <?php ini_set('error_reporting', E_ALL); $cmd ="/var/www/script/test.sh 192.168.145.11 >> /var/www/script/logs/test.log"; $result = shell_exec("$cmd"); ?>
Voici le script Shell
Bon tout ceci fonctionne parfaitement lorsque je lance le script en Shell (avec l'ID www-data) -- >/var/www/script/test.sh 192.168.145.11 >> test.log
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 #!/usr/bin/expect set timeout 5 set IPaddress [lindex $argv 0] set username "admin" set password "XXXXXXX" set enablepassword "XXXXXXXX" set Directory "/logs" log_file /var/www/script/logs/session_$IPaddress.log send_log "### /START-SSH-SESSION/ IP: $IPaddress @ [exec date] ###\r" spawn telnet $IPaddress expect "login:" { send "$username\n" expect "Password:" send "$password\n" expect ">" { send "WhoAmI\r" } send "logout\r" interact } send_log "\r### /END-SSH-SESSION/ IP: $IPaddress @ [exec date] ###\r" exit
Tout ceci fonctionne parfaitement lorsque je lance le PHP en mode console (avec l'ID www-data --> /usr/bin/php /var/www/testmicro.php
le résultat du fichier test.log normal est le suivant :
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 spawn telnet 192.168.145.11^M Trying 192.168.145.11...^M Connected to 192.168.145.11.^M Escape character is '^]'.^M ^M^M MICROSENS G6 Micro-Switch^M ^MMICROSENS-G6-MAC-00-60-A7-08-16-9E login: admin^M Password: ^M ^[(B^[)0^[[1;65r^[[m^O^[[4l^[[?7h^[[?1h^[=^M^[[33m>>^[[0m^[[H^[[JCommand Line Interface (CLI) / MICROSENS G6 Micro-Switch^M System name: TEST JU^M You are logged in as ^[[36madmin^[[0m (id:242)^M Login status index: 14^M Your general access rights are: ^[[36mRead/Write^[[0m^M ^[[32mType ? for help on operation and for parameter details.^[[0m ^M^[[33m>>^[[0mW^H ^HWhoAmI h^H ^Ho^H ^HA^H ^Hm^H ^HI^H ^H^M System name: TEST JU^M You are logged in as ^[[36madmin^[[0m (id:242)^M Login status index: 14^M Your general access rights are: ^[[36mRead/Write^[[0m^M The following view based access restrictions apply:^M admin group:FULL_ACCESS_VIEW: ^[[35m*^[[0m = ^[[36mREAD/WRITE^[[0m^M ^M^[[33m>>^[[0ml^H ^HLogout o^H ^Hg^H ^Ho^H ^Hu^H ^Ht^H ^H^M ^[[65;1H^M^[[?1l^[>Connection closed by foreign host.^M
Mais des que je lance "testmicro.php" dans un browser, les logs s'arrete toujours au même endroit sans finir
Desolé pour un post si long
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11 spawn telnet 192.168.145.11 Trying 192.168.145.11... Connected to 192.168.145.11. Escape character is '^]'. ^M MICROSENS G6 Micro-Switch ^MMICROSENS-G6-MAC-00-60-A7-08-16-9E login: admin Password: ^[(B^[)0^[[1;24r^[[m^O^[[4l^[[?7h^[[?1h^[=^M^[[33m>>^[[0m^[[H^[[J ~ ~
Si quelqu'un a une idée je suis preneur car je tourne en rond,
Pourquoi la commande exec() donnerai un résultat différent exécuté dans la fenêtre terminal que dans un browser ?
Merci bien
Partager