[Parted-maintainers] Bug#753573: parted: please allow to read script commands from stdin or a file

Colin Watson cjwatson at debian.org
Sat Jul 19 23:58:12 UTC 2014


On Thu, Jul 03, 2014 at 10:31:02AM +0200, Enrico Zini wrote:
> I currently have this in a deploy script:
> 
>   DISK=`find_disk`
>   while read -r cmd; do parted -s -a optimal $DISK $cmd; done < commands.txt
> 
> that while loop works around parted only accepting script commands on
> the command line. I wish I could do this:
> 
>   DISK=`find_disk`
>   parted -s -a optimal $DISK read commands.txt
> 
> or this:
> 
>   DISK=`find_disk`
>   compute_parted_commands | parted -s -a optimal $DISK read -
> 
> I understand that running each command in its own invocation makes it
> possible to know which command exactly failed. In my case, though, I
> work on an all-or-nothing situation: either the disk ends up partitioned
> how we need it, or the installation procedure alarms[1] and halts.

Does it help to know (as I don't think it's well-documented) that all
parted commands apart from "help" can unambiguously determine when their
arguments end?  "parted -s" actually just works by popping a
command name from the command line, having that command pop arguments
until it's finished, popping another command name if possible, and
repeating until it runs out of words.  So, for example, you can do this:

  parted -s $DISK print unit s print

... and that's parsed as:

  print
  unit s
  print

This is a bit weird and so doesn't necessarily obviate your request, of
course, but it should let you just do this or some nearby variation:

  DISK=`find_disk`
  compute_parted_commands | xargs parted -s -a optimal $DISK

Cheers,

-- 
Colin Watson                                       [cjwatson at debian.org]



More information about the Parted-maintainers mailing list