The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Possible to move files with cron job? [moved]

Discussion in 'General Discussion' started by Phree, Feb 21, 2006.

  1. Phree

    Phree Member

    Joined:
    Nov 17, 2005
    Messages:
    20
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    South Coast of England
    Possible to move files with cron job?

    Hi,

    this may be impossible, I don't know...

    I have a need to move files from one location on my site to another. I have cpanel access and I would like to run this every 30 minutes or so. Ideally, what I would like to do, is this:

    Move all files from /mysite/public_html/newmedia to mysite/public_html/publishnew

    However, I would also like to be able to change the filename at the same time, but keeping the same extension! For instance, I may have an image called picture1.jpg but I need to change it to yyyymmddhhmmss.jpg - yyyy=year mm=month etc., etc.

    Is this possible - and if so, could anyone please show me how? I don't have the first idea how I could or would achieve this but if it can be done, it would solve a problem for me that I have had for about 2 months!

    Thanks to anyone who can help...There's a pint in it for you!
     
  2. rustelekom

    rustelekom Well-Known Member
    PartnerNOC

    Joined:
    Nov 13, 2003
    Messages:
    290
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    moscow
    generally cron is just your robot which can automate your work. you don't need do some works each 5 minutes yourself. you just give to cron time period when your works will rund and give to cron some command which he need to be run, that's all, it is not magic.

    so, about your question. you may write simple shell(bash) script. It is look very similar like a DOS .bat file (if you know what is DOS :)), just for example:

    cd /mysite/public_html/newmedia
    cp ./*.files /mysite/public_html/publishnew/*.newfiles

    in your case you need more complex scripts which can be written on bash command or on perl or any script languages which you prefer and consist from gernerally three segment:

    1) you need get your current date and time
    2) get listing od your current files and rename it accordingly by 1) step and add some random value (for getting uniques filename)
    3) move your modified files to new location.

    then just assign in cron time for running this script.
     
  3. Phree

    Phree Member

    Joined:
    Nov 17, 2005
    Messages:
    20
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    South Coast of England
    Hi,

    thanks for your reply :) After posting, I kinda figured that was the case so I'll work on a script that will do it for me and then set a cron job to run. So far as cron jobs go, is it ok to run it say, every 5 minutes? I've never set one up before so I don't know the impact. I wouldn't be handling hundred of files every 5 minutes so the actual work on the server would be quite low.

    Thanks again!
     
  4. rustelekom

    rustelekom Well-Known Member
    PartnerNOC

    Joined:
    Nov 13, 2003
    Messages:
    290
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    moscow
    it's depend from script resource usage. i would recomment you, first, run script from command prompt and check how it work. if all is okay, check how long scripts work and how many resource he eat. then you may setup your cron accrodingly. for example if your script work more than a minute you shouldn't setup cron time less than 2 minute, if your scripts work more than 3 minute, you should setup cron as 5-10 minute period. if your script is resource eating, you may add to cron command prompt something like "nice -21" (command "nice" will change default system priority for your script. by defualt it is 0, when you will add this command it will 21).
    hope that this will help.
     
  5. Spiral

    Spiral BANNED

    Joined:
    Jun 24, 2005
    Messages:
    2,023
    Likes Received:
    7
    Trophy Points:
    0
    A simple file copy should not take up any significant resources so you can
    probably set the cron job for what time interval you wish.
     
Loading...

Share This Page