pepoとネットワークを語ろう

40年前からこれまでとこれからのネットワークを語る

rootのmail fowardができない-3

2009-03-18 12:20:28 | Linux
ふと疑問からCron以外をmboxへ落とさずにmailのspoolへ残したい
場合
[pepo1@~]$ cat .procmailrc
#$HOME/.procmailrc
VERBOSE=on
LOGFILE=$HOME/procmail.log

# Is it coming from Cron If yes, DELETE IT!!!
# Other coming in mbox
:0
* ^Subject.*Cron
/dev/null

# Cron以外の全てmboxへ
#:0
#* ! ^Subject: Cron
#mbox
とコメントアウトしてテスト
[root@~]# mail root
Subject: Test no mbox
Test no mbox
.
Cc:
[root@~]#
きちんとspoolされとる。。当たり前か
[pepo1@~]$ mail
Mail version 8.1 6/6/93. Type ? for help.
"/var/spool/mail/pepo1": 1 message 1 new
>N 1 root@www.pepolinux.l Wed Mar 18 12:26 21/841 "Test no mbox"
& 1
Message 1:
From root@www.pepolinux.local Wed Mar 18 12:26:09 2009
X-Original-To: root@www.pepolinux.local
Delivered-To: pepo1@pepolinux.local
Delivered-To: root@www.pepolinux.local
Date: Wed, 18 Mar 2009 12:26:09 +0900
From: root <root@www.pepolinux.local>
To: root@www.pepolinux.local
Subject: Test no mbox

Test no mbox

& q
Saved 1 message in mbox
[pepo1@~]$
[pepo1@~]$ cat procmail.log
procmail: Match on "^Subject.*Cron"
procmail: Assigning "LASTFOLDER=/dev/null"
procmail: Opening "/dev/null"
procmail: Notified comsat: "pepo1@0:/dev/null"
From root@www.pepolinux.local Wed Mar 18 12:25:01 2009
Subject: Cron <root@www> /usr/bin/webalizer -c /etc/webalizer.conf
Folder: /dev/null 1451
procmail: No match on "^Subject.*Cron"
procmail: Bypassed locking "/var/mail/pepo1.lock"
procmail: Assigning "LASTFOLDER=/var/mail/pepo1"
procmail: Opening "/var/mail/pepo1"
procmail: Acquiring kernel-lock
procmail: Notified comsat: "pepo1@0:/var/mail/pepo1"
From root@www.pepolinux.local Wed Mar 18 12:26:09 2009
Subject: Test no mbox
Folder: /var/mail/pepo1

rootのmail fowardができない-2

2009-03-18 11:22:34 | Linux

検索エンジンにお願いしてもなかなか結果が見つからず、結果からするとroot自身はでは、どうにもならない事が分かり、別ユーザへ転送してからレシピ
なんか何年も前に同じような事を調べた気がするが今回でブログとけば、これて常識だったりして

#$HOME/.forward
#rootは.procmailrcが使えないので.forwardで別ユーザへ転送してから.procmailrcと連携する
#.procmailrcを設定したら、nobody に転送しようとしてmaillogに下記メッセージを残す
#procmail: Couldn't create "/var/mail/nobody"
#rootは下記設定をしても動作しない。root以外の設定で.forwardに設定する
#"|IFS=' ' && exec /usr/bin/procmail -f- || exit 75 #pepo1"
#rootはpepo1へ転送してpepo1のhomeディレクトリに.forwardと.procmailrcを設定する
#pepo1

pepo1
[root@~]#
とユーザpepo1へ転送設定を行い、テスト
[root@~]# mail root
Subject: Test Cron
test
test
.
Cc:
[root@~]# mail root
Subject: Test
test
tes
.
Cc:
[root@~]#
下記ログから正しく転送レシピがされていることが分かると思う
[pepo1@~]$ cat .forward
#$HOME/.forward
"|IFS=' ' && exec /usr/bin/procmail -f- || exit 75 #pepo1"
[pepo1@~]$ cat .procmailrc
#$HOME/.procmailrc
#rootは.forwardが使えないので別ユーザへ転送してから.procmailrcと連携すること
#設定しても、nobody に転送しようとしてmaillogに下記メッセージを残す
#procmail: Couldn't create "/var/mail/nobody"
VERBOSE=on
LOGFILE=$HOME/procmail.log

# Is it coming from Cron If yes, DELETE IT!!!
# Other coming in mbox
:0
* ^Subject.*Cron
/dev/null

# Cron以外の全てmboxへ
:0
* ! ^Subject: Cron
mbox

#:0
#* ^.*[Ff]rom: root@
#/dev/null
pepo1@~]$ cat procmail.log
procmail: Match on "^Subject.*Cron"
procmail: Assigning "LASTFOLDER=/dev/null"
procmail: Opening "/dev/null"
procmail: Notified comsat: "pepo1@0:/dev/null"
From root@www.pepolinux.local Wed Mar 18 12:00:03 2009
Subject: Cron /usr/bin/webalizer -c /etc/webalizer.conf
Folder: /dev/null 1452
procmail: Match on "^Subject.*Cron"
procmail: Assigning "LASTFOLDER=/dev/null"
procmail: Opening "/dev/null"
procmail: Notified comsat: "pepo1@0:/dev/null"
From root@www.pepolinux.local Wed Mar 18 12:00:03 2009
Subject: Cron /usr/sbin/ntpdate gpsntp.miz.nao.ac.jp
Folder: /dev/null 1160
procmail: Match on "^Subject.*Cron"
procmail: Assigning "LASTFOLDER=/dev/null"
procmail: Opening "/dev/null"
procmail: Notified comsat: "pepo1@0:/dev/null"
From root@www.pepolinux.local Wed Mar 18 12:00:16 2009
Subject: Test Cron
Folder: /dev/null 834
procmail: No match on "^Subject.*Cron"
procmail: Match on ! "^Subject: Cron"
procmail: Assigning "LASTFOLDER=mbox"
procmail: Opening "mbox"
procmail: Acquiring kernel-lock
procmail: Notified comsat: "pepo1@0:/home/pepo1/mbox"
From root@www.pepolinux.local Wed Mar 18 12:00:31 2009
Subject: Test
Folder: mbox 829
[pepo1@~]$
[pepo1@~]$ cat mbox
From root@www.pepolinux.local Wed Mar 18 12:00:31 2009
Return-Path:
X-Original-To: root@www.pepolinux.local
Delivered-To: pepo1@pepolinux.local
Received: by www.pepolinux.local (Postfix)
id 463BB51E9A; Wed, 18 Mar 2009 12:00:31 +0900 (JST)
Delivered-To: root@www.pepolinux.local
Received: from www.pepolinux.local (localhost [127.0.0.1])
by www.pepolinux.local (Postfix) with ESMTP id 3AE5A51E8D
for ; Wed, 18 Mar 2009 12:00:31 +0900 (JST)
Received: (from root@localhost)
by www.pepolinux.local (8.13.8/8.13.8/Submit) id n2I30VXh030369
for root; Wed, 18 Mar 2009 12:00:31 +0900
Date: Wed, 18 Mar 2009 12:00:31 +0900
From: root
Message-Id: <200903180300.n2I30VXh030369@www.pepolinux.local>
To: root@www.pepolinux.local
Subject: Test

test
tes

[pepo1@~]$
最後にメールログを
[root@~]# tail -n 10 /var/log/maillog
Mar 18 12:15:01 (none) postfix/cleanup[538]: C607C53BA6: message-id=<200903180315.n2I3F1Bp000524@www.pepolinux.local>
Mar 18 12:15:01 (none) postfix/qmgr[15366]: C607C53BA6: from=, size=1171, nrcpt=1 (queue active)
Mar 18 12:15:01 (none) sendmail[524]: n2I3F1Bp000524: to=root, ctladdr=root (0/0), delay=00:00:00, xdelay=00:00:00, mailer=relay, pri=30683, relay=[127.0.0.1] [127.0.0.1], dsn=2.0.0, stat=Sent (Ok: queued as C607C53BA6)
Mar 18 12:15:01 (none) postfix/smtpd[527]: disconnect from localhost[127.0.0.1]
Mar 18 12:15:01 (none) postfix/cleanup[538]: DB8E153BCA: message-id=<200903180315.n2I3F1Bp000524@www.pepolinux.local>
Mar 18 12:15:01 (none) postfix/qmgr[15366]: DB8E153BCA: from=, size=1310, nrcpt=1 (queue active)
Mar 18 12:15:01 (none) postfix/local[545]: C607C53BA6: to=, relay=local, delay=0.15, delays=0.08/0.04/0/0.03, dsn=2.0.0, status=sent (forwarded as DB8E153BCA)
Mar 18 12:15:01 (none) postfix/qmgr[15366]: C607C53BA6: removed
Mar 18 12:15:01 (none) postfix/local[550]: DB8E153BCA: to=, orig_to=, relay=local, delay=0.04, delays=0/0.02/0/0.02, dsn=2.0.0, status=sent (delivered to command: IFS=' ' && exec /usr/bin/procmail -f- || exit 75 #pepo1)
Mar 18 12:15:01 (none) postfix/qmgr[15366]: DB8E153BCA: removed
[root@~]#


rootのmail fowardができない

2009-03-18 10:59:56 | Linux
[root@~]# mail
Mail version 8.1 6/6/93. Type ? for help.
"/var/spool/mail/root": 120 messages 120 unread
>U 1 root@www.pepolinux.l Mon Mar 16 12:00 26/1036 "Cron <root@www> /usr/"
U 2 root@www.pepolinux.l Mon Mar 16 12:00 31/1190 "Cron <root@www> /usr/"
U 3 root@www.pepolinux.l Mon Mar 16 12:00 45/3016 "Cron <root@www> /etc/"
U 4 root@www.pepolinux.l Mon Mar 16 12:05 31/1190 "Cron <root@www> /usr/"
U 5 root@www.pepolinux.l Mon Mar 16 12:05 30/1411 "Cron <root@www> /etc/"
U 6 root@www.pepolinux.l Mon Mar 16 12:10 31/1190 "Cron <root@www> /usr/"
U 7 root@www.pepolinux.l Mon Mar 16 12:15 31/1190 "Cron <root@www> /usr/"
U 8 root@www.pepolinux.l Mon Mar 16 12:20 31/1190 "Cron <root@www> /usr/"
U 9 root@www.pepolinux.l Mon Mar 16 12:25 31/1190 "Cron <root@www> /usr/"
U 10 root@www.pepolinux.l Mon Mar 16 12:30 31/1190 "Cron <root@www> /usr/"
&q
Held 120 messages in /var/spool/mail/root

Cronからのメールを転送しようと考え
[root@~]# cat .forward
#$HOME/.forward
"|IFS=' ' && exec /usr/bin/procmail -f- || exit 75 #root"
[root@~]# cat .procmailrc
#$HOME/.procmailrc
VERBOSE=on
LOGFILE=$HOME/procmail.log
# Is it coming from Cron If yes, DELETE IT!!!
# Other coming in mbox
:0
* ^Subject.*Cron
/dev/null

#Cron以外の全てmboxへ
:0
* ! ^Subject: Cron
mbox

実際に運用してみると一向にCronからのメールは減りません、メールログを確認するとprocmailが"/var/mail/nobody"にアクセス権が無いようなメッセージが
[root@~]# tail -n 5 /var/log/maillog
Mar 18 11:15:02 (none) postfix/qmgr[15366]: 2B0944BE37: from=<>, size=3052, nrcpt=1 (queue active)
Mar 18 11:15:02 (none) postfix/bounce[21805]: ED3C04BDB7: sender non-delivery notification: 2B0944BE37
Mar 18 11:15:02 (none) postfix/qmgr[15366]: ED3C04BDB7: removed
Mar 18 11:15:02 (none) postfix/local[21794]: 2B0944BE37: to=<root@www.pepolinux.local>, relay=local, delay=0.01, delays=0/0/0/0.01, dsn=5.2.0, status=bounced (can't create user output file. Command output: procmail: Couldn't create "/var/mail/nobody" )
Mar 18 11:15:02 (none) postfix/qmgr[15366]: 2B0944BE37: removed



PHP Secure Shell2 これはいい!

2009-03-08 14:09:01 | Linux
php-develがインストールされてなければ
[root@~]# yum install php-devel
libssh2をwget
[root@~]# wget http://downloads.sourceforge.net/libssh2/libssh2-1.0.tar.gz?use_mirror=jaist
[root@~]# tar xvfz libssh2-1.0.tar.gz
解凍 && make && make install
[root@~]# cd libssh2-1.0
[root@libssh2-1.0]# ./configure --prefix=/usr
[root@libssh2-1.0]# make && make install
[root@~]# cd
ssh2をインストール
[root@~]# pecl install ssh2-0.11.0
WARNING: channel "pear.php.net" has updated its protocols, use "channel-update pear.php.net" to update
downloading ssh2-0.11.0.tgz ...
Starting to download ssh2-0.11.0.tgz (22,884 bytes)
........done: 22,884 bytes
5 source files, building
running: phpize
Configuring for:
PHP Api Version: 20041225
Zend Module Api No: 20050922
Zend Extension Api No: 220051025
libssh2 prefix? [/usr] :
install ok: channel://pear.php.net/ssh2-0.11.0
/etc/php.iniへextension=ssh2.so追加
[root@~]# vi /etc/php.ini
extension=ssh2.so
info.phpでRegistered PHP Streams の項を確認すると下記のモジュールが追加されているはずこれでPHP Secure Shell2が使えるようになった
ssh2.shell, ssh2.exec, ssh2.tunnel, ssh2.scp, ssh2.sftp




X-Windowsを使わないが文字化けはいや

2009-03-04 15:27:31 | Linux
ログインプロンプトからログイン後LANG=Cを忘れた時に文字化けの経験が無いだろうか?
[root@~]# cat date
2009?? 3?? 16?? ?? ?? ?? 15:12:32 JST2009?? 3?? 16?? ?? ?? ?? 15:12:32 JST
/etc/profileをこんな風にするとOK
[root@~]# cat /etc/profile
#!/bin/bash
export USER=`whoami`
export MAIL="/var/spool/mail/$USER"
export PATH=/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/etc
TERM=linux
if [ ! $USER = "root" ] ;then
HISTFILE=/home/$USER/.bash_history
elif [ $USER = "root" ] ;then
HISTFILE=/root/.bash_history
fi

HISTSIZE=500
#which, LANG C or ja_JP.utf8
TTY=` set| grep pts| wc -l`
if [ $TTY == "0" ];then
LANG=C
else
LANG=ja_JP.utf8
fi
PS1="[u@W]$ "
export HISTFILE
export HISTFILESIZE
export HISTSIZE
export PS1
export LANG
clear
alias ll='ls -l'
stty sane
stty erase ^?
#if [ -f /etc/WELCOME ]; then
#cat /etc/WELCOME
#fi