====== mailコマンド ======
====== mail ======
===== mailのフロー =====
- /var/spool/mail/root にメールが届く
- mail コマンドでメールを確認する
- 数字+Enterで任意のメールを読む
- d数字+Enterで任意のメールを削除
- h でメールリストを開く
- q で閉じる
- /root/mbox に既読メールが保存される(Saved ** messages in mbox)
- mail -f で既読メールを確認する
===== mailコマンド =====
==== カーソルの位置のメールが現在選択されているメール ====
# mail
U754 MAILER-DAEMON@kd-adm Mon Oct 15 01:00 251/8692 "Undelivered Mail Returned to Sender"
>U755 MAILER-DAEMON@kd-adm Mon Oct 15 02:23 251/8692 "Undelivered Mail Returned to Sender"
U756 MAILER-DAEMON@kd-adm Mon Oct 15 02:23 246/8417 "Undelivered Mail Returned to Sender"
==== 指定メールを開く ====
# 756
==== メール一覧を表示 ====
# h
U754 MAILER-DAEMON@kd-adm Mon Oct 15 01:00 251/8692 "Undelivered Mail Returned to Sender"
U755 MAILER-DAEMON@kd-adm Mon Oct 15 02:23 251/8692 "Undelivered Mail Returned to Sender"
> 756 MAILER-DAEMON@kd-adm Mon Oct 15 02:23 246/8417 "Undelivered Mail Returned to Sender"
==== 範囲指定して削除 ====
# d 750-753
===== メール削除 =====
# ll /var/spool/mail/
合計 0
-rw-rw---- 1 istadmin mail 0 8月 2 19:53 2013 root
-rw-rw---- 1 istpika mail 0 8月 2 19:53 2013 taro
# rm -rf /var/spool/mail/root
===== mail送信 =====
==== CentOS5.x ====
- s:SUBJECT
- :TO
- f:FROM
メール本文入力後、ピリオドで送信
# mail -s "SUBJECT" clown@example.com -- -f FROM@mail.com
mail body
.
EOT
==== CentOS6.x ====
- s:SUBJECT
- r:FROM
- :TO
メール本文入力後、ピリオドで送信
# mail -s "SUBJECT" -r FROM@mail.com clown@example.com
mail body
.
EOT
====== Tips ======
===== cronの実行結果のメールを止める =====
==== crontab ====
# crontab -e
MAILTO=""
*/1 * * * * /usr/local/bin/exec
==== /etc/crontab ====
# vi /etc/crontab
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
#MAILTO=root
MAILTO=""
HOME=/
# For details see man 4 crontabs
# Example of job definition:
# .---------------- minute (0 - 59)
# | .------------- hour (0 - 23)
# | | .---------- day of month (1 - 31)
# | | | .------- month (1 - 12) OR jan,feb,mar,apr ...
# | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# | | | | |
# * * * * * user-name command to be executed
==== /etc/anacrontab ====
# vi /etc/anacrontab
# /etc/anacrontab: configuration file for anacron
# See anacron(8) and anacrontab(5) for details.
SHELL=/bin/sh
PATH=/sbin:/bin:/usr/sbin:/usr/bin
#MAILTO=root
MAILTO=""
# the maximal random delay added to the base delay of the jobs
RANDOM_DELAY=45
# the jobs will be started during the following hours only
START_HOURS_RANGE=3-22
#period in days delay in minutes job-identifier command
1 5 cron.daily nice run-parts /etc/cron.daily
7 25 cron.weekly nice run-parts /etc/cron.weekly
@monthly 45 cron.monthly nice run-parts /etc/cron.monthly
==== /etc/cron.d/0hourly ====
# vi /etc/cron.d/0hourly
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
#MAILTO=root
MAILTO=""
HOME=/
01 * * * * root run-parts /etc/cron.hourly
===== メール送信時にIPv6の警告がでる =====
mailコマンドで送信時に次のような警告が出る。
send-mail: warning: inet_protocols: IPv6 support is disabled: Address family not supported by protocol
send-mail: warning: inet_protocols: configuring for IPv4 support only
postdrop: warning: inet_protocols: IPv6 support is disabled: Address family not supported by protocol
postdrop: warning: inet_protocols: configuring for IPv4 support only
プロトコルはIPv4とIPv6が両方とも対応になっているようなので、設定ファイル(/etc/postfix/main.cf)を開き、ipv4 だけにする。
# vi /etc/postfix/main.cf
#inet_protocols = all
inet_protocols = ipv4
デーモン再起動。
# /etc/init.d/postfix restart