-2

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?

dandan
  • 1,081
  • 4
  • 13
  • 21
  • 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

2 Answers2

2

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.

Sven
  • 98,649
  • 14
  • 180
  • 226
  • 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 00:40
0

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.

Martian
  • 1,100
  • 8
  • 8