我有一个mysql过程,我希望从linux中的shell脚本运行该过程,并将输出存储在日志文件中。但是我的脚本不起作用。下面是我的脚本:
#!/bin/bash
source CX20-PIM-properties.prop
status=$(mysql -u $user -h $host -D $database -se "call fetchFromPAsIsToPIDX()")
if [ $status ]; then
echo "Procedure executed successfully" | tee procedure_output.log
else
echo "Procedure execution failed" | tee procedure_output.log
fi输出如下:
[anurag@pimdev0 ~]$ ./load-from-AsIs-to-IDX.sh
Procedure execution failed发布于 2019-02-13 17:15:57
您应该将cmd的返回值存储在cmd的status中,而不是stdout。
#!/bin/bash
source CX20-PIM-properties.prop
if [ `mysql -u $user -h $host -D $database -se "call fetchFromPAsIsToPIDX()" &> /dev/null` ]; then
echo "Procedure executed successfully" | tee procedure_output.log
else
echo "Procedure execution failed" | tee procedure_output.log
fihttps://stackoverflow.com/questions/54665779
复制相似问题