-3

I have a shell script which contains some functions in it. One of those functions has to be executed through perl. The perl functions checks whether port is opened on a remote server or not.

#!/usr/bin/ksh

function1
function2
telnet_check()
{

#!/usr/bin/perl -w

use IO::Socket;
use IO::Socket::INET;

my ($host,$port);
$host=Ip address ;
$port=9443;
my $sock=IO::Socket::INET->new("Ip address:$port") or die "" ;

}

some shell commands

while executing the above script, am getting the error

 syntax error at line: `(' unexpected [which falls in the line my ($host,$port); under the Perl function]

Could any one help what can be done to fix the above error.

Cheers in Advance :)

1
  • Hey @toolic I already tried like that and it works. But, i want to put it in one script itself. Can this be achieved? Commented Jan 10, 2017 at 15:16

1 Answer 1

3

You can't switch from ksh to Perl that easily. Either, quote the script and pass it as a parameter to perl's -e:

perl -MIO::Socket -MIO::Socket::INET -we 'my ($host, $port) = qw( host.name 9443 ); ...'

or, store the perl script in a file of its own, and run it:

perl /path/to/the/script.pl

or, send the script to the stdin of perl - only works if you don't need to read input from within the script.

cat <<'EOF' | perl
use IO::Socket;
use IO::Socket::INET;
...
EOF
Sign up to request clarification or add additional context in comments.

3 Comments

am getting error while trying in the last way. syntax error at line 10 : `<<' unmatched
@Su_scriptingbee: Are you sure the closing EOF is alone on the line, i.e. no whitespace around it?
There was a space between EOF and closing brace. I corrected it now and it works fine :) Thanks a lot

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.