Showing posts with label unix. Show all posts
Showing posts with label unix. Show all posts

Sunday, June 21, 2009

神奇的 ssh 端口转发

ssh 端口转发。

作用:
1 不同的内网之间互联;
    假设有 2 台在不同网段之间的机器需要连接,那么在 A 网段用一台机器 ssh 到公网 abc.com 上,绑定一个 abc.com 的端口 x 到 A 网的任意 ip:port,
    然后在任意地方访问 abc.com:x 就等于访问之前绑定的 A 网段的 ip:port,这样,几乎任何服务都可以传递过来,包括远程连接,打印机等

2 发布本地服务到外网;
   跟上面类似,只要将远程主机的端口绑定到本地机器即可。

3 欺骗程序(比如 RDC 的 mac 版本不能指定端口,如果服务器设置了非默认端口,则可以通过 ssh 在本机转发一下);
   这个纯粹的是做端口转发,本机就可以搞定。

4 用作代理服务器。
   用到 -D 参数,配合 pac 文件很好用。



参考:
理解这个得到 agentzh 的大力帮助。
这篇文章也比较好。

Friday, May 15, 2009

用 Mac 拍照,连续的照片(zh-CN)

此为译稿,原始来源: http://www.carbonsilk.com/development/timelapse-video-mac/
更多类似应用: http://lancewig.com/2008/08/06/tutorial-poor-mans-macbook-webcam/

Me on a time lapse from James Broad on Vimeo.

你可以在 Mac 上跟随以下步骤来创建上面类似的视频。

步骤 1

下载并安装一个命令行下拍照的工具:isightcapture http://www.macupdate.com/info.php/id/18598 (原始地址好像下不到,提供另一个地址 http://blog.chlean.net/misc/isightcapture1_1.dmg)

打开这个 dmg 并复制 isightcapture 到/usr/bin/

sudo cp /Volumes/isightcapture1_1/isightcapture /usr/bin/

步骤 2

创建一个目录来保存我们的视频和图片,假设为 ~/captures/ 。

cd ~
mkdir captures
mkdir captures/scripts
mkdir captures/series

步骤 3

创建一个脚本,用于捕捉并保存图片:

cd ~/captures/scripts
vim captureme.sh

输入以下内容:

CAPTURE="isightcapture -t jpg"
cd $HOME/captures
D1=`date +%y%m%d/%H`
D2=`date +%y%m%d.%H%M%S`

# If the date directory does not exist, create it
if [ ! -d $D1 ] ; then
mkdir -p $D1
fi

# Construct the filename and path and capture a pic
FN="$D1/$D2.jpg"
$CAPTURE $FN

# Make a symlinked image of the last photo taken
if [ -h 'last.jpg' ] ; then
rm last.jpg
fi
ln -s $FN last.jpg

保存并退出(:wq)

给这个脚本添加执行权限

chmod a+x captureme.sh

步骤 4

把这个脚本变成自动运行的:

crontab -e

然后这么写:

* * * * * ~/captures/scripts/captureme.sh

保存,退出(:wq)

步骤 5

做到以上步骤,你的电脑已经每分钟拍一张照片,并且保存到 ~/captures/年月日 目录下了。 下面是把那些图片连起来做成视频,你可以用自己的方式来乐(因为装这个 ffmpeg 很麻烦)。 我想后面的属于高级主题,就不翻译了,大家自己搞定吧 :)。

Install a utility to convert a series of images to a movie. We will be using ffmpeg cd /tmp/ svn checkout svn://svn.ffmpeg.org/ffmpeg/trunk ffmpeg cd ffmpeg

We need to install ffmpeg to our machine, this process is going to basically compile the code. Hopefully nothing will go wrong for you here, if it does though, take a look on http://stephenjungels.com/jungels.net/articles/ffmpeg-howto.html

./configure --enable-shared --disable-mmx sudo make sudo make install

Step 5

Make script to grab photos and run them through ffmpeg mkdir ~/captures/videos/ cd ~/captures/scripts vi make_complete_sequence.sh

Write the contents to the file:

COUNTER=0; rm ~/captures/series/*.jpg for i in `find ~/captures -name '*.jpg'` ; do #Write the filename to be friendly with ffmpeg's odd filename input FILENAME=`printf '%03d.jpg' $COUNTER` cp $i ~/captures/series/$FILENAME let COUNTER=COUNTER+1; done nice ffmpeg -r 20 -b 1800  -i ~/captures/series/%3d.jpg ~/captures/videos/timelapse_complete.mp4 

Again setting the permissions to be able to run the script and then run it to generate a movie based on the images taken so far.

chmod a+x make_complete_sequence.sh ./make_complete_sequence.sh

Step 6

View the finished result Browse in finder to your home directory > captures/videos and watch the result.