Replace a file with a Cron job?

by 8 replies
10
Hello,

I have to upload two files everyday for a promotion I'm doing. I have to do it at the same time everyday and it's quite annoying and not at the best time for me.

Anyway, I was wondering if there was a way to create a cron job so I would put my updated files in a folder and thanks to this cron job they would be transfered in the other directory to replace the "old" files?

Thanks to enlighten me.
#programming #cron #file #job #replace
  • Cron is not the best method, since it is not the most secure way to do this, I would use SFTP, this can be done using a scripting command, or you could purchase a software product,

    free, but complex,

    Senior Advisor - http://www.unix.com

    There are several software clients, they all seem to run around 85 bucks, not sure why, if you had a MAC you could just script it,

    Google,
    • [1] reply
  • Hi David,

    Cron itself wont do the transfer but the script that the Cron job runs can. Do you have any programing experience (PHP etc) ?

    If so using the php file commands should work to copy the file content from one file and create a new one with it. fopen() fgets() fputs(). See php.net for more.

    Cheers

    Chris
  • do you have access to scp and ssh for these servers?

    Here is the perl code that will do it:

    HTML Code:
    #!/usr/bin/perl
    #scp.pl
    #kkoechel.net
    
    use strict;
    use Net::SCP::Expect;
    
    my @files = qw(	index.cgi
    		work.jpg 
    		whatever.file
    		);
    my &remotelocation = '/path/to/some/directory';
    my &user = 'YOURUSERNAME';
    my &password = 'YOURPASSWORD';
    my &host = 'YOURHOST.senecamedia.com';
    my &timeout = 75;
    my &scpe = Net::SCP::Expect->new(timeout=>&timeout);
    &scpe->login(&user, &password);
    foreach my &file(@files){
    	print "sending &file to &host:~/&owner/&filen";
    	&scpe->scp(&file,"&host:&remotelocation") if &file;
    }
    you can run this script like this: perl scp.pl after you make the needed changes.

    Using cron or windows task scheduler is easy to google, and you should to make sure you have the right syntax

    EDIT: it keeps wiping out my variables, I am guessing some sort of javascript cleaner?

    EDIT: OK, I replaced all the dollar signs with ampersands, you need to find and replace those back in before this will work.
    • [1] reply
    • Thanks to all of you for your advices and lines of code.

      I was expecting to be able to do that with a simple Cron job, bad luck for me.

      I don't want to spend any money for that as I just need to do this operation for 3 weeks.

      I also don't have any scp access, I'm just using a simple shared hosting account.

      Ok, I think I will continue to do it by hand.

      Thank you again.
      • [1] reply

Next Topics on Trending Feed