0

using Ubuntu 16. I have created this script and placed it in /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='youremail@gmail.com'
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

When I try to run it either with sudo or root like root/s3backyupsync.sh I get command not found. Am I missing something?

Results of ls -l /root/s3backyupsync.sh

-rwxr-xr-x 1 root root 1013 Sep 15 15:05 /root/s3backyupsync.sh
  • Please show us the exact commands you tried to run and also tell us whether the script is executable (show us the output of ls -l /root/s3backyupsync.sh) – terdon Sep 15 '16 at 14:20
  • -rwxr-xr-x 1 root root 1013 Sep 15 15:05 /root/s3backyupsync.sh – Joanna Mikalai Sep 15 '16 at 14:21
  • I tried writing just sudo /root/s3backyupsync.sh as a user and also as root /root/s3backyupsync.sh – Joanna Mikalai Sep 15 '16 at 14:21
  • Thanks but please add that to your question. Comments are easy to miss and can be deleted without warning. Make sure to also show us the exact commands as requested. What happens if you just run sudo /root/s3backyupsync.sh? What exact error message? Please edit your question and include all this. – terdon Sep 15 '16 at 14:22
  • 1
    OK, just to rule some things out. Please edit your question and show us what happens (including the exact wording of the error) if you run sudo sh /root/s3backyupsync.sh – terdon Sep 15 '16 at 14:28
2

Try putting #!/bin/bash first. Also try going into the directory and type ./s3backyupsync.sh

  • No Problem , just saw you figured it out yourself :) – Meerkat Sep 15 '16 at 14:31
  • #!/bin/bash/ has no function. Its a comment... – CJ Dana Sep 15 '16 at 14:39
  • 2
    It has a function ! It tells the shell what program to interpret the script with. #!/bin/bash — Execute the file using bash, the Bourne shell, or a compatible shell – Meerkat Sep 15 '16 at 14:40
  • 2
    You probably don't want the trailing / on your shebang – Eric Renouf Sep 15 '16 at 14:42
  • Sry you are right.Fixed it. – Meerkat Sep 15 '16 at 14:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.