[lug] sed from cron job fails (works from command line)

Ben bluey at iguanaworks.net
Mon Oct 22 09:34:23 MDT 2007


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).

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'

While I'm asking about silly escape characters and the such. Is there a 
good way to cat the $variable line of a file inside a bash script? On 
the command line I'd use awk: cat file|awk '(print NR==500) {print }' -- 
but if I put that in a bash script and replace 500 with $i (and set 
i=500) it doesn't work because bash sees $i inside quote and so doesn't 
replace $i with its value. My hack-ish solution is

|head -n $i |tail -n 1

but this is hardly efficient with large files.

Thanks for the help, and if anyone has more suggestions, I'd appreciate it.

Ben



Jeffrey Haemer wrote:
> Any luck?
>




More information about the LUG mailing list