使用 Ubuntu 16。我创建了这个脚本并将其放置在 /root/s3backyupsync.sh
#!/bin/sh
################################################
# Simple script to synchronise data into S3 bucket(s)
# @Author: Per Lasse Baasch (https://skycube.net)
# @Version: 2016-01-27
#############################################
LOCALDIR='/mnt/backups'
S3BUCKET='s3://server-backups/'
MAILLOG=yes
MAILRECEIPIENT='[email protected]'
MAILSUBJECT='Daily S3 Cloud Backup Sync'
#############################################
### Remember start time
CURRENTDATETIME=$(date +%Y-%m-%-d-%H:%M:%S);
### Sync data
s3cmd sync --no-progress --recursive --skip-existing --no-check-md5 $LOCALDIR $S3BUCKET;
### Mailing
if [ "${MAILLOG}" = "yes" ]; then
TMPFILE=/tmp/s3backupsynclog.txt;
echo "STARTED: ${CURRENTDATETIME}" > $TMPFILE;
echo "ENDED : $(date +%Y-%m-%-d-%H:%M:%S)" >> $TMPFILE;
echo '' >> $TMPFILE;
s3cmd du -H $S3BUCKET >> $TMPFILE;
echo '' >> $TMPFILE;
mutt $MAILRECEIPIENT -s "${MAILSUBJECT}. - ${CURRENTDATETIME}" < $TMPFILE;
rm $TMPFILE;
fi
当我尝试使用 sudo 或 root 运行它时,root/s3backyupsync.sh
我得到命令未找到。我错过了什么吗?
结果ls -l /root/s3backyupsync.sh
-rwxr-xr-x 1 root root 1013 Sep 15 15:05 /root/s3backyupsync.sh
答案1
尝试放在第一位#!/bin/bash
。还可以尝试进入目录并输入./s3backyupsync.sh