shellunixscriptinguuencode

substitute for uuencode in UNIX shell scripting (to send an email from UNIX box)


I have been given a task to automate a script, and I have written a script for this purpose. This script needs to run from both datacentre and AWS. In the end the result needs to be zipped and sent to the intended recipient.

I have used uuencode to generate the mail in datacentre, which runs absolutely fine in the datacentre. However, when I run it in AWS, I am getting an error Syntax error: uuencode, not found.

Upon searching over the internet, I came to know this is happening because the uuencode is not installed in my AWS machine. Which is correct as I verified it.

I am new to coding, any help would really be appreciated. My problem here is that the AWS is a client machine where we are not supposed to install anything new. So, installing uuencode is not an option here for me.

Can someone please let me know an alternate command for uuencode.

Here are my linux versions:

Linux AWS version: 3.8.13-55.1.2.el6uek.x86_64 #2 SMP Thu Dec 18 00:15:51 PST 2014 x86_64 x86_64 x86_64 GNU/Linux

Linux Datacentre version: 2.6.18-194.el5 #1 SMP Mon Mar 29 22:10:29 EDT 2010 x86_64 x86_64 x86_64 GNU/Linux

and here is the piece of code I have written:

i

f [ -s $WORKINGDIR/Report.zip ]
then

(echo "Hi,

 Please find attached, report for datacentre.

 Please let us know for further clarifications.


Thanks,
JordanForever ";uuencode $WORKINGDIR/Report.zip Report.zip;)| mailx -s "report for datacentre " $MAILLIST
else
(echo "script for datacentre failed.

        Script Details:

                Host: $HOSTNAME
                Path: $WORKINGDIR

";) | mailx -s "Failed: report for datacentre " $FAILURE_MAILLIST
fi

I have tried mutt and sendmail command, but that did not help either.

Can one of you please help me out. I cannot install/uninstall uuencode. Any alternate command would help.

Regards


Solution

  • If you need uuencode and you cannot install uuencode, then consider python. In modern times, python is installed everywhere and uuencode is part of one of its standard modules.

    To uuencode Report.zip and send the output to stdout, try:

    python -c 'import sys,uu; uu.encode("Report.zip", sys.stdout)' # Python 2 only
    

    Update (2024)

    Python 3 distinguishes strings from (raw) bytes. If you are using Python 3.12 or earlier, then try:

    python3 -c 'import sys,uu; uu.encode("Report.pdf", sys.stdout.buffer)' # py 3.12 or earlier
    

    The uu module was deprecated in python 3.11 and will be removed in python 3.13. Going forward, python recommends using MIME encoding instead of uu encoding.