简体   繁体   English

超时命令-Shell脚本的回显输出

[英]Timeout command - echo output from shell script

I wanted to put a timeout on my import script. 我想在导入脚本上设置超时。

When using timeout the import script does not output via the loadImport.sh . 使用timeout ,导入脚本不会通过loadImport.sh输出。 This is troublesome since loadImport.sh is the script loaded by a php file and thus no output is seen. 这很麻烦,因为loadImport.sh是由php文件加载的脚本,因此看不到任何输出。

The first script loadImport.sh loads the import script doImport.sh with a timeout. 第一个脚本loadImport.sh加载带有超时的导入脚本doImport.sh

loadImport.sh

#!/bin/bash

IMPORTLOG='/usr/local/bin/import.log'
DBNAME=$1

timeout --kill-after=90s 60s sudo ./doImport.sh $DBNAME
if (($? == 124)); then
  echo "Import timed out" | tee -a $IMPORTLOG
  exit 124
fi

How do I get the output from doImport.sh with the line timeout --kill-after=90s 60s sudo ./doImport.sh $DBNAME ? 我如何从doImport.sh的输出中获取timeout --kill-after=90s 60s sudo ./doImport.sh $DBNAME

source solved my problem. source解决了我的问题。

I was using it wrong first since in combination with sudo it has to be used like this sudo -s 我首先使用它是错误的,因为它必须与sudo结合使用,例如sudo -s

Changing my script like this: timeout --kill-after=90s 60s sudo -s ./doImport.sh $DBNAME was the answer 像这样更改我的脚本: timeout --kill-after=90s 60s sudo -s ./doImport.sh $DBNAME是答案

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM