1

I try to write a little script that overwrites from adress of nullmailer. Nullmailer has an option "allmailfrom" you can put a mail adress into /etc/nullmailer/allmailfrom and all mails sent have this address as "Return-Path", but From is still the value from so sending programm like pi@raspberrypi

So I've tried to create a little script to rewrite the from adress. Basically you move sendmail to sendmail-bin and name the created script sendmail. It works with the command "mail", adress is rewritten as it should. However with cron it doesn't work. STDIN is empty and so the output of cron isn't received via E-Mail. Syslogs writes

 /usr/sbin/sendmail: line 11: /dev/stdin: permission denied

Here the script.

#!/bin/bash
#########################################
#Beginn change here
export NULLMAILER_USER=user
export NULLMAILER_HOST=somedomain.com
#Ende change here
#############################################

export NULLMAILER_FLAGS=ft

stdin=$(</dev/stdin)

optPosition=0 #defaultvalue when not found

while getopts ":f:" from; do
    case $from in
        f) optPosition=$OPTIND
           break
           ;;
    esac
done


arguments=($@)

if (($optPosition != 0)); then #-f Option was used
 arguments[(($optPosition-2))]=$NULLMAILER_USER@$NULLMAILER_HOST
 set -- "${arguments[@]}"
fi



echo "$stdin" | /usr/sbin/sendmail-bin "$@"   

The NULLMAILER_USER with NULLMAILER_HOST and NULLMAILER_FLAGS=f tell nullmailer to use this as the from adress. That part works, see http://manpages.ubuntu.com/manpages/trusty/man1/nullmailer-inject.1.html

In crontab is just

*/1 * * * * echo test 

When orignal sendmail of nullmailer is present, then "test" is in the body of the mail, as it should. So why can't read this bash script from stdin?

0

replace line

stdin=$(</dev/stdin)

with

stdin=`cat`

and it works. Answer was inspired by https://stackoverflow.com/questions/212965/how-to-read-mutliline-input-from-stdin-into-variable-and-how-to-print-one-out-in

Don't know why this makes so much difference, important it works.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.