budihartono
asked on
How do i know the perl 'Can't call method "login" on an undefined value at' error cause
Hi,
I have problem with my perl script.
This perl script i added on my crontab that will run every hour.
But sometimes when i checked the log, the ftp is not running and got message :
Can't call method "login" on an undefined value at
But the thing is, this is intermeatten. Let's say at time 01.00, 02.00 it works then at 03.00, it is not working
then 04.00 it's working again, 05.0 it's not working again.
I was wondering what is the cause of it ?
I understand that this is because the perl is unable to call Net::Ftp module.
But what i don't understand is what is the cause of the ftp can not call the module or login ?
I try to add some ping command, but unfortunately i don't have any root password, so i can not use ping command.
use Net::FTP;
&log ("Trying to get new FTP connection");
$ftp=Net::FTP->new($host,D ebug => 1) or $newerr=1;
push (@ERRORS, "Can't ftp to $host: $!\n") if $newerr;
&log ("Error: $newerr ", @ERRORS) if $newerr;
&log ("Connected");
&log("Login FTP server, host = $host, user = $user, password not shown");
$ftp->login($user,$passwd) or $newerr=1;
I have problem with my perl script.
This perl script i added on my crontab that will run every hour.
But sometimes when i checked the log, the ftp is not running and got message :
Can't call method "login" on an undefined value at
But the thing is, this is intermeatten. Let's say at time 01.00, 02.00 it works then at 03.00, it is not working
then 04.00 it's working again, 05.0 it's not working again.
I was wondering what is the cause of it ?
I understand that this is because the perl is unable to call Net::Ftp module.
But what i don't understand is what is the cause of the ftp can not call the module or login ?
I try to add some ping command, but unfortunately i don't have any root password, so i can not use ping command.
use Net::FTP;
&log ("Trying to get new FTP connection");
$ftp=Net::FTP->new($host,D
push (@ERRORS, "Can't ftp to $host: $!\n") if $newerr;
&log ("Error: $newerr ", @ERRORS) if $newerr;
&log ("Connected");
&log("Login FTP server, host = $host, user = $user, password not shown");
$ftp->login($user,$passwd)
ASKER
HI Don,
Thank you for your help.
But if i checked on the script, it doesnt say anything much about the failed reason.
I guess if the script is failed, it will only log no server connection.
The things that i want to know is why it's failed ?Is it network connection or failed port? or something else? So actually we wan to retrieve information what is this 'undef' ?
Since sometimes it works, sometimes it doesnt work.
Thank you.
Thank you for your help.
But if i checked on the script, it doesnt say anything much about the failed reason.
I guess if the script is failed, it will only log no server connection.
The things that i want to know is why it's failed ?Is it network connection or failed port? or something else? So actually we wan to retrieve information what is this 'undef' ?
Since sometimes it works, sometimes it doesnt work.
Thank you.
"If the constructor fails undef will be returned and an error message will be in $@"
&log("no server connection - cannot login to FTP server, host = $host, reason: $@");
&log("no server connection - cannot login to FTP server, host = $host, reason: $@");
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi all,
Thanks..
now i can see it why ,
2011-02-17 12:03:00 [20770] Trying to get new FTP connection
2011-02-17 12:05:00 [20770] Cannot connect to 10.159.5.2 : Net::FTP: Timeout
2011-02-17 12:05:00 [20770] no server connection - cannot login to FTP server, host = 10.159.5.2, reason: Net::FTP: Timeout
But i am teriblle sory, my next question is, whether this is a network problem ? How do we check it? Can we add some ping command ?
But if i check while the script is trying to get FTP connection, manually i check using ping, i got result that the ip is alive.
I am so confused.
Thank you.
Thanks..
now i can see it why ,
2011-02-17 12:03:00 [20770] Trying to get new FTP connection
2011-02-17 12:05:00 [20770] Cannot connect to 10.159.5.2 : Net::FTP: Timeout
2011-02-17 12:05:00 [20770] no server connection - cannot login to FTP server, host = 10.159.5.2, reason: Net::FTP: Timeout
But i am teriblle sory, my next question is, whether this is a network problem ? How do we check it? Can we add some ping command ?
But if i check while the script is trying to get FTP connection, manually i check using ping, i got result that the ip is alive.
I am so confused.
Thank you.
ASKER
secondly..right after the crontab is running the perl script, and the result is Time Out, then i mannually running the script, it works ...!!
I was wondering why from crontab is failed.
I was wondering why from crontab is failed.
try increasing the Timeout parameter
$ftp=Net::FTP->new($host,D ebug => 1, Timout => 300) or $newerr=1;
$ftp=Net::FTP->new($host,D
oops - Timeout it is :-)
$ftp=Net::FTP->new($host,D ebug => 1, Timeout => 300) or $newerr=1;
$ftp=Net::FTP->new($host,D
ASKER
Hi,
I try to add longer timeout as suggested, the result, stil the same, sometimes its working, sometimes it is not working.
THe log is
2011-02-17 15:07:44 [3091] Trying to get new FTP connection
2011-02-17 15:11:29 [3091] Cannot connect to SGJKT4 : Net::FTP: Timeout
2011-02-17 15:11:29 [3091] no server connection - cannot login to FTP server, host = SGJKT4, reason: Net::FTP: Timeout
2011-02-17 16:03:00 [16029] Trying to get new FTP connection
2011-02-17 16:06:45 [16029] Cannot connect to 10.159.5.2 : Net::FTP: Timeout
2011-02-17 16:06:45 [16029] no server connection - cannot login to FTP server, host = 10.159.5.2, reason: Net::FTP: Timeout
As your information, i have 4 line of the FTP script that executed by crontab.
But still i don't understand, sometimes it works, sometimes it's not.
even when it's trying to get ftp connection , mannualy i try to ping, i can reach the server.
Also when i run it manually, its always working.
Weird..
I try to add longer timeout as suggested, the result, stil the same, sometimes its working, sometimes it is not working.
THe log is
2011-02-17 15:07:44 [3091] Trying to get new FTP connection
2011-02-17 15:11:29 [3091] Cannot connect to SGJKT4 : Net::FTP: Timeout
2011-02-17 15:11:29 [3091] no server connection - cannot login to FTP server, host = SGJKT4, reason: Net::FTP: Timeout
2011-02-17 16:03:00 [16029] Trying to get new FTP connection
2011-02-17 16:06:45 [16029] Cannot connect to 10.159.5.2 : Net::FTP: Timeout
2011-02-17 16:06:45 [16029] no server connection - cannot login to FTP server, host = 10.159.5.2, reason: Net::FTP: Timeout
As your information, i have 4 line of the FTP script that executed by crontab.
But still i don't understand, sometimes it works, sometimes it's not.
even when it's trying to get ftp connection , mannualy i try to ping, i can reach the server.
Also when i run it manually, its always working.
Weird..
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
"undef" does not have a "login" method, because it is not a valid Net::FTP object.
use something like
if ( defined $ftp ) {
$ftp->login($user,$passwd)
} else {
&log("no server connection - cannot login to FTP server, host = $host");
}