Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I use the following commands to copy the entire directory to another server.

Sending server:

cd /var/log/ && tar c mysql > to_analyse.tar && nc 10.10.10.99 1236 < to_analyse.tar

Receiving server:

mkdir -p /var/log/splunk/from_217 && cd /var/log/splunk/from_217 && nc  -l 1236 > to_analyse.tar && tar -xf to_analyse.tar

It is working as expected. But when I add it to cron (copy paste with appropriate times), it does not work.

share|improve this question
1  
It's usually the best idea to simply put it all in a script, and call the script from cron. You'll get predictable better supported results. –  Chris S Jul 7 '11 at 12:29
add comment

1 Answer 1

up vote 3 down vote accepted

There are several things to check when using cron:

1- The user that is executing the cron job. This will affect the privileges assigned to the cron jobs.

2- The environment variables. Some scripts command may require some environment variables to work as expected.

3- It is better to refer to binaries/scripts using full path instead of just its name like mkdir and nc. I am not saying it will not work. It may or may not depending on the PATH definition and binary location.

share|improve this answer
    
cd is always just cd since it's a shell built-in. You may have a cd executable, but it's purpose is to test whether you can cd into a given directory (by checking the return value). –  DerfK Jul 7 '11 at 12:26
    
@DerfK: Yes, you are right. Thanks! –  Khaled Jul 7 '11 at 13:01
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.