0

I have a rare problem.

When I execute a file by console, it works well, but when I execute it (the same file) by crontab I receive an error in the following part of the code

join -j 1 -t ',' <(sort $dir/Xem3.csv) <(sort $dir/coordenades.csv)|awk -F "," '{print  $15","$16","$17"," $3"," $4","$18"," $5"," $6","$7","$8"," $9","$10","$11","$12","$13}' > $dir/Xem4.csv

the error in the log of the crontab is

/home/enric/proves/web.sh: line 95: syntax error near unexpected token `('
/home/enric/proves/web.sh: line 95: `join -j 1 -t ',' <(sort $dir/Xem3.csv) <(sort $dir/coordenades.csv)|awk -F "," '{print  $15","$16","$17"," $3"," $4","$18"," $5"," $6","$7","$8"," $9","$10","$11","$12","$13}' > $dir/Xem4.csv'

any idea?

My script is

#/bin/bash

dir=/home/enric/proves

join -j 1 -t ',' <(sort $dir/Xem3.csv) <(sort $dir/coordenades.csv)|awk -F "," '{print  $15","$16","$17"," $3"," $4","$18"," $5"," $6","$7","$8"," $9","$10","$11","$12","$13}' > $dir/Xem4.csv

tr -d '\r' < $dir/Xem4.csv > $dir/out.csv
Enric Agud Pique
  • 1,087
  • 7
  • 13
  • 30
  • 2
    Does your console script specify the shell it's using? E.g. are you sure your crontab is using the same shell as your interactive login? – AlG Apr 14 '15 at 14:55
  • 1
    Looks like you're using process substitution `<(sort ...)`, a bash feature but your script is either invoked as `sh script.sh` or `./script.sh` with the wrong shebang. It should be `#!/bin/bash` at the top. – Tom Fenech Apr 14 '15 at 15:00
  • At the top I have #/bin/bash – Enric Agud Pique Apr 14 '15 at 15:26
  • 2
    @Enric that should be `#!/bin/bash` (with exclamation mark) – Tom Fenech Apr 14 '15 at 15:30

1 Answers1

2

Your first line is not a shebang line. You want #!/usr/bin/env bash. Without the exclamation mark the line is just another comment, and the script will be executed in the shell that cron uses (usually /bin/sh). <(my_command) is a bashism, hence the syntax error.

l0b0
  • 55,365
  • 30
  • 138
  • 223