Skip to content
Advertisement

Any idea how i can use timeout command with condition in linux and shell script

aim working on some shell script , i would like to check the following command

df -h

if timeout more than 60 second then echo “error ” else pass.

so if this command will not responding for 1 minute then I will receive and error message , otherwise it will pass , any creative idea will be high apricated .

Advertisement

Answer

timeout 60 df -h > /dev/null && echo "PASS" || echo "PROBLEM"

Using timeout, if the command df -h doesn’t execute within 60 seconds or errors, it will return a none 0 return code. If a none 0 return code is returned echo “PROBLEM” using the || condition.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement