无法找到sqlplus的进程可以通过crontab执行shell脚本运行时 [英] Unable to find SqlPlus processes running when executing shell script via Crontab

查看:139
本文介绍了无法找到sqlplus的进程可以通过crontab执行shell脚本运行时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有被公司可以通过crontab执行shell脚本。 shell脚本正确创建sqlplus的工作,他们完成运行。什么是不工作是我想要的脚本来等待所有sqlplus的工作,完成年底while循环。

如果我手动执行这个shell脚本,在最后while循环正常工作和shell脚本将不会退出,直到所有sqlplus的工作已经完成。

我如何获得while循环在年底看到sqlplus的工作,而可以通过crontab运行?

 #!/斌/庆典
CD /一些/路径/要/文​​件夹源〜/ .profile文件回声开始运行
回声$(日期)I = 0
而[$ I -lt 12]

    呼应开始的过程'$ I    SQLPLUS username/password@'(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=server)(PORT=1521))(CONNECT_DATA=(SID=SERVERSID)))' @ $ import.sql I> import_batch $ i.log&安培;    让我= $ I + 1
DONE而[$(PS -a | grep的-w -c'的sqlplus')-ne 0] //这不是在crontab中工作
直到[[-z $(指派,-flx'的sqlplus')]] //我也试过这个(而不是在我的脚本的同时),而在crontab中成功

    睡眠60
DONE回声运行完成
回声$(日期)


解决方案

根据上面我的意见,使用等待等待这个过程comlete拥有的所有进程。例如:

 #!/斌/庆典
CD /一些/路径/要/文​​件夹源〜/ .profile文件回声开始运行
回声$(日期)I = 0
而[$ I -lt 12]

    呼应开始的过程'$ I    SQLPLUS username/password@'(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=server)(PORT=1521))(CONNECT_DATA=(SID=SERVERSID)))' @ $ import.sql I> import_batch $ i.log&安培;    让我= $ I + 1
DONE等待回声运行完成
回声$(日期)

I have a shell script that's being executed via Crontab. The shell script is properly creating the Sqlplus jobs and they run to completion. What's not working is the while loop at the end where I want the script to wait for all of the Sqlplus jobs to complete.

If I execute this shell script manually, the while loop at the end works properly and the shell script won't exit until all the Sqlplus jobs have finished.

How do I get the while loop at the end to see the Sqlplus jobs while running via Crontab?

#!/bin/bash
cd /some/path/to/folder

source ~/.profile

echo 'Run started'
echo $(date)

i=0
while [ $i -lt 12 ]
do
    echo 'Starting process ' $i

    sqlplus username/password@'(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=server)(PORT=1521))(CONNECT_DATA=(SID=SERVERSID)))' @import.sql $i > import_batch$i.log &

    let i=$i+1
done

while [ $(ps -a | grep -w -c 'sqlplus') -ne 0 ] //This is not working in Crontab
until [[ -z $(pgrep -flx 'sqlplus') ]] //I've also tried this (instead of the while in my script) without success in Crontab
do
    sleep 60
done

echo 'Run completed'
echo $(date)

解决方案

As per my comment above, use "wait" to wait for all processes owned by this process to comlete. e.g.:

#!/bin/bash
cd /some/path/to/folder

source ~/.profile

echo 'Run started'
echo $(date)

i=0
while [ $i -lt 12 ]
do
    echo 'Starting process ' $i

    sqlplus username/password@'(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=server)(PORT=1521))(CONNECT_DATA=(SID=SERVERSID)))' @import.sql $i > import_batch$i.log &

    let i=$i+1
done

wait

echo 'Run completed'
echo $(date)

这篇关于无法找到sqlplus的进程可以通过crontab执行shell脚本运行时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆