I would like to used the yes command so that GNU parted does not wait for user input :root@195-xxx-xxx-xxx:/proc# parted /dev/sda unit B resizepart 2 1166016512B Warning: Shrinking a partition can cause data loss, are you sure you want  to continue?Yes/No? y                                                                 Information: You may need to update /etc/fstab.root@195-xxx-xxx-xxx:/proc# echo $?0However using yes does not work here : root@195-xxx-xxx-xxx:/proc# yes | parted /dev/sda unit B resizepart 2 166016512B Warning: Shrinking a partition can cause data loss, are you sure you  want to continue?root@195-xxx-xxx-xxx:/proc# echo $?1Edit:The --script option does not work as well : root@195-xxx-xxx-xxx:/proc# parted --script /dev/sda unit B resizepart 2 1166016512B Warning: Shrinking a partition can cause data loss, are you sure you  want to continue?root@195-xxx-xxx-xxx:/proc# echo $?1
GNU parted resizepart in script
shell script;partition;parted
If resizepart does not work, you might have to resort to rm and mkpart to achieve the same thing.Of course, this would require you to parse the partition table first in order to determine partition type and start offset. Unless you already know the necessary values. After all you had to get the 166016512B from somewhere too.parted has the --machine option to produce easily parseable output. On the other hand, examples of actually parsing it are not easily found. ;)