Avatar of hiendang
hiendangFlag for Australia

asked on 

Mailx command and attachments not working as expected in RHEL Linux

Hi all,

I am trying to port some scripts that were writen in Tru64 over to Linux and when I try to execute an existing script that uses mailx to send a uuencoded attachment the attachment is missing from the received email.

Mailx takes in a command as standard input from a file and appends the standard output from the commands executed in that file and then mails it. On the alpha the commands work as you would expect however on the linux box the standard imput from the file is passed to mailx as a literal with the mail message being the contents of the input file.

eg mailx -s "why does this work on an alpha" foo@bar.edu.au < email_report_body.txt


The input file contains the following:

on the alpha
Hi, Report attached to this email
~<! /usr/bin/uuencode /usr/opt/sis/my_report my_report.xls

on the linux box*
Hi, Report attached to this email
~! /usr/bin/uuencode /usr/opt/sis/my_report my_report.xls

* the linux version of mail/mailx does not appear to like ~<! command to run a script or command but yet it is listed in the man page.

Is there something different with the RHEL implementation of mailx (which is a posix implementation of mail) or am I doing something wrong or stupid here?

I realise the command could be re-written, for example:
(cat email_report_body.txt ; uuencode my_report.txt my_report.xls) | mailx -s "This now works on RHEL" foo@bar.edu.au

......however this would be the last option chosen as obviously I would just like to port the code as is.

All suggestions greatly appreciated,
Regards



Linux OS Dev

Avatar of undefined
Last Comment
hiendang
Avatar of omarfarid
omarfarid
Flag of United Arab Emirates image

can you post the script you want to port?
Avatar of hiendang
hiendang
Flag of Australia image

ASKER

Sample script - text file
email-report-body.txt
Avatar of hiendang
hiendang
Flag of Australia image

ASKER

Sample script - shell script
email-report-sh.txt
Avatar of omarfarid
omarfarid
Flag of United Arab Emirates image

I would suggest:

#!/bin/sh
#

# Email the report, using the text file 'email_report_body.txt' to create the email body content/attachment.
echo "Emailing the files to the relevant parties...."
/usr/bin/uuencode /usr/opt/sis/my_report my_report.xls > file.$$
cat email_report_body.txt file.$$ | mailx -s "Daily Report" foo@bar.edu.au

You may remove the reference from the text file for the excel sheet

I noticed the following from the link below:

The example below is using > rather < as you are in your txt file

~r,~> !command            Read output from command into message


https://engineering.purdue.edu/ECN/Support/KB/Docs/MailXTutorial
ASKER CERTIFIED SOLUTION
Avatar of hiendang
hiendang
Flag of Australia image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of hiendang
hiendang
Flag of Australia image

ASKER

please close this question
Linux OS Dev
Linux OS Dev

Kernel programming for Linux operating systems can be done with many different languages; C, C++, Python, Perl and Java, which are some of the most common languages used.There are also many different varieties of Linux, such as Ubuntu, Fedora and OpenSUSE.

10K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo