如果某个 shell 失败如何退出?

如果某个 shell 失败如何退出?

我正在尝试使用 Perl 脚本连接到 Oracle DB 以在 Solaris 操作系统上执行一些查询,并且我已将其中的每个查询保存为:

create table t1 ..
update t1 ..
insert into t1 ..

要点是它们必须按顺序运行,如果其中一个失败,脚本应该退出。如何编写一个在其中一部分失败时退出的 shell 脚本?

我已经尝试过很多次set -e,但它在 Solaris 上运行得不好。最后,我发现了类似的东西,但我遇到了同样的问题,每次都失败:

if ! nohup /data/scripts/drop_table.pl   >> /info/saved/LOG/`date +\%Y\%m\%d`_result.log   2>&1;
then echo "dropping error!!" >&2;
exit 1;
fi

if ! nohup /data/scripts/update_table.pl   >> /info/saved/LOG/`date +\%Y\%m\%d`_result.log   2>&1;
then echo "updating error!!" >&2;
exit 1;
fi

if ! nohup /data/scripts/insert_table.pl   >> /info/saved/LOG/`date +\%Y\%m\%d`_result.log   2>&1;
then echo "insertion error!!" >&2;
exit 1;
fi

相关内容