OVH Cloud OVH Cloud

shell et perl

4 réponses
Avatar
Arnaud Launay
Bonjour,

J'essayais d'intégrer un bout de perl dans un script shell, mais
visiblement, il ne m'aime pas...

-----------------------------------------
#! /bin/sh

check_open_port() {
perl -e -Mstrict -MSocket 'if ($#ARGV != 1) { print STDERR "port.pl ip port"; exit(1); } \
my ($host,$port) = @ARGV; my $proto = getprotobyname("tcp"); socket(SH, PF_INET, SOCK_STREAM, $proto); \
my $sin = sockaddr_in($port,inet_aton($host)); if (connect(SH,$sin)) { exit(0); } else { print("$host:$port NOK"); exit(1); }' $1 $2
}

check_open_port localhost 27 || echo "NOPE"
-----------------------------------------


asl@citron ~ $ sh bouh
asl@citron ~ $

Quelque chose m'échappe...

Arnaud.
--
Perso: http://launay.org/blog/
Hébergement: http://www.nocworld.com/

4 réponses

Avatar
Benoit Izac
Bonjour,

le 22/07/2006 à 11:12, Arnaud Launay a écrit dans le message
:

J'essayais d'intégrer un bout de perl dans un script shell, mais
visiblement, il ne m'aime pas...

-----------------------------------------
#! /bin/sh

check_open_port() {
perl -e -Mstrict -MSocket '[...]'


perl -Mstrict -MSocket -e '...'

--
Benoit Izac

Avatar
Arnaud Launay
Le Sat, 22 Jul 2006 09:50:22 +0000 (UTC), Loic Tortay écrivit:
Il faut mettre le '-e' de l'appel à "perl" après les '-Mstrict' et
'-MSocket', sinon, "perl" les considère comme faisant partie du script
(et ils n'en font pas partie, sinon ils devraient être sous la forme
"use strict; use Socket;").


Pas beaucoup mieux:

~ $ sh bouh
Can't modify reference constructor in scalar assignment at -e line 2, near "@ARGV;"
Execution of -e aborted due to compilation errors.

Problème de passage des argument ?

Arnaud.
--
Perso: http://launay.org/blog/
Hébergement: http://www.nocworld.com/

Avatar
Benoit Izac
Bonjour,

le 22/07/2006 à 15:29, Arnaud Launay a écrit dans le message
:

~ $ sh bouh
Can't modify reference constructor in scalar assignment at -e line 2,
near "@ARGV;"
Execution of -e aborted due to compilation errors.

Problème de passage des argument ?


Non, comme il t'a été dit, supprime les « ».

--
Benoit Izac

Avatar
Arnaud Launay
Le Sat, 22 Jul 2006 16:39:33 +0200, Benoit Izac écrivit:
Problème de passage des argument ?
Non, comme il t'a été dit, supprime les « ».



Ah voui. Hmm. Ah bah voui, chuis con.

Merci :-)

Arnaud.
--
Perso: http://launay.org/blog/
Hébergement: http://www.nocworld.com/