[lug] sed from cron job fails (works from command line)
Lee Woodworth
blug-mail at duboulder.com
Mon Oct 22 20:06:53 MDT 2007
Ben wrote:
> Thanks everyone for all the suggestions. Unfortunately, nothing yet has
> worked.
>
> In /etc/crontab I already have then line:
>
> SHELL=/bin/sh
>
> and /bin/sh is a symlink to /bin/bash
>
> I tried having my script run /etc/skel/.bashrc and
> /etc/skel/.bash_profile before running sed, but that didn't make any
> difference. (/etc/skel holds the defaults user config files).
IIRC, the skel files are used when a new account is created.
Your environment is different in the cron job. Find your version of cron
(fcron, visiecron, ...) and look at the man page to see how it sets up the environment.
Try adding these to the beginning of your cron job to get info about
the environment.
id > /tmp/cron-debug.txt 2>&1
set >> /tmp/cron-debug.txt 2>&1
This will tell you the UIDs the job is run with (the id command), and
the environment variables (the set command, may need to adjust this
for sh, I know it works for bash).
>
> I added "-x" to the first line #!/bin/sh -x I didn't learn anything
> from the debugging, but maybe someone else can:
>
> ++ grep reject /var/log/mail.log.0
>
> ++ tail -n 1
> ++ head -n 1
> + line=Oct 19 06:39:18 localhost postfix/smtpd[6853]: NOQUEUE: reject:
> RCPT from unknown[122.35.234.34]: 450 Client host rejected: cannot find
> your hostname, [122.35.234.34]; from=<spammer at spamsolutions.com>
> to=<niceguy at mydomain.com> proto=SMTP helo=<140414104>
> + echo Oct 19 06:39:18 localhost 'postfix/smtpd[6853]:' NOQUEUE: reject:
> RCPT from 'unknown[122.35.234.34]:' 450 Client host rejected: cannot
> find your hostname, '[122.35.234.34];'
> 'from==<spammer at spamsolutions.com>' 'to=<niceguy at mydomain>' proto=SMTP
> 'helo=<140414104>'
> + sed -e 's/\(.*RCPT\ from\ \)\([a-Z0-9\.\-]*\)\[\([0-9\.]*\)]:\
> \(.*;\).*from=<\(.*\)>\ to=<\(.*\)>\
> proto.*helo=<\(.*\)>.*/\2\t\3\t\5\t\6\t\7\t\4/g'
> sed: -e expression #1, char 139: Invalid range end
> + i=2
> + '[' 2 -le 20 ']'
>
> and as I mentioned in the original post, the offending sed line (which
> works from the command line) is:
>
> cat somefile|sed -e 's/\(.*RCPT\ from\
> \)\([a-Z0-9\.\-]*\)\[\([0-9\.]*\)]:\ \(.*;\).*from=<\(.*\)>\
> to=<\(.*\)>\ proto.*helo=<\(.*\)>.*/\2\t\3\t\5\t\6\t\7\t\4/g'
What environment variables does sed implicitly use? In particular
ones related to white space/word/line breaks.
More information about the LUG
mailing list