Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7921303
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T16:32:04+00:00 2026-06-03T16:32:04+00:00

I setup a script on my dedicated server to backup all of my Cpanel

  • 0

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.

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 date 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:

Here’s the full code for the backup script:

#!/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
:> ${ERRORLOG}
:> ${ACTIVITYLOG}

##Uploading the daily backup to Amazon s3
/usr/bin/s3cmd -r put ${SOURCE} s3://MK_Web_Server_Backup/${DESTINATION}/ 1>>${ACTIVITYLOG} 2>>${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>>${ACTIVITYLOG} 2>>${ERRORLOG}

And here is the sample code that I am testing to try and simply echo the date code above:

#!/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}

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:

“date –date=4 days ago: command not found”

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 (date --date="4 days ago" +%F), it works like a charm, outputting the data just as I would expect it to.

What am I doing wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T16:32:06+00:00Added an answer on June 3, 2026 at 4:32 pm

    You probably are picking up different versions of the date command when you run the script from a regular terminal, vs. running it from the script, because they use different paths. Either use the full path to the version of the date command you want to use, or explicitly set the path at the beginning of the script.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The script to setup up the SQL Server database for Elmah has a warning
i would like to setup auto deployment script to my testing server locally. i'm
I have a sql server on a dedicated machine, running SQL 2008. I have
I'm trying to setup attribute-sets and attributes automatically via a setup script. The script
My Inno Setup script includes a directory: [Files] ... Source: C:\MyProg\Tools\*.*; Destdir: {app}\Tools ...
I have a setup script which I run in the morning which starts all
I got the following traceback in my setup script: Exception in Tkinter callback Traceback
I have a simple inno-setup script that allows my setup to install either the
I'm using following define to make my setup script flexible according to the build
I have a SSIS 2008 script component which is setup as a transform (so

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.