Bonjour a tous,
Voila, j’ai voulu créer un petit script bash avec dedans du Mysql. J’ai mit cette ligne dans mon fichier bash
mysql -u root -pMotDePasse -h 127.0.0.1 -e "INSERT INTO `host`.`benchmark` (`cpu_model`, `cores`, `cpu_freq`, 'ram', 'swap', 'uptime', 'dl_speed', 'IO', 'runtime', 'heberg') VALUES (`$cname`, `$cores`, `$freq`, '$tram', '$swap', '$up', '$cache', '$io', '$runtime', '$heberg');"
Mais voila ce que ca me retourne malheuresement
./bench.sh: line 34: rankhost: command not found
./bench.sh: line 34: benchmark: command not found
./bench.sh: line 34: cpu_model: command not found
./bench.sh: line 34: cores: command not found
./bench.sh: line 34: cpu_freq: command not found
./bench.sh: line 34: Intel(R): command not found
./bench.sh: line 34: 1: command not found
./bench.sh: line 34: 1862.000: command not found
ERROR 1064 (42000) at line 1: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‹ (, , , ‹ ram ›, ‹ swap ›, ‹ uptime ›, ‹ dl_speed ›, ‹ IO ›, ‹ runtime ›, ‹ heberg ›) VALUES (, › at line 1
Merci d’avance pour votre aide
Salut,
remplace les back quotes (`) par des simple quotes (’) dans les deux closes entre parenthèses.
La présence de back quotes signifie à bash qu’il doit interpréter en tant que commande système les caractères entre ces back quotes.
Salut,
Deja merci de ton aide, je n’obtiens désormais plus la même erreur
[quote]ERROR 1064 (42000) at line 1: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '‘rankhost’.‘benchmark’ (‘cpu_model’, ‘cores’, ‘cpu_freq’, ‘ram’, ‘swap’, ‘uptime’ at line 1
[/quote]
Voici désormais mon code
mysql -u root -pXXXXXX -h 127.0.0.1 -e "INSERT INTO 'host'.'benchmark' ('cpu_model', 'cores', 'cpu_freq', 'ram', 'swap', 'uptime', 'dl_speed', 'IO', 'runtime', 'heberg') VALUES ('$cname', '$cores', '$freq', '$tram', '$swap', '$up', '$cache', '$io', '$runtime', '$heberg');"
Au temps pour moi, il y a un peu trop de backquotes : elles ne sont nécessaires que pour les valeurs à insérer. La ligne devient donc :
mysql -u root -pXXXXXX -h 127.0.0.1 -e "INSERT INTO host.benchmark (cpu_model, cores, cpu_freq, ram, swap, uptime, dl_speed, IO, runtime, heberg) VALUES ('$cname', '$cores', '$freq', '$tram', '$swap', '$up', '$cache', '$io', '$runtime', '$heberg');"