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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T14:04:56+00:00 2026-05-13T14:04:56+00:00

I am working on a script to create files basically replica of some tables

  • 0

I am working on a script to create files basically replica of some tables and ftp those files to the remote machine.there is one more requirement to delete the 3days old files on the remote machine before dumping these files.

I need help in writing the ksh for deleting 3 days old files on a remote machine using ftp

  • 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-13T14:04:57+00:00Added an answer on May 13, 2026 at 2:04 pm

    Normally, you would use:

    find . -mtime +3 -exec rm {} ';'
    

    or something similar (i.e., there may be other limiting clauses like -type f for regular files or -maxdepth 0 to do current directory only, no subdirectories). The -mtime +3 only gets those files whose modification date is 3 days age or more.

    Execute man find on your system for full details. Whether Solaris has the same features as GNU find I don’t know. It may be more limited (or better).


    Update: Please, in the name of whatever gods you worship, please test the command first with echo instead of rm. I take no responsibility for the destruction of your files if you trust the advice of “some random guy on the net who may or may not have your best interests at heart” 🙂


    And, before anyone jumps in and berates me for not using xargs (or, better yet, find -print0 with xargs -0 where available), I know. But it’s not relevant to the specific question at hand. The OP can ask another question if and when the performance of the find -exec is a problem.


    If you have a specific file format with the date in it (as you indicate in your comment), you can actually use mdel under ftp. Consider the following script:

    # The prefix and suffix of files to delete.
    prefix='*_'
    suffix='-i.tbl'
    
    # Create FTP script file.
    rm -rf temp.ftp
    echo "user pax pax_password" >>temp.ftp
    echo "cd /my/directory" >>temp.ftp
    echo "prompt" >>temp.ftp
    
    # Get current date.
    y=$(date +%Y)
    m=$(date +%m)
    d=$(date +%d)
    ((lasty = y - 1))
    ((lastm = m - 1))
    
    # If past Jan 3, delete all of previous year.
    if [[ $m -gt 1 || $d -gt 3 ]] ; then
        echo "mdel ${prefix}${lasty}????${suffix}" >>temp.ftp
    fi
    
    # If past Jan and past the third, delete all of previous month.
    if [[ $m -gt 1 && $d -gt 3 ]] ; then
        if [[ ${lastm} -lt 10 ]] ; then
            echo "mdel ${prefix}${y}0${lastm}??${suffix}" >>temp.ftp
        else
            echo "mdel ${prefix}${y}${lastm}??${suffix}" >>temp.ftp
        fi
    fi
    
    # If past the third, delete current month more than three days old.
    if [[ $d -gt 3 ]] ; then
        ((d = d - 3))
        if [[ ${m} -lt 10 ]] ; then
            m="0${m}"
        fi
        while [[ ${d} -gt 0 ]] ; do
            if [[ ${d} -lt 10 ]] ; then
                echo "mdel ${prefix}${y}${m}0${d}${suffix}" >>temp.ftp
            else
                echo "mdel ${prefix}${y}${m}${d}${suffix}" >>temp.ftp
            fi
            ((d = d - 1))
        done
    fi
    
    # Finalise script and run it.
    echo "bye" >>temp.ftp
    ftp -n mymachine.com <temp.ftp
    rm -rf temp.ftp
    

    Other than a slight annoyance where you may have up to six days of files left there on month boundaries, this does what you need. You could of course make the code handling the month boundaries a little more intelligent if that’s really important.

    Just run this script on your box each day and it will clear out files on the target box by using standard ftp tooling. I still think it’s easier to run a find on the server box but I’ll present this option if that avenue is not available.

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

Sidebar

Related Questions

Greetings, A script is working on one or more files. I want to pass
I`m working on a script to create csv files for an analysis. When running
I'm working on a Python script to go through two files - one containing
I am creating a script on the fly to ftp some files from a
I'm working on a few scripts to create txt files, rsync a few files
I used this script to create a jQuery accordion. Check out the working jsFiddle
I'm working on a Python script that needs to create about 50 distinct temporary
I have a working script from someone, there in is this line: this.event =
I am working on a script that downloads various image files from the web
I'm working to create a simple Python script that will ultimately tell you how

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.