So as the title suggests I am trying to create an expect script that will run fsck on my corrupted drive. The goal is to repair the drive so I can mount it and recover the data from it.
When running the command manually I get:
Either the superblock or the partition table is likely to be corrupt! Abort y?
If I state "NO" it will begin the check, and I receive:
/dev/footage/TrickCeratops contains a file system with errors, check forced. Pass 1: Checking inodes, blocks and sizes Error reading block 1221066784 (Invalid argument) while getting next inode from scan. Ignore error y?
I can then state "YES" to move forward and it will prompt me again with:
Force rewrite y ?
This is where I'm running into the problem... I can automate up to the first two answers, but am unable to get my expect script to answer "YES" on the "Force rewrite?" If I can get it to answer the 2nd and 3rd questions yes, I would then need to loop it until completion.
So far my script looks as such:
#!/bin/bash
expect -c'
set timeout -1
set temp password
spawn ./e2fsckscript.sh
expect "password for user:"
send "$temp\r"
expect "Abort<y>?"
send "no\r"
expect {
"Ignore error<y>?"{
send "yes\r"
}
"Force rewrite<y>?"{
send "yes\r"
}
exp_continue
}
'
The "spawn ./e2fsckscript.sh" simply runs a command:
sudo e2fsck -b 32768 /dev/footage/TrickCeratops