Score:0

mailutils in script versus command line

br flag

The following works fine as expected from command line:

mail < /home/incoming/mailprocoutput.txt -s "Message Processing results..." -r [email protected] [email protected]

cat filename pipe mail etc also works fine on command line. But either method results in an empty message body when used in a shell script:

#!/bin/bash
# This is to send an email from the mailproc python script with the results of message processing

timestamp=$( date +%T )
curDate=$( date +"%m-%d-%y" )

logger "Mailproc has run at $timestamp on $curDate, sending response back to the creator..."

mail < /home/incoming/mailprocoutput.txt -s "Message Processing results..." -r [email protected] [email protected]

exit

What am I doing wrong? Ubuntu 18.04, GNU mailutils version 3.4

FedKad avatar
cn flag
Are the command line and the script being run from *the same user*? Do you get any _stderr_ output from the script?
waltinator avatar
it flag
Always paste your script into `https://shellcheck.net`, a syntax checker, or install `shellcheck` locally. Make using `shellcheck` part of your development process.
waltinator avatar
it flag
Are you running the script at system startup, via `cron`, `at`, or `batch`? Look at the results of `echo "=== id ===";id;echo "=== set ===";set;echo "=== env ===";env | sort;echo "=== alias ===";alias` in each of your environments.
alabamatoy avatar
br flag
@FedKad apparently it is indeed a user issue. The script runs under user incoming and indeed the command line cat-to-pipe-to-mail does not work for that user, but works for root. So I have a user rights issue.
alabamatoy avatar
br flag
su username then attempt to cat file and I get nothing. the file is 0644 username:username So is there something I have to do to allow the user to have rights to cat something which is shown as owned by that user? Befuddled, I am.
FedKad avatar
cn flag
I would redirect the `stderr` output _of the whole script_ to some writable location like `2>/tmp/mymail.err` to see what the error is.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.