Logo Linux Bash SSH Ubuntu Git Menu
 

linux + timeout from command

in my bash script I want to add timeout for the lvresize command so if the command is waiting ,

I will exit after 5 second , as the follwing:

 timeout 5  lvresize -L 1M /dev/mapper/rootvg-home

 Rounding size to boundary between physical extents: 32.00 MiB
 WARNING: Reducing active and open logical volume to 32.00 MiB
 THIS MAY DESTROY YOUR DATA (filesystem etc.)
 Do you really want to reduce home? [y/n]:

but from some unclear reason timeout not works on lvresize?

why? timeout not exit the command after 5 sec?

like image 539
dandan Avatar asked May 03 '26 20:05

dandan


1 Answers

Whyever this fails (my assumption would be lvresize ignoring the TERM signal), this a terrible approach, as lvresize's real task might take that long and you really don't want to kill it while it works.

Instead, ask for confirmation separately (with timeout if need be) and then run lvresize uninterrupted.

like image 57
Sven Avatar answered May 06 '26 09:05

Sven