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
|
||||
fi
|
||||
|
||||
# Define the expect script in a variable
|
||||
expect_script=$(cat <<END_EXPECT
|
||||
echo "Running PREHOOK..."
|
||||
eval $PREHOOK
|
||||
|
||||
echo "Running borg backup.."
|
||||
expect <<END_EXPECT
|
||||
#!/usr/bin/expect -f
|
||||
|
||||
# Set the timeout for waiting
|
||||
set timeout 30
|
||||
set timeout -1
|
||||
|
||||
# Set the passphrase
|
||||
set _passphrase "$PASSPHRASE"
|
||||
|
@ -68,25 +70,21 @@ send "\$_passphrase\r"
|
|||
|
||||
# Wait for the command to finish
|
||||
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
|
||||
)
|
||||
|
||||
echo "Running PREHOOK..."
|
||||
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 "Borg exit status: exit_status=$?"
|
||||
|
||||
echo "Running POSTHOOK..."
|
||||
eval $POSTHOOK
|
||||
|
||||
exit $exit_status
|
Loading…
Reference in New Issue