1

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

sarnold
  • 102,305
  • 22
  • 181
  • 238
Ben
  • 69
  • 1
  • 9

1 Answers1

2

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).

paxdiablo
  • 854,327
  • 234
  • 1,573
  • 1,953
  • "locale" from command line returns LC_COLLATE="en_US.UTF-8", from crontab script it returns LC_COLLATE="POSIX". Not sure what all this means and what to do about it exactly, but sounds like this is the cause. Thanks – Ben Nov 14 '11 at 06:03
  • Should be easy enough to check, @Ben, set `LC_COLLATE` to `POSIX` on the command line and see if they start agreeing with each other. – paxdiablo Nov 14 '11 at 06:31
  • I am actually running the Linux 'comm' (and sort, join, etc..) from a PHP client-mode script using "shell_exec()". I have added putenv('LC_COLLATE=en_US.UTF-8'); to the beginning of the php script. This has solved the issue. The cron no longer behaves differently. Thanks again paxdiablo for your insights. – Ben Nov 14 '11 at 23:48