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

  • Home
  • SEARCH
  • 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 6017453
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T03:07:51+00:00 2026-05-23T03:07:51+00:00

I have a shell script. A cron job runs it once a day. At

  • 0

I have a shell script. A cron job runs it once a day. At the moment it just downloads a file from the web using wget, appends a timestamp to the filename, then compresses it. Basic stuff.

This file doesn’t change very frequently though, so I want to discard the downloaded file if it already exists.

Easiest way to do this?

Thanks!

  • 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-05-23T03:07:51+00:00Added an answer on May 23, 2026 at 3:07 am

    Do you really need to compress the file ?
    wget provides -N, --timestamping which obviously, turns on time-stamping. What that does is say your file is located at http://www.example.com/file.txt

    The first time you do:

    $ wget -N www.example.com/file.txt
    [...]
    [...] file.txt saved [..size..]
    

    The next time it’ll be like this:

    $ wget -N www.example.com/file.txt
    Server file no newer than local file “file.txt” -- not retrieving.
    

    Except if the file on the server was updated.

    That would solve your problem, if you didn’t compress the file.
    If you really need to compress it, then I guess I’d go with comparing the hash of the new file/archive and the old. What matters in that case is, how big is the downloaded file ? is it worth compressing it first then checking the hashes ? is it worth decompressing the old archive and comparing the hashes ? is it better to store the old hash in a txt file ? do all these have an advantage over overwriting the old file ?

    You only know that, make some tests.


    So if you go the hash way, consider sha256 and xz (lzma2 algorithm) compression.
    I would do something like this (in Bash):

    newfilesum="$(wget -q www.example.com/file.txt -O- | tee file.txt | sha256sum)"
    oldfilesum="$(xzcat file.txt.xz | sha256sum)"
    if [[ $newfilesum != $oldfilesum ]]; then
        xz -f file.txt # overwrite with the new compressed data
    else
        rm file.txt
    fi
    

    and that’s done;

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

Sidebar

Related Questions

I have a cron job to run a Ruby script, which runs fine on
I have a shell script which is called by a cron job. I don't
I have a shell script that starts tomcat using 'catalina.sh start'. This script runs
Here's a snippet of code from a shell script I have written: for src
I need some help from the shell-script gurus out there. I have a .txt
I would like to execute a MySQL command in a shell script/cron job that
I need this cron job to execute my shell just as it does when
I have a shell script which I execute frequently in a day with different
I have a shell script that runs some acceptance tests for an application I'm
I have a shell script that runs every night to backup my EC2 sites

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.