我正在使用 rsync 脚本将一些东西同步到我的手机上。我正在尝试编写一个 if 语句来决定在命令完成后我在电子邮件中收到哪条消息。出于某种原因,无论命令如何退出,我都会收到两封电子邮件。
success_message=echo "Podcasts are synced." | mail -s "Your podcasts have been synced to your phone." $email_address
fail_message=echo "Your phone did not sync." | mail -s "For some reason, your podcasts did not sync today." $email_address
rsync --log-file=/home/jake/logs/rsync.log -avzu $local_directory $remote_directory
if [ $? -ne "0" ];
then
$fail_message
else
$success_message
fi