Note that there are some explanatory texts on larger screens.

plurals
  1. POKeep getting error: "date --date=4 days ago: command not found"
    primarykey
    data
    text
    <p>I setup a script on my dedicated server to backup all of my Cpanel backup files to Amazon S3, and I've got it running every night via cron.</p> <p>It ran perfectly last night and backed everything up, but then proceeded to delete all it had backed up. It appears to have something to do with the <code>date</code> command because if I pull the "deletion" portion of the script out and put it into another file and run it as an echo, I can't get the date to echo properly. I keep getting a "command not found" error:</p> <p>Here's the full code for the backup script:</p> <pre><code>#!/bin/bash ##Notification email address _EMAIL=klawncare1212@gmail.com ERRORLOG=/var/log/s3_backup_logs/backup.err`date +%F` ACTIVITYLOG=/var/log/s3_backup_logs/activity.log`date +%F` ##Directory which needs to be backed up SOURCE=/backup/cpbackup/daily ##Name of the backup in bucket DESTINATION=`date +%F` ##Backup degree DEGREE=4 #Clear the logs if the script is executed second time :&gt; ${ERRORLOG} :&gt; ${ACTIVITYLOG} ##Uploading the daily backup to Amazon s3 /usr/bin/s3cmd -r put ${SOURCE} s3://MK_Web_Server_Backup/${DESTINATION}/ 1&gt;&gt;${ACTIVITYLOG} 2&gt;&gt;${ERRORLOG} ret2=$? ##Sent email alert msg="BACKUP NOTIFICATION ALERT FROM `hostname`" if [ $ret2 -eq 0 ];then msg1="Amazon s3 DAILY Backup Uploaded Successfully" else msg1="Amazon s3 DAILY Backup Failed!!\n Check ${ERRORLOG} for more details" fi echo -e "$msg1"|mail -s "$msg" ${_EMAIL} ####################### ##Deleting backup's older than DEGREE days ## Delete from both server and amazon ####################### DELETENAME=$(date --date="${DEGREE} days ago" +%F) /usr/bin/s3cmd -r --force del s3://MK_Web_Server_Backup/${DELETENAME} 1&gt;&gt;${ACTIVITYLOG} 2&gt;&gt;${ERRORLOG} </code></pre> <p>And here is the sample code that I am testing to try and simply echo the date code above:</p> <pre><code>#!/bin/bash ##Backup degree DEGREE=4 ####################### ##Deleting backup's older than DEGREE days ## Delete from both server and amazon ####################### DELETENAME=$(date --date="4 days ago" +%F) echo ${DELETENAME} </code></pre> <p>What am I doing wrong? Every time I run this small test script on my CentOS linux server through SSH I get the following error:</p> <p>"date --date=4 days ago: command not found"</p> <p>So, it's not having any trouble inserting the "degree" variable value. And, if I simply take and run the same command at the prompt in SSH (<code>date --date="4 days ago" +%F</code>), it works like a charm, outputting the data just as I would expect it to.</p> <p>What am I doing wrong?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload