Q:

unexpected EOF while looking for matching `"' while trying to set time using ssh

I have a perl script that runs commands on some PCs remotely via SSH.  So I want to set the time on all pcs to be the same.  The PCs are a linux based system and the perl script uses another .txt file that has the commands to execute.  But when I run the perl script, I got the following error :
Command = date --set "27 SEP 2012 19

sh: -c: line 0: unexpected EOF while looking for matching `"'
sh: -c: line 1: syntax error: unexpected end of file

The perl script is working fine because I tried another command and it gives the results. 
So what could cause this error.  
The perl code is :
#! /usr/bin/perl

open (MYFILE,'HostIPWithCmd.txt');
$i=0;
 @IPs=<MYFILE>;
 foreach (@IPs) {
chomp;
($EthIP,$Cmd)= split(":");
 if($EthIP!=~ ("#"))
 {
    push(@hostIP,$EthIP);
    push(@destCmd,$Cmd);

 }

 else
 {
   push(@hostIP,"$EthIP");
   push(@destCmd,$Cmd);
 }
}

$i=0;

foreach my $host (@hostIP)
{
   if($host ! =~ ("#"))
   {

      my @cmds= split(/,/,$destCmd[$i]);
      print "\n\nCommands For $host = $destCmd[$i]\n";

   foreach my $command (@cmds)
             {
 print "\n*************************************";
 print "\nCommand = $command \n\n";
 system("ssh -o ConnectTimeout=10 $host $command");

         }

  print "\n***** End Of Host : $host  *****\n";
  print "************************************************************\n\n";
      }

 $i++;
}

and the HostIPWithCmd.txt
   10.20.146.97:date --set "27 SEP 2012 19:00:00"

Thanks in advance.  

A:

It's quite simple.  It's because you have colons otherwhere in your string, which causes the end of your string to disappear.  The statement:
($EthIP,$Cmd)= split(":");

with the input:
10.20.146.97:date --set "27 SEP 2012 19:00:00"

Will yield:
$EthIP = '10.20.146.97';
$Cmd   = 'date --set "27 SEP 2012 19';

And the rest of the split list (which is discarded) would be:
@rest = ("00", "00");

Because you split on colon :.  A simple fix would be to have a limit:
($EthIP,$Cmd)= split(/:/, $_, 2);  # max 2 fields

---
However, it is doubtful that your code will work even with this fix.  There are quite a few serious errors in your code.  From top to bottom:

You do not use use strict; use warnings; This is a major mistake, since it will allow you to have silent warnings and typos in your code (See below for examples).  Never write perl code without these two pragmas. 
You use an open statement without checking the return value, e.g. open MYFILE, 'HostwithIP.txt' or die $!.  Not checking the return value will allow the open to fail silently, causing all sorts of troubles.  Not using warnings will not warn you that you are reading from a closed file handle, and you will be sitting there scratching your head all day long before you figure it out. 
You use the two argument open with a global file handle.  You should use an explicit open mode and a lexical file handle.  E.g. open my $fh, "<", 'HostIPWithCmd.txt" or die $!. 
You are using foreach (@IP) instead of simply iterating over the file handle, e.g. while (<MYFILE>)
split uses a regex, not a string.  It will convert a string to a regex, but its better to do it right from the start.  split /#/.
There is no ! =~ operator.  It will be interpreted as $foo ! = ~ $bar, or in other words, a numerical inequality check between $foo and the bitwise negation of $bar.  The operator you want is ! ~. This particular thing will break your code into so many little pieces, especially when you don't use warnings, and the error is silent.  So no, as you said in your comment, your script is not working perfectly, it is horribly broken.  You just don't see it because you don't use warnings. 
Your if-else statement is completely redundant, because the same thing happens in both if and else clause.  There is no difference between $EthIP and "$EthIP".  Both are exactly identical.  This is perhaps the reason you think your code is working. 

Also, when using system, backticks or qx() it is always a good idea to consider other ways to solve the problem.  There are modules that can handle this much better for you than system.