开发者

SIGPIPE when echoing variable inside bash script

开发者 https://www.devze.com 2023-04-09 05:18 出处:网络
I have a cronjob running on a debian box. At certain points through the script, I set variables via HOSTNAME=$( hostname -s | tr A-Z a-z )

I have a cronjob running on a debian box. At certain points through the script, I set variables via

HOSTNAME=$( hostname -s | tr A-Z a-z )

then later, I log that value to syslog (so I can see that everything is running properly)

function log {
    # just echo it
    echo 开发者_运维百科-n `date -u "+%s"`
    echo -n " "
    echo $1

    /usr/bin/logger -t $0 -- $1
}

log "Hostname: ${HOSTNAME}"

However, on this box, I receive a SIGPIPE. This happens many times throughout the script. I've trapped the SIGPIPE to confirm that this is the case, but would like to actually fix the problem instead.

Can someone tell me what might be causing the SIGPIPE, and how to fix it? I've tried creating a smaller test-script, but that script doesn't react the same way.


My guess: within the cron environment, the PATH is limited, which means the shell might not be able to find hostname and/or tr. First, find out where hostname and tr are located and use absolute path instead, for example:

HOSTNAME=$( /bin/hostname -s | /usr/bin/tr A-Z a-z )
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号