我想在shell脚本中运行hive查询。如果我的配置单元查询失败,我想退出shell脚本并抛出错误。 现在,即使我的配置单元查询失败,接下来的步骤也会被执行。有人可以帮忙解决这个问题:
VAL = my $pm = Parallel::ForkManager->new($max_procs);
my @collect_processed_data;
$pm->run_on_finish(sub {
my ($pid, $exit_code, $ident, $exit_signal, $core_dump, $processed_data) = @_;
if ($exit_signal) { warn("$pid killed by signal $exit_signal\n"); }
elsif ($exit_code) { warn("$pid exited with error $exit_code\n"); }
push @collect_processed_data, $processed_data
if defined($processed_data);
});
for (...) {
$pm->start and next;
...
my $processed_data = ...;
...
$pm->finish(0, $processed_data);
}
(假设表只有一行)
答案 0 :(得分:1)
hive -e "select col1 from table_name"
if test $? -ne 0
then
exit 1
fi