コマンドで添付ファイル付メール送信

コマンドで添付ファイル付メールを送信したいなーという時があると思います。
ないとか言わないで下さい、きっとあります。
調べてみるとuuencodeというものを使えばできるらしい。
sharutilsパッケージに同梱されているようなのでyumでインストールを行います。

[root@cent5 ~]# yum install sharutils
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* addons: centos.mirror.secureax.com
* base: centos.mirror.secureax.com
* extras: centos.mirror.secureax.com
* updates: centos.mirror.secureax.com
Setting up Install Process
Resolving Dependencies
–> Running transaction check
—> Package sharutils.i386 0:4.6.1-2 set to be updated
–> Finished Dependency Resolution

Dependencies Resolved

================================================================================
Package Arch Version Repository Size
================================================================================
Installing:
sharutils i386 4.6.1-2 base 201 k

Transaction Summary
================================================================================
Install 1 Package(s)
Update 0 Package(s)
Remove 0 Package(s)

Total download size: 201 k
Is this ok [y/N]: y
Downloading Packages:
sharutils-4.6.1-2.i386.rpm | 201 kB 00:00
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
Installing : sharutils 1/1

Installed:
sharutils.i386 0:4.6.1-2

Complete!
[root@cent5 ~]# uu
uuclient uudecode uuencode uuidgen uuserver

コマンドが表示されたので問題なさそう

さっそく送ってみる

[root@cent5 ~]# uuencode test.log test.log | mail -s ‘test’ test@neko.mydns.jp

問題なくメールは送れました。

スクリプト等で集計したファイルを送ったりできるのは便利ですよね!

コメントする