我正在连接到远程主机并执行一个不退出的命令(tail -f logfile)
我正在注册一个处理程序并将输出写入日志文件.这工作正常但我想按主程序上的Control + C,它应该停止远程机器上的命令并优雅地关闭ssh连接
所以我正在为SIGINT注册一个信号处理程序
需要我需要放在子程序中的代码
下面的代码位于一个从forked child调用的函数中
#!/ats/bin/perl
use Net::SSH::Perl;
use File::Path;
use Text::CSV_XS;
chomp ($progName = `basename $0`);
if (@ARGV != 1 ) {
print "usage: perl $progName <tc_id>\n";
exit;
}
$tc_id = shift;
$file = "config.prop";
$log_dir = "logs/";
#$SIG{INT}=\&close_write;
sub close_write
{
#-- write it to file
print "\nInside END block\n";
#open FH, ">$log_file";
#print $log_file;
#print FH @out;
#$thr->kill('INT');
#close $ssh->sock;
#undef $ssh;
exit 1;
}
# Read the configuration file and populate …Run Code Online (Sandbox Code Playgroud)