2012年10月22日 星期一

postfix 查看、刪除佇列郵件

參考官方說明:http://www.postfix.org/postqueue.1.html

POSTQUEUE(1)                                                      POSTQUEUE(1)

NAME
       postqueue - Postfix queue control

SYNOPSIS
       postqueue [-v] [-c config_dir] -f
       postqueue [-v] [-c config_dir] -i queue_id
       postqueue [-v] [-c config_dir] -p
       postqueue [-v] [-c config_dir] -s site

--以下略--


官方上面只有這些參數,但是網路上一堆轉貼都是說

看被Queue的信:
postqueue -q
強迫將Queue信寄出:
postqueue -f
刪除所有被Queue的信:
postsuper -d ALL
刪除某封Queue的信:
postsuper -d queue_id
刪除所有正在 deferred 佇列中的郵件 ( 刪除曾經發送失敗的信 ):
postsuper -d ALL deferred
是版本的問題嗎?

不管他...

從 postfix 官方說明:http://www.postfix.org/qmgr.8.html
可查到佇列相關資訊。

另外也有人整理好相關資訊:

※ Mail Queue 所在的目錄 
/var/spool/mqueue
/var/spool/postfix -- 底下列出 postfix 的子目錄

 》active
  目前正在準備發送的信件。(在 message id 後會多加一個 * 號)
Messages  that  the  queue  manager  has opened for delivery. Only a  limited  number  of  messages  is allowed  to  enter  the  active queue (leaky bucket strategy, for a fixed delivery rate).

 》bounce
  每一位收件者的傳送狀態,並記載為何會被退信
Per-recipient status information about why mail  is bounced.    These   files  are  maintained  by  the bounce(8) daemon.

 》corrupt
  信件損毀導致無法傳送的信件
Unreadable  or  damaged  queue files are moved here for inspection.
 》defer
   暫時無法被傳送的信件,並記載為何會被延遲傳送。這種情形最常發生在你的 Mail Server 被列入灰名單(GrayList)的時候,你會看到訊息為「 Your access to this mail system has been rejected due to the sending MTA's poor reputation. If you believe that this failure is in error, please contact the intended recipient via alternate means.」
Per-recipient status information about why mail  is delayed. These files are maintained by the defer(8) daemon.

 》deferred
  無法被傳送的信件會放置在此目錄,但 Mail Server 還是會嘗試幫你繼續送,只是必須等 Backoff time。
Mail that could not be  delivered  upon  the  first attempt.  The  queue manager implements exponential backoff  by  doubling  the  time  between  delivery attempts.

 》hold
  被暫時停止發送的信件,如要發送出去,需要由手動(在 message id 後會多加一個 ! 號)
Messages that are kept  "on  hold"  are  kept  here until someone sets them free.

 》incoming
  從外部或本地寄送到本機的信件。
Inbound mail from the network, or mail picked up by the local pickup(8) daemon from the maildrop directory.
 知道這些就好辦了,直接到相對應的資料夾把信刪掉即可。


參考:Postfix Mail Queue - 一些簡單的管理指令





2012年10月18日 星期四

FreeBSD 帳號密碼移轉至 linux


FreeBSD的帳號密碼及其他資訊都存在master.passwd,Linux則分別存在passwd及shadow中。
master.passwd@FreeBSD
帳號:密碼:UID:GID:Login Class:Change:Expire:Full Name:家目錄:Login SHELL
  • Login Class:幾乎沒在用了,通常是空的
  • Change:強迫使用者改密碼的時間週期, 0 表示不設定
  • Expire:使用者帳號的使用期限, 0 表示不設定
passwd@Linux
帳號:密碼:UID:GID:Full Name:家目錄:Login SHELL
FreeBSD比Linux多了三個欄位
所以我們將那三個欄位捨棄,並把密碼那欄設為x,因為Linux的密碼是存在shadow
cat master.passwd.bsd | awk -F":" '$3>=1002&&$3<=60000{printf"%s:x:%s:%s:%s:%s:%s\n",$1,$3,$4,$8,$9,$10}' > passwd.linux


shadow@Linux
帳號:密碼:3:4:5:6:7:8:9
  • 3.last password change
  • 4.days until change allowed
  • 5.days before change required
  • 6.days warning for expiration
  • 7.days before account inactive
  • 8.date when account expires
  • 9.reserved for future use
接著處理shadow
cat master.passwd.bsd | awk -F":" '$3>=1002&&$3<=60000{printf "%s:%s:13367:0:99999:7:::\n",$1,$2 }' > shadow.linux

再來處理group
cat group.bsd | awk -F":" '$3 >=1002&&$3<=60000{printf "%s::%s:%s\n",$1,$3,$4 }' > group.linux

接著把他們附加到原本的檔案後面
cat shadow.linux >> /etc/shadow
cat passwd.linux >> /etc/passwd
cat group.linux >> /etc/group



home、mail的移轉只需要用tar將資料夾打包即可。

如果不移轉home的資料,但是需要建立user home,寫迴圈來建立。
cd /tmp
vim create_user_home.sh
#!/usr/bin/ksh
for users in `awk -F: '{print $1}' passwd.linux`
do
mkdir /home/$users
chown $users:
$users /home/$users
chmod 700
done
執行sh
./create_user_home.sh




註:$3 >=1002  的部份是uid,需按照系統預設起始值修改


參考:
http://mail.lsps.tp.edu.tw/~gsyan/freebsd2001/Linux2FreeBSD.html
[轉錄] FreeBSD帳號密碼轉移至Linux

2012年10月8日 星期一

ssh斷線後,利用screen套件恢復被中斷的作業


參考來源:

使用 GNU Screen 回復被中斷的遠端存取作業階段
SSH 斷線了怎麼辦?沒關係,還有 Screen 幫你保留! 


套件:
screen

使用:

#screen 開啟一個新的作業階段,如果連線中斷,此作業階段依舊會被保留住。

檢視工作階段列表:
$ screen -ls
There are screens on:
        13454.pts-2.mail        (Attached)
        13670.pts-4.mail        (Detached)
2 Sockets in /var/run/screen/S-zongyan..

其中,13670.pts-4.mail        (Detached)代表中斷的作業階段。
 復原作業階段:
#screen -r [作業階段識別號]
例如:
#screen -r 13670.pts-4.mail
切換到Attached的作業階段:
#screen -d -r [作業階段識別號]
例如:
#screen -d -r 13454.pts-2.mail
離開作業階段方式:
#exit