调用cat时悬挂的shell脚本 [英] Shell script hanging when calling cat

查看:58
本文介绍了调用cat时悬挂的shell脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Shell脚本,可通过电子邮件将通过crontasks遇到的错误发送给我,如下所示:

I have a shell script which emails me errors encountered via crontasks which looks like the following:

exec >&-;

output="$(cat)";

shopt -s nocasematch

if [[ "$output" == *"error"* || "$output" == *"warning"* ]]; then
    echo "$output" | mail -s "Error" my@email.com;
fi

exit 0;

我的crontab如下:

My crontab looks like:

*/1 * * * * /opt/sh/email.sh /usr/bin/php /home/sites/website/app/console my:cli:command >> /var/log/cron.d/ my.cli.command/log 2>&1

该脚本有效,但"cat"似乎挂起:

The script works, but "cat" seem to hang:

root 23083 0.0 0.0 139752 1112 ? S Mar20 0:00 \_ CROND
500 23091 0.0 0.0 106096 1016 ? Ss Mar20 0:00 | \_ /bin/sh -c /usr/bin/php /var/www/website/app/console my:cli:command 2>&1 | /usr/local/bin/email.sh
500 23096 0.0 0.3 463528 27292 ? S Mar20 0:35 | \_ /usr/bin/php /var/www/website/app/console my:cli:command
500 23097 0.0 0.0 106096 1048 ? S Mar20 0:00 | \_ /bin/bash /usr/local/bin/email.sh
500 23101 0.0 0.0 100936 496 ? S Mar20 0:00 | \_ cat
root 12167 0.0 0.0 139752 1276 ? S Mar22 0:00 \_ CROND
500 12183 0.0 0.0 106096 1104 ? Ss Mar22 0:00 | \_ /bin/sh -c /usr/bin/php /var/www/website/app/console my:cli:command 2>&1 | /usr/local/bin/email.sh
500 12185 0.0 0.4 463528 36612 ? S Mar22 0:32 | \_ /usr/bin/php /var/www/website/app/console my:cli:command
500 12186 0.0 0.0 106096 1104 ? S Mar22 0:00 | \_ /bin/bash /usr/local/bin/email.sh
500 12194 0.0 0.0 100936 516 ? S Mar22 0:00 | \_ cat
root 1675 0.0 0.0 139752 1128 ? S Mar25 0:00 \_ CROND

那里有什么主意吗?

推荐答案

它挂起是因为您没有给 cat 进行连接的任何输入,因此它将永远听STDIN.

It is hanging because you're not giving cat any input to concatenate, so it will just listen to STDIN forever.

在手册页中:

cat实用程序按顺序读取文件,并将它们写入标准输出.文件操作数按命令行顺序处理.如果文件是单个破折号(`-')或不存在,则cat从标准输入中读取.如果file是UNIX域套接字,则cat连接到它,然后读取它直到EOF.这补充了inetd(8)中可用的UNIX域绑定功能.

The cat utility reads files sequentially, writing them to the standard output. The file operands are processed in command-line order. If file is a single dash (`-') or absent, cat reads from the standard input. If file is a UNIX domain socket, cat connects to it and then reads it until EOF. This complements the UNIX domain binding capability available in inetd(8).

这篇关于调用cat时悬挂的shell脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆