Ben
Ben

Reputation: 69

linux comm produces different results when run from crontab

I am running the following command from a bash script:

comm -23 file1 file2 > file3

(file1 & file2 are de-duped and sorted first)

This produces a file3 that contains rows unique to file1 only (what I want).

When the script is run from the command line, there are no issues. However, when it is run from the crontab, it produces a much larger (incorrect) file3. The crontab user is the same as the logged-in user when run manually.

Any clues as to what would cause such a discrepancy?

Thanks in advance

Upvotes: 1

Views: 1207

Answers (1)

paxdiablo
paxdiablo

Reputation: 881463

Almost all disparities between programs running from your shell and from within cron have to do with the environment.

The first thing to do is to run something like env in both places and capture the output. It may be something as simple as running a different executable because the paths are different.

Another possibility is that the LC_COLLATE setting is different between the two environments. From the info page:

Before comm can be used, the input files must be sorted using the collating sequence specified by the LC_COLLATE locale.

The --check-order option may be a way to check this, causing a fatal error on unsorted input (including unsorted based on a different collation than you think you're using).

Upvotes: 2

Related Questions