如何解决“input设备不是TTY”使用grunt-shell来调用docker运行的脚本?
当发出grunt shell:test
,我得到警告“input设备不是TTY”,不想使用-f
:
$ grunt shell:test Running "shell:test" (shell) task the input device is not a TTY Warning: Command failed: /bin/sh -c ./run.sh npm test the input device is not a TTY Use --force to continue. Aborted due to warnings.
这里是Gruntfile.js
命令:
shell: { test: { command: './run.sh npm test' }
这里是run.sh
:
#!/bin/sh # should use the latest available image to validate, but not LATEST if [ -f .env ]; then RUN_ENV_FILE='--env-file .env' fi docker run $RUN_ENV_FILE -it --rm --user node -v "$PWD":/app -w /app yaktor/node:0.39.0 $@
下面是命令test
的相关package.json
scripts
:
"scripts": { "test": "mocha --color=true -R spec test/*.test.js && npm run lint" }
我怎样才能让docker
满意TTY? 执行./run.sh npm test
在grunt之外工作正常:
$ ./run.sh npm test > yaktor@0.59.2-pre.0 test /app > mocha --color=true -R spec test/*.test.js && npm run lint [snip] 105 passing (3s) > yaktor@0.59.2-pre.0 lint /app > standard --verbose
从docker run命令中删除-t
:
docker run $RUN_ENV_FILE -i --rm --user node -v "$PWD":/app -w /app yaktor/node:0.39.0 $@
-t
告诉dockerconfigurationtty,如果你没有tty并且尝试附加到容器(默认不做-d
),tty将不起作用。
这为我解决了一个恼人的问题。 脚本有这些行:
docker exec **-it** $( docker ps | grep mysql | cut -d' ' -f1) mysql --user= ..... > /var/tmp/temp.file mutt -s "File is here" someone@somewhere.com < /var/tmp/temp.file
如果直接运行,该脚本将运行得非常好,并且邮件将带有正确的输出。 但是,从cron
运行时,( crontab -e
)邮件将没有内容。 尝试许多权限和shell和path等事情,但没有喜悦!
终于find了这个:
*/20 * * * * scriptblah.sh > $HOME/cron.log 2>&1
并在该cron.log
文件find这个输出:
input设备不是TTY
search带领我到这里。 而我删除了-t
,现在它工作的很好!
docker exec **-i** $( docker ps | grep mysql | cut -d' ' -f1) mysql --user= ..... > /var/tmp/temp.file