1

I'm trying to automate some mundane stuff I have to do with bash, but I'm running into trouble with debugging. Basically when I run interactively the script runs fine, but when I submit the job to a batch system whatever I'm running prints

Please answer yes or no.

multiple times. The problem is that I have no idea what it's asking me. Is there some way to direct the prompt to be printed so I can debug this?

Shep
  • 7,990
  • 8
  • 49
  • 71
  • 2
    Have you tried [`bash -x`](http://stackoverflow.com/questions/10107124/bash-x-command)? Basically, `bash -x -c your-script.sh`. – Boldewyn May 09 '14 at 12:47
  • hmm, that's theoretically useful, but the problem is that bash is executed by the batch system. Is there some way to turn that option on once I'm in a script? – Shep May 09 '14 at 12:50
  • hmm, so it seems there is: http://stackoverflow.com/a/951352/915501 – Shep May 09 '14 at 12:52
  • 1
    yes `set -x` and `set +x` – PradyJord May 09 '14 at 13:18
  • still doesn't really help, this just tells me that the method calls a python script. I'd imagine that python somehow prints a prompt, but I can't seem to view it. – Shep May 09 '14 at 13:28
  • Doesn't the batch system give you a capture of stdout when it runs your job? How about result files? you could redirect stdout to a file in the script with `exec >file` – Jacobo de Vera May 09 '14 at 14:45
  • Workaround: try to execute as `/bin/bash -i myscript.sh` and/ or to put `#!/bin/bash -i` as 1st row... you can try to cheat it ;) – Hastur May 29 '14 at 16:19

1 Answers1

0

I think your script is in sort of need for a TTY, my workaround is this one:

have_tty()
{
    tty >/dev/null 2>&1
    return $?
}

say()
{
    if have_tty; then echo $@; return; fi
    logger -i -t restart_libertas $@
}

Just replace

echo

with

say

and I think you're done

user2285948
  • 101
  • 1