I'm trying to save the output of a rsnapshot
command to a variable, and then later use that output. The variable seems empty, however.
Here's the script. Modified for debugging.
#!/bin/bash
#Run the command `rsnapshot daily`, and show results
echo "Making backup on USB drive attached to nas."
echo "running command 'rsnapshot -v daily'..."
rsnapshotresult=$( { rsnapshot -v daily; } )
if [ $? -ne 0 ]
then
echo "rsnapshotdaily.sh error"
echo $rsnapshotresult
echo "done"
fi
Now, I run this script (file rsnapshotdaily.sh
) on the command line. The output in the terminal:
[~] # /folder/rsnapshotdaily.sh
Making backup on USB drive attached to nas.
running command 'rsnapshot -v daily'...
Could not open logfile /share/USBDisk1/rsnapshotlog for writing
Do you have write permission for this file?
rsnapshotdaily.sh error
done
There is output shown in the terminal, but appently directly from the the rsnapshot
command, and none appears stored in the variable rsnapshotresult
.
What am I doing wrong?