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?

  • 2
    Killing a command that's modifying a logical volume with a (probably mounted) filesystem seems like a good way to corrupt the volume. – Karen B Jun 19 '16 at 22:22

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.

  • is it possible to tell lvresize for answering by default as NO ? – dandan Jun 19 '16 at 22:32
  • 1
    As the man page says (man lvresize), you can pass --force, but again, this is a really good way to corrupt your filesystem if you don't fully understand what you're doing. I suggest learning expect if you really want to resize volumes or filesystems in a script. – Karen B Jun 20 '16 at 0:40

To answer no to any question add -qq option to a command.

When using --force/--yes you should double check what is the script doing. +1 to Karen B's suggestion to use expect.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.