LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   [bash script] automating ntfsresize? (https://www.linuxquestions.org/questions/programming-9/%5Bbash-script%5D-automating-ntfsresize-744232/)

Naviathan 07-31-2009 03:14 PM

[bash script] automating ntfsresize?
 
Synopsis: Windows Imaging System script. Windows XP on NTFS containing two partitions on one drive. I have the script I need running beautifully. Manually I've taken care of the resizing, imaging and compressing. The problem comes in when I go to expand the volumes again on the follow up system.

The intent is to create a no user input needed image disk. I've imaged my syspreped/ntfsresized system using dd piped through bzip2. The script I've written partitions the drive in 1/2 unpacks the images and writes them back to the new system using cplbar for progress. Anyhow, all that works perfectly, it images the first half of the first partition, ejects the dvd, requests the second one using a "dialog --msgbox" then I have loop script that runs after the OK button is pressed attempting to mount the cd until df greps a /mnt/cdrom entry then it moves on, does the second half of the first part, the second part then the MBR. After this ntfsresize is run again to expand the volumes into the partitions. This is where I'm having trouble. ntfsresize does not have a quiet/no interaction/all answer y switch and it of course prompts the user to proceed with the expansion on both partitions. I need to circumvent this prompt somehow. My end users that the disks are intended for would probably have a heart attack if the read that message ntfsresize prints to the screen and enter n instead of y. Trust me, these guys are not computer literate and everything on their machines is critical. Any ideas? I'm experimenting with expect scripting for the final steps, but I've read another post where someone had issues with expect and ntfsresize. Any ideas are greatly appreciated.

gnashley 08-01-2009 11:02 AM

You might try piping 'y' to it like this:
echo y | ntfsresize-command
And you might end that line with '&> /dev/null' to suppress any output.

Naviathan 08-01-2009 01:31 PM

I think piping y would just append a y to the end of the parameters. Also the user would still have to hit enter at some point to get it to move on.

gnashley 08-02-2009 02:45 AM

Try it before rejecting the idea -that is the method used to configure QT in order to automate the acceptance of the license.

fericyde 08-03-2009 11:52 PM

Don't forget about expect.

Run the "autoexpect" command on a trial run with the command you're trying to execute and immediately exit.

It will take care of creepy standard-in type issues that the "echo y | [command]" trick may not be able to handle.

I've found that for small tasks like this one I can usually get the expect script down to 5-10 lines or so (lots of removal of comments helps).

--Paul

Naviathan 08-04-2009 06:28 AM

Expect worked perfectly. Thanks for the help. BTW piping "y" to ntfsresize caused it append a y to the end of the input and just error out.

fericyde 08-05-2009 12:21 AM

Awesome!
 
Quote:

Originally Posted by Naviathan (Post 3630689)
Expect worked perfectly. Thanks for the help. BTW piping "y" to ntfsresize caused it append a y to the end of the input and just error out.

You're welcome -- glad to hear this did the trick.
--Paul

archtoad6 08-10-2009 05:44 AM

Can't test this, so it may be a bad idea; but would '<<< y' work?
Code:

ntfsresize-command <<< y
Or would it have the same effect as the discarded echo y ntfsresize-command suggestion?

I'm sleepy/hazy enough this am I can't even think of a good test I could do here.

fericyde 08-11-2009 05:59 AM

Probably not
 
< [some file] -- maybe -- but my experience with a lot of redirected input is that if:

# echo [data] | [process]

If the above fails you're in for something timing sensitive, like expect.

Using a here document is most likely going to grant the same results as the above.

Just my $0.02

Driadan 12-05-2012 09:57 AM

It should be
Code:

echo -e "y\n" | ntfsresize -P <device>


All times are GMT -5. The time now is 10:26 PM.