我正在尝试将rsnapshot
命令的输出保存到变量中,然后再使用该输出。但是,该变量似乎为空。
这是脚本。修改用于调试。
#!/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
现在,我在命令行上运行此脚本(文件rsnapshotdaily.sh
)。终端中的输出:
[~] # /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
在终端上显示了输出,但是直接从rsnapshot
命令发出,没有输出显示在变量rsnapshotresult
中。
我在做什么错了?