man: NAME: mailx, mail – interactive message processing system

send file as attachment

Use uuencode to encode a file and pipe it to mailx to be send as attachment (when you quickly need a file on your desktop it’s faster then ftp…)

uuencode file to mailx
$ uuencode file.txt file.txt | mailx -s file.txt <your-email-address>

In my environment the -r flag (return address) is needed since my mailserver is blocking mail without a known email address reply header.

uuencode file to mailx with -r flag
$ uuencode file.txt file.txt | mailx -s file.txt -r <your-email-address> <your-email-address>


Email yourself a list of modified (php) files automatically
One of my WordPress websites I created as a volunteer has been hacked – sunday morning ….. %^&*()

I want to email myself a list of modified php files in the last ‘N’ days to monitor if hack will comem back so I put this in my crontab.
Command below shows php files modified in the last 7 days – -mtime -7

$ find . -name "*.php" -mtime -7 -type f -print -exec ls -lart {} \;

Command below shows php files modified in the last 7 days, pipes output to mailx sending it to me

$ find . -name "*.php" -mtime -7 -type f -print -exec ls -lart {} \; | mailx -s

crontab entry to send myself lis of modifed php files
Make sure to always specify fully qualified paths in crontab.

# m h  dom mon dow   command
# ********** was hacked ... 7/22/2012 10:31:44 AM - cotnroleer voor aangepaste php files om te kijken of hack terug komt ...
0,5,10,15,20,25,30,35,40,45,50,55 * * * * /usr/bin/find /home/websites/ -name "*.php" -mtime -7 -type f -print -exec /bin/ls -lart {} \; | /usr/bin/mailx -s

Every five minutes is for testing only of course; time clause should be like daily ie – every morning at 7:30

# m h  dom mon dow   command
30 7 * * * 

Make ls list more readable – omit owner/group and make sizes human raadable –

$ ls -algGh wp-config.php
-rw-r--r-- 1 3.3K Jul 22 04:18 wp-config.php

Leave a Reply

Helpful? - leave your note below so I can brag

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>