0

Using Shell Script like below:

if [[timeout 60 | wsof -l]]; then echo "thread sleeping for 60 seconds" exit else echo "timeout failed" exit fi

But getting error timeout failed. How to apply timeout for 60 seconds so that return is echo "thread sleeping" in this case? I'm using bash script for this Case

1 Answers1

0

I'm not sure what |wsof -l is supposed to do, but it may not be working properly because of the brackets (it doesn't work for me when I do it with brackets, but when I do it without it only errors out at the wsof -l command, which I assume you made).

maxbear123
  • 202
  • 1
  • 10
  • If you don't want it to display the time then use `timeout /t 30 > NUL`. If you don't want it to be stopped by user input, use `timeout /t 30 /nobreak`. – maxbear123 Oct 20 '20 at 14:19
  • no i want to use lsof in conjunction with timeout. how to do that?? –  Oct 20 '20 at 14:25
  • Try switching it to `[[timeout /t 60 |wsof -l]]` instead of `[[timeout 60 |wsof -l]]` – maxbear123 Oct 20 '20 at 14:29
  • sure will try and post the output. Thanks, maxbear –  Oct 20 '20 at 14:30
  • Hi Maxbear, should i declare timeout variable elsewhere in the script ?? –  Oct 20 '20 at 14:57
  • Getting error timeout: command not found for statement [[timeout /t 60 |wsof -l]] –  Oct 20 '20 at 15:08
  • Actually, timeout 60 should work fine; I think it was the brackets that was messing it up. (Although, I'm assuming wsof -I is something you made). What does it do? – maxbear123 Oct 21 '20 at 21:50
  • If it worked, just accept the answer (click the checkmark), you need 15 rep to upvote something. – maxbear123 Oct 22 '20 at 14:25
  • hi @maxbear, can i write the above as if timeout 60 lsof | wc -l ; then echo "successful" else echo "not successful" fi –  Nov 17 '20 at 16:00