Remove timeout, remove temp script, and catch exit status
This commit is contained in:
parent
392cdf5edf
commit
882c7cfacf
|
@ -49,12 +49,14 @@ if test -f /etc/borgbackup.conf; then
|
||||||
source /etc/borgbackup.conf
|
source /etc/borgbackup.conf
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Define the expect script in a variable
|
echo "Running PREHOOK..."
|
||||||
expect_script=$(cat <<END_EXPECT
|
eval $PREHOOK
|
||||||
|
|
||||||
|
echo "Running borg backup.."
|
||||||
|
expect <<END_EXPECT
|
||||||
#!/usr/bin/expect -f
|
#!/usr/bin/expect -f
|
||||||
|
|
||||||
# Set the timeout for waiting
|
set timeout -1
|
||||||
set timeout 30
|
|
||||||
|
|
||||||
# Set the passphrase
|
# Set the passphrase
|
||||||
set _passphrase "$PASSPHRASE"
|
set _passphrase "$PASSPHRASE"
|
||||||
|
@ -68,25 +70,21 @@ send "\$_passphrase\r"
|
||||||
|
|
||||||
# Wait for the command to finish
|
# Wait for the command to finish
|
||||||
expect eof
|
expect eof
|
||||||
|
|
||||||
|
foreach {pid spawnid os_error_flag value} [wait] break
|
||||||
|
|
||||||
|
if {\$os_error_flag == 0} {
|
||||||
|
puts "exit status: \$value"
|
||||||
|
exit \$value
|
||||||
|
} else {
|
||||||
|
puts "errno: \$value"
|
||||||
|
exit \$value
|
||||||
|
}
|
||||||
END_EXPECT
|
END_EXPECT
|
||||||
)
|
|
||||||
|
|
||||||
echo "Running PREHOOK..."
|
echo "Borg exit status: exit_status=$?"
|
||||||
eval $PREHOOK
|
|
||||||
|
|
||||||
echo "Running borg backup.."
|
|
||||||
# Save the expect script to a temporary file
|
|
||||||
expect_script_file=$(mktemp)
|
|
||||||
echo "$expect_script" > "$expect_script_file"
|
|
||||||
|
|
||||||
# Make the temporary expect script executable
|
|
||||||
chmod +x "$expect_script_file"
|
|
||||||
|
|
||||||
# Execute the expect script
|
|
||||||
$expect_script_file
|
|
||||||
|
|
||||||
# Clean up the temporary expect script
|
|
||||||
rm -f "$expect_script_file"
|
|
||||||
|
|
||||||
echo "Running POSTHOOK..."
|
echo "Running POSTHOOK..."
|
||||||
eval $POSTHOOK
|
eval $POSTHOOK
|
||||||
|
|
||||||
|
exit $exit_status
|
Loading…
Reference in New Issue