0

I am trying to write a cronjob to do an action if replicationTest.txt does not exist and replicationTestSeen.txt does exist in a specific directory. Right now what I am doing is not working. Here is the what I am doing:

0 3 * * 0 [ [ ! -e /dv1/replicationtest/replicationTest.txt ] && [ -e /dv1/replicationtest/replicationTestSeen.txt ] ] && echo 'replication passed' | mail -s 'Replication Test Passed' myemail@email.com || echo ' replication failed' | mail -s 'Replication failed' myemail@email.com

Even when the conditions are right for the cron to email replication passed it still emails replication failed.

Alec H
  • 7
  • 1

1 Answers1

0

You’re mixing your tests. This pattern of [ [ ... ] && [ ... ] ] should not work. See this answer for details. If you change your tests to this it should work:

[[ ! -e ... ]] && [[ -e /dv1/... ]]

Test your conditions outside of cron before putting them into your crontab. And make sure of which shell your cron is actually set to use.

Community
  • 1
  • 1
Micah Elliott
  • 9,600
  • 5
  • 51
  • 54