Cron Job and log file copy help

toddhutch

Verified User
Joined
Dec 12, 2007
Messages
7
I've tried to figure this out but it appears I'm missing something.

I need to copy the log files from the default location to a directory that I'm going to give specific access to via FTP.

if I run this command it does what I'd like it to do, but I'd like this command ran daily. (xxxx I've removed the actual domains)

cp -f domains/xxxx.com/logs/* domains/xxxx.com/public_logs

I've created a file using pico called copylog.sh

here is the contents-

cp -f domains/xxxx.com/logs/* domains/xxxx.com/public_logs

The file is located at home/userxxxx/

when I setup the cron job in the direct admin I did this-

*/1 * * * * /home/userxxxx/copylog.sh

But this doesn't appear to run. (I've set it to the one minute so I can test eventually it will be this -- * */24 * * * /home/leupold/copylog.sh )


Any help or pointers would be very much appreciated it.
 
Last edited:
Try putting "#!/bin/sh" at the top of your script. It should look like this:

Code:
#!/bin/sh
cp -f domains/xxxx.com/logs/* domains/xxxx.com/public_logs

You may also have to give the full path in your script, for example:

Code:
cp -f /home/user/domains/xxxx.com/logs/* /home/user/domains/xxxx.com/public_logs
 
Last edited:
I've added the first line and the full path.

I added #!/bin/sh to the top of the copylog.sh file

waited 2 minutes no files were copied...

so I added the full path, and I've waited 2 minutes no files were copied...

should there be an initial / in the path directory for the co command?

the command I tested didn't have an / to start with.

cp -f home/userxxx/domains/xxxx.com/logs/* home/userxxx/domains/xxxx.com/public_logs

should it have an initial /?

cp -f /home/userxxx/domains/xxxx.com/logs/* /home/userxxx/domains/xxxx.com/public_logs

Boy I'm going nutz on this one. Do I need to just wait more then 60 seconds one you hit the add button in DA? Or do you need to run another command to kick off the newly added cron job?



-Todd
 
Last edited:
nope, but I just did.

chmod 755 copylog.sh



Waited 2 minutes and no files have been copied, should I delete an re-add the conjob via DA?
 
screen shot of DA

There you go...

-Todd
 

Attachments

  • dascreen.JPG
    dascreen.JPG
    140.5 KB · Views: 184
It's probably something ovbious that I'm just not seeing. One more question, is the user that the cron job is going to run under the owner of the .sh file? If not, then you'll need to make sure he/she is. If that doesn't work, then I'm afraid I have no other ideas. Oh, one more thing, check to see if the crond service is even running on the server. Are other cron jobs running okay?
 
Try changing it to:

Code:
#!/bin/sh
/bin/cp -f ./domains/xxxx.com/logs/* ./domains/xxxx.com/public_logs

or

Code:
#!/bin/sh
/bin/cp -f /home/username/domains/xxxx.com/logs/* /home/username/domains/xxxx.com/public_logs

or

Code:
#!/bin/sh
homedir=/home/username
/bin/cp -f $homedir/domains/xxxx.com/logs/* $homedir/domains/xxxx.com/public_logs
 
It's probably something ovbious that I'm just not seeing. One more question, is the user that the cron job is going to run under the owner of the .sh file? If not, then you'll need to make sure he/she is. If that doesn't work, then I'm afraid I have no other ideas. Oh, one more thing, check to see if the crond service is even running on the server. Are other cron jobs running okay?


I should have said that I'm not that familar with unix, so if there is a command I should run on the file, (I have SU access to the box) I can do that, but you'll need help with the exact syntax of the command. I did the chmod 755, but I don't know how to check ownership or change ownership of the file. I did create it when I was logged in as a SU, so perhaps I should log in as the user and recreate the file? Or is there a command I can run to change it.

Thx -
Todd
 
Type:

chown username:username filename

change username with the actual username
 
We have a winner!!!!!!!!

Try changing it to:

Code:
#!/bin/sh
cp -f ./domains/xxxx.com/logs/* ./domains/xxxx.com/public_logs


That worked!!!!!

Thank you very much for you help, I'd spent 6-8 hours before posting to the forum attempting to figure it out. Thank you!
 
Last edited:
More than likely it was because of the missing /bin infront of cp and it didnt know the path to the cp command.
 
clarification

More than likely it was because of the missing /bin infront of cp and it didnt know the path to the cp command.

Actually I didn't notice that difference and didn't add in the /bin/cp ...

cp -f ./domains/xxxx.com/logs/* ./domains/xxxx.com/public_logs

I just replaced the /home/userxxx/ with the ./ and that made it work.

Thank you for the help.

-Todd
 
I would have noticed this earlier but I haven't been on the forum in a while; yes you should have had a leading / before home.

Jeff
 
Back
Top