0

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.

1
  • 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, 2011 at 12:29

1 Answer 1

3

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.

1
  • 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, 2011 at 12:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .