Skip to main content
added 70 characters in body
Source Link
su_li
  • 131
  • 1
  • 5

In Bash this will set a time limit of 10 seconds for the slowcommand

timeout 10 slowcommand

I'm wondering how I could get the same behavior, if I had to call sudo in order to run slowcommand, i.e.:

timeout 10 sudo slowcommand

This will timelimit on sudo, not on the slowcommand... Is there an elegant way to do this while using sudo?

Edit: Let's assume timeout is not permitted to be run with sudo.

In Bash this will set a time limit of 10 seconds for the slowcommand

timeout 10 slowcommand

I'm wondering how I could get the same behavior, if I had to call sudo in order to run slowcommand, i.e.:

timeout 10 sudo slowcommand

This will timelimit on sudo, not on the slowcommand... Is there an elegant way to do this while using sudo?

In Bash this will set a time limit of 10 seconds for the slowcommand

timeout 10 slowcommand

I'm wondering how I could get the same behavior, if I had to call sudo in order to run slowcommand, i.e.:

timeout 10 sudo slowcommand

This will timelimit on sudo, not on the slowcommand... Is there an elegant way to do this while using sudo?

Edit: Let's assume timeout is not permitted to be run with sudo.

Source Link
su_li
  • 131
  • 1
  • 5

How to use the bash timeout function for commands requiring sudo?

In Bash this will set a time limit of 10 seconds for the slowcommand

timeout 10 slowcommand

I'm wondering how I could get the same behavior, if I had to call sudo in order to run slowcommand, i.e.:

timeout 10 sudo slowcommand

This will timelimit on sudo, not on the slowcommand... Is there an elegant way to do this while using sudo?