I have bash script
#!/bin/sh
DTFILE=/etc/daytime.addr
DTPORT=13
DAYTIME_ERROR=/tmp/dtm.err
function daytime_error(){
if [[ -z $1 ]]
then
exit 1
fi
if [[ -e $DAYTIME_ERROR ]]
then
echo "Error already reported"
else
logger "$1"
touch $DAYTIME_ERROR
fi
exit 1
}
if [[ -s $DTFILE ]]
then
ADDR=$(head -n1 $DTFILE)
DAYTIME=$(telnet $ADDR $DTPORT | time_conv.awk)
if [[ -z $DAYTIME ]]
then
daytime_error "Daytime client: no connection to $ADDR"
else
date -s "$DAYTIME"
hwclock -w
rm $DAYTIME_ERROR
fi
else
daytime_error "Daytime client: no daytime server address in file $DTFILE"
fi
and it works when called from command line, but fails when cron calls it. Specifically the line with telnet command gives zero bytes of output. Telnet has 755 mask, so every user should be able to use it. Any ideas ?
/path/to/bash /path/to/scriptto the cron rather than/path/to/scriptto humour me? Also add a full path to any non-builtin executables such as telnet? – PriceChild Apr 21 '11 at 10:32#!/bin/shit's not really a bash script, even if /bin/sh is symlinked to bash. Bash behaves differently if invoked as "sh". – glenn jackman Apr 21 '11 at 13:12