Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I can't find the error, the scripts runs fine from console, I thought it was PHP thing but couldn't fine anything.

Maybe permissions things? Exec things? I really don't know much, hope someone can help me. Thanks!

BASH Script (SIMPLY SENDS A JOB TO A PRINTER, but I put it enterely just in case):

#!/bin/bash
PBOX_DIR_TMP="/tmp"
DESDE=$1
HASTA=$2
FORMULARIO=$3
COLA=$4
FECHA=$(date +%F)
SPOOL="/spool.$$.txt"
ARCHIVOSALIDA="${PBOX_DIR_TMP}"/salida.$$.txt
RETURNCODE=0
echo "$DESDE"
echo "$HASTA"
echo "@PBSSFORM ${FORMULARIO}" > "${SPOOL}"
for ((i = ${DESDE};i <= ${HASTA};i++))
do
  if [ $i > ${DESDE} ]
  then
    echo -e "\f${FECHA}" >> "${SPOOL}"
    echo "${i}" >> "${SPOOL}"
  else
    echo "${FECHA}" >> "${SPOOL}"
    echo "${i}" >> "${SPOOL}"
  fi
done
cat "${SPOOL}" | pboxsvc ${PBOX_DIR_BIN}/pboxlib.bin AplicarHostForm > "${ARCHIVOSALIDA}"
lp -d "${COLA}" "${ARCHIVOSALIDA}"
RETURNCODE=$?
rm "${ARCHIVOSALIDA}"
rm "${SPOOL}"
if [ ${RETURNCODE} -eq 0 ]
  then
    exit 1
  else
    exit 0
fi

PHP call:

$cmd = "/printb/imprimirFormPlano.bin 1 2 FILE.PS Cola1";

Apache Log:

/printb/imprimirFormPlano.bin 1: Syntax error: ")" unexpected
sh: 2: not found.

The scripts works if I call it from shell like this: ./printb/imprimirFormPlano.bin 1 2 FILE.PS Cola1

share|improve this question
 
what does this have to do with PHP? –  thatidiotguy Dec 13 '12 at 16:26
 
@thatidiotguy I need to call it from PHP. It will be web based –  Jorge Dec 13 '12 at 16:27

1 Answer

It looks like your apache's default shell is sh rather than bash. Try changing your command to

$cmd = '/bin/bash /printb/imprimirFormPlano.bin 1 2 FILE.PS Cola1';
share|improve this answer
 
Thanks, it gives different output in apache's error log: /printb/imprimirFormPlano.bin: Cannot execute binary file. sh: 2: not found (I converted it to bin from .sh) –  Jorge Dec 13 '12 at 16:30
 
@Jorge Converted how? –  NullUserException Dec 13 '12 at 16:31
 
@NullUserException Sorry it's encripted the one that converts to bin. –  Jorge Dec 13 '12 at 16:33
 
@Jorge Why do you need to make this conversion? Why can't you just call the .sh file itself? –  NullUserException Dec 13 '12 at 16:39
 
@NullUserException I don't know it's my works politic. I tried using the sh with PHP but gives me access errors to locations (maybe user problem). The strange thing is that the error is like this: /spool.4234.txt Access denied is like if its trying to save on / instead of /temp/. –  Jorge Dec 13 '12 at 16:46

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.