【问题标题】:Shell script to run PLP/SQL procedure requiring terminal input and then move the shell process to background运行需要终端输入的 PLP/SQL 过程的 shell 脚本,然后将 shell 进程移至后台
【发布时间】:2020-08-26 01:11:23
【问题描述】:

我正在一个 shell 脚本中运行一个 PL/SQL,该脚本接受来自 shell 终端的过程的 IN 参数。整个过程大约需要4个小时。我知道我们可以输入 ctrl+z 来暂停进程,然后使用 bg 命令将进程发送到后台重新启动。有没有办法可以通过终端输入输入并将进程发送到后台而不暂停它?

【问题讨论】:

    标签: bash shell plsql procedure


    【解决方案1】:

    如果我正确理解您的要求,那么读取参数的包装脚本似乎就足够了。它可以使用 & 符号将您的 PL/SQL 脚本作为后台进程启动:

    me:~/$ cat ./wrapper.sh 
    #!/bin/bash
    read -p "Enter the first parameter: " p1
    read -p "Enter the second parameter: " p2
    read -p "Enter the third parameter: " p3
    read -p "Enter the fourth parameter: " p4
    
    ./plsql.sh $p1 $p2 $p3 $p4 &
    pid=$!
    jobs -l
    ps aux | grep -v grep | grep $pid
    

    实际效果如下:

    me:~/$ ./wrapper.sh 
    Enter the first parameter: a  
    Enter the second parameter: b
    Enter the third parameter: c
    Enter the fourth parameter: dd
    [1]+ 151367 Running                 ./plsql.sh $p1 $p2 $p3 $p4 &
    me      151367  0.0  0.1   6940  3404 pts/2    S+   06:49   0:00 /bin/bash ./plsql.sh a b c dd
    

    【讨论】:

    • 我的外壳是 korn。这种方法不适用于 korn。 plpsql.sh运行时不保存参数
    • 您已将 bash 放入问题标签中,而不是 korn。
    【解决方案2】:

    如果你想让 shell 自己进入后台,试试exec:

    if [[ -n "$stuff" ]]
    then sleep "$stuff"
    else read -p "gimme some input: " stuff
         export stuff
         exec $0 &
    fi
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-09-11
      • 2013-10-14
      • 1970-01-01
      • 1970-01-01
      • 2021-03-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多