Shell: March 2010 Archives

Pure-FTP uploadscript

user-pic
Vote 0 Votes

Pure-FTPd 在 configure 時加 --with-uploadscript 參數可以 enable uploadscript 的功能,
就是上傳檔案後可以呼叫外部程式或 script.

pure-ftpd 啟動參數加 -o, 有設定檔(pure-ftpd.conf)的系統就設 CallUploadScript yes

必需先啟動 pure-ftpd 後再啟動 pure-uploadscript, 不然無法運作.
pure-uploadscript -Br /usr/local/bin/uploadscript.sh

上傳檔案的絕對路徑會帶到第一個參數 $1
其他可用的環境變數如下:
$UPLOAD_SIZE : the size of the file, in bytes.
$UPLOAD_PERMS : the permissions, as an octal value.
$UPLOAD_UID : the uid of the owner.
$UPLOAD_GID : the group the file belongs to.
$UPLOAD_USER : the name of the owner.
$UPLOAD_GROUP : the group name the file belongs to.
$UPLOAD_VUSER : the full user name, or the virtual user name. (127 chars max)

uploadscript 範例, 上傳的檔會移到 /tmp/日期 目錄下, 並記錄一筆 Log 到 /var/log/uploadscript.log
#!/bin/sh
DIR=/tmp/`date +%Y%m%d`
[ -d $DIR ] || mkdir $DIR
mv "$1" $DIR
echo `date` size $UPLOAD_SIZE by $UPLOAD_USER >> /var/log/uploadscript.log

Pure-FTPd 1.0.29 released on 2010-03-15, 最近改版還滿勤的.

另一套 ProFTPD 在 1.3.3 版(2010-02-24 Released)也加入了 mod_exec,
比起 Pure-FTPd uploadscript 更為強大, 各種 FTP 的 event 都能呼叫外部程式或 script.

ssh-copy-id

user-pic
Vote 0 Votes

要用 SSH public key authentication 通常會這樣做
ssh-keygen
scp ~/.ssh/id_rsa.pub remote-host
ssh remote-machine
cat id_rsa.pub >> ~/.ssh/authorized_keys

2-4 步驟可以用一行指令取代
ssh-copy-id -i ~/.ssh/id_rsa.pub remote-host

ref. 10 個最酷的 Linux 單行命令
Top Ten One-Liners from CommandLineFu Explained
CommandLineFu All commands sorted by votes

SADDR=台中市中區中山路1號
DADDR=台中市西屯區文華路100號
w3m -dump "http://maps.google.com.tw/maps?saddr=$SADDR&daddr=$DADDR" | egrep "公里.*大約"

輸出結果:
8.3 公里 - 大約 24 分鐘

About this Archive

This page is an archive of entries in the Shell category from March 2010.

Shell: October 2009 is the previous archive.

Shell: May 2010 is the next archive.

Find recent content on the main index or look in the archives to find all content.

Monthly Archives