简体   繁体   中英

Cron job outputting php headers when piping to file

I've got a bash script which runs 4 commands and redirects to a file. This script works fine when I run it myself from the CLI on my server. It does not work when I let cron run the script.

my file looks something like this:

#!/bin/bash
command > file.csv
command >> file.csv
command >> file.csv
command >> file.csv

I get the expected result when I run it myself but when cron runs it I get this:

X-Powered-By: PHP/7.1.31
Content-type: text/html; charset=UTF-8

X-Powered-By: PHP/7.1.31
Content-type: text/html; charset=UTF-8

X-Powered-By: PHP/7.1.31
Content-type: text/html; charset=UTF-8

X-Powered-By: PHP/7.1.31
Content-type: text/html; charset=UTF-8

I execute the cron job like this:

/usr/bin/php -q /home/user/rest/of/path/script.sh >/dev/null

can someone please help? Driving me mad....

The solution was specifying a PATH property in the bash script.

I echoed the $PATH variable in my shell and copied this into the script and this seemed to solve things.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM