简体   繁体   中英

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 . This is troublesome since loadImport.sh is the script loaded by a php file and thus no output is seen.

The first script loadImport.sh loads the import script doImport.sh with a timeout.

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 ?

source solved my problem.

I was using it wrong first since in combination with sudo it has to be used like this sudo -s

Changing my script like this: timeout --kill-after=90s 60s sudo -s ./doImport.sh $DBNAME was the answer

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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