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 9168019
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:31:54+00:00 2026-06-17T15:31:54+00:00

I am new to bash and shell but I am running a debian install

  • 0

I am new to bash and shell but I am running a debian install and I am trying to make a script which can find a date in the past without having to install any additional packages. From tutorials I have got to this stage:

#!/bin/sh
#
# BACKUP DB TO S3
#

# VARIABLES
TYPE="DATABASE"
DAYS="30"

# GET CURRENT DATETIME
CURRENTDATE="$(date +%Y%m%d%H%M%S)"

# GENERATE PAST DATE FROM DAYS CONTSTANT
OLDERDATE=`expr $CURRENTDATE - $DAYS'

# CALL PYTHON SCRIPT WITH OLDERDATE ARGUMENT
python script.py $OLDERDATE

Where I am getting stuck is the fact that my “days” is just the number 30 and isnt datetime formattted, so when I come to minus it from the currentdate variable it obviously isnt compatible.

Would anyone be kind enough to help me find a way to get this working as it should?

  • 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-17T15:31:55+00:00Added an answer on June 17, 2026 at 3:31 pm

    Try doing this :

    #!/bin/sh
    #
    # BACKUP DB TO S3
    #
    
    # VARIABLES
    TYPE="DATABASE"
    DAYS="30"
    
    # GET CURRENT DATETIME
    CURRENTDATE="$(date +%Y%m%d%H%M%S)"
    
    # GENERATE PAST DATE FROM DAYS CONSTANT
    OLDERDATE="$(date "+%Y%m%d%H%M%S" -d "$DAYS days ago")"
    
    # CALL PYTHON SCRIPT WITH OLDERDATE ARGUMENT
    python script.py "$OLDERDATE"
    

    See info coreutils 'date invocation' | less +/28.7\ Relative\ items\ in\ date\ strings

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

Sidebar

Related Questions

I'm new to bash scripts (and the *nix shell altogether) but I'm trying to
new to c#. I'm trying to make a simple system where I can search
I am very new to Shell/Bash but I want to use it to establish
I'm trying to use bundle to install gems required for my new project, but
I am trying to install ruby 1.9.2 from a ruby script using rvm which
I'm working on a bash shell script, which goes through a folder and eventually
I'm new to Rails trying to complete this tutorial, but I can;t even get
I have a bash shell script that loops through all child directories (but not
I am new to bash scripting and trying to learn a few things. Here
I'm creating a bash script to create new EC2 instances and then upload a

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.