[sf-lug] yes(1): Re: problem using gnu parted
Michael Paoli
Michael.Paoli at cal.berkeley.edu
Tue Jan 30 23:48:46 PST 2018
Well, typically with something like:
$ yes | some_program
But alas, GNU parted - or at least the version I've got at my fingertips,
is rather annoyingly adverse to automation and non-interactive use.
Seems it insists upon reading from a tty device, and stubbornly fails
to make a change it otherwise warns about without being able to get a
Yes from attached tty device. Your version/mileage may very.
Even if I do it under batch(1) so there's no attahced tty device,
parted still fails. From strace(1), I find:
...
6111 write(2, "Shrinking a partition can cause data loss, are you
sure you want to", 67) = 67
6111 write(2, "\n", 1) = 1
6111 write(2, "continue?", 9) = 9
6111 write(2, "\n", 1) = 1
6111 ioctl(0, TCGETS, 0x7ffe7922d2c0) = -1 ENOTTY (Inappropriate
ioctl for device)
...
essentially, after prompting (and regardless of whether or not -s or --script
option is given), it seems to try tty type ioctl call on file descriptor
0 (stdin), and if that fails it just fairly quickly cleans up and exits.
Annoying, but could possibly use expect or similar to work around that.
Personally I tend to use and quite like sfdisk ... but one needs to be
highly careful with sfdisk - very easy to screw things up if one doesn't
know what one is doing, e.g. "Oh, sure, sfdisk, let me try that ..."
# sfdisk /dev/sda
Your input is now specifying the precise layout of your new partition
table. You know the precise input format to use, right?
Good luck with that if that isn't what you were expecting to be doing.
Anyway, in more typical case using stdin, yes(1) is quite useful, e.g.:
$ ./yn; echo $?
What'll it be? [y/n]: y
Okay, fine.
$ </dev/null ./yn; echo $?
What'll it be? [y/n]: Nope.
1
$ yes | ./yn; echo $?
What'll it be? [y/n]: Okay, fine.
$
> From: "Alex Kleider" <akleider at sonic.net>
> Subject: Re: yes(1): Re: [sf-lug] problem using gnu parted
> Date: Tue, 30 Jan 2018 22:01:59 -0800
> On 2018-01-30 21:31, Michael Paoli wrote:
>> See also: yes(1)
>>
>>> From: "Alex Kleider" <akleider at sonic.net>
>>> Subject: [sf-lug] problem using gnu parted
>>> Date: Tue, 30 Jan 2018 19:59:46 -0800
>>
>>> parted $LOOPDEV unit 's' resizepart "$PART_NUMBER" "${ENDING_SECTOR}" <<
>>> HERE
>>> yes
>>> HERE
>
> I looked at man yes.
> How would one use it? And specifically, how could it be used to
> solve my problem?
More information about the sf-lug
mailing list