<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>飞扬轻狂&#039;s blog &#187; X shell</title>
	<atom:link href="http://blog.fallseir.com/tag/x-shell/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.fallseir.com</link>
	<description>我心飞扬 我意轻狂</description>
	<lastBuildDate>Thu, 06 May 2010 07:13:50 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
<atom:link rel="hub" href="http://pubsubhubbub.appspot.com"/><atom:link rel="hub" href="http://superfeedr.com/hubbub"/><cloud domain='blog.fallseir.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
		<item>
		<title>HelloWorld Java 1: ShutdownHook &amp; start/stop Script</title>
		<link>http://blog.fallseir.com/2010/03/helloworld-java-1-shutdownhook-startstop-script/</link>
		<comments>http://blog.fallseir.com/2010/03/helloworld-java-1-shutdownhook-startstop-script/#comments</comments>
		<pubDate>Fri, 26 Mar 2010 07:59:16 +0000</pubDate>
		<dc:creator>飞扬轻狂</dc:creator>
				<category><![CDATA[闲言片语]]></category>
		<category><![CDATA[helloworld]]></category>
		<category><![CDATA[X shell]]></category>

		<guid isPermaLink="false">http://blog.fallseir.com/?p=232</guid>
		<description><![CDATA[Java 代码： package test.helloworld.cmd; // by fallseir 2010-03-26 public class ShutdownHook { public static void main(String args[]){ System.out.println("start"); ShutdownHook cmd=new ShutdownHook(); cmd.installShutdownHook(); try{ Thread.sleep(1000*10*10); }catch(InterruptedException e){ e.printStackTrace(); } } private void shutdown(){ System.out.println("shutdown"); } private void installShutdownHook(){ Runtime.getRuntime().addShutdownHook(new Thread(){ public void run(){ shutdown(); } }); } } sh 代码： #!/bin/sh # ----------------------------------------------------------------------------- # fallseir 2010-03-26 [...]]]></description>
			<content:encoded><![CDATA[<p>Java 代码：</p>
<pre>
package test.helloworld.cmd;
// by fallseir 2010-03-26
public class ShutdownHook {
	public static void main(String args[]){
		System.out.println("start");
		ShutdownHook cmd=new ShutdownHook();
		cmd.installShutdownHook();
		try{
			Thread.sleep(1000*10*10);
		}catch(InterruptedException e){
			e.printStackTrace();
		}
	}
	private void shutdown(){
		System.out.println("shutdown");
	}
	private void installShutdownHook(){
		Runtime.getRuntime().addShutdownHook(new Thread(){
			public void run(){
				shutdown();
			}
		});
	}
}
</pre>
<p>sh 代码：</p>
<pre>
#!/bin/sh
# -----------------------------------------------------------------------------
# fallseir 2010-03-26
# Start/Stop Script for the test.helloworld.cmd.ShutdownHook system
# run.sh start|stop|check
#
base="."
lib="$base/lib"
log="$base/log"

app="run"
mainCls="test.helloworld.cmd.ShutdownHook"
pid="$app"".pid"

cp=""
#cp="$cp:$lib/log4j-1.2.13.jar"

cmd="java -cp $cp $mainCls $args"

ARG=$1
if [ "x$ARG" = "x" ] ; then
  ARG="start"
else
  shift
fi

if [ ! -d "$log" ] ; then
  mkdir "$log"
fi

if [ "$ARG" = "start" ] ; then
  AppErr="$log/$app.err"
  AppOut="$log/$app.out"
  # 备份历史日志
  if [ -f "$AppErr" ] ; then
    mv "$AppErr" "$AppErr".`date +%Y%m%d`"."$$
  fi
  if [ -f "$AppOut" ] ; then
    mv "$AppOut" "$AppOut".`date +%Y%m%d`"."$$
  fi
  # 在后台启动应用
  echo "$cmd $@ > $AppOut 2> $AppErr"
  $cmd "$@" > "$AppOut" 2> "$AppOut" &#038;
  # 记录进程ID
  if [ ! -z "$pid" ] ; then
    echo $! > $pid
  fi
# 使用USR2 进行简单通信
#elif [ "$ARG" = "check" ] ; then
#  if [ ! -z "$pid" ]; then
#    echo "check: `cat $pid`"
#    kill -USR2 `cat $pid`
#  else
#    echo "Kill failed: \$pid not set"
#  fi
elif [ "$ARG" = "stop" ] ; then
  # kill 应用进程
  if [ ! -z "$pid" ]; then
    echo "Killing: `cat $pid`"
    kill -15 `cat $pid`
    rm $pid
  else
    echo "Kill failed: \$pid not set"
  fi
fi
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.fallseir.com/2010/03/helloworld-java-1-shutdownhook-startstop-script/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>使用mysqldump进行单表备份</title>
		<link>http://blog.fallseir.com/2008/10/mysqldump_tables/</link>
		<comments>http://blog.fallseir.com/2008/10/mysqldump_tables/#comments</comments>
		<pubDate>Fri, 10 Oct 2008 09:17:39 +0000</pubDate>
		<dc:creator>飞扬轻狂</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[笔记]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[mysqldump]]></category>
		<category><![CDATA[X shell]]></category>
		<category><![CDATA[数据备份]]></category>

		<guid isPermaLink="false">http://blog.fallseir.com/?p=99</guid>
		<description><![CDATA[写了一个shell脚本 对数据库中每个表进行备份 这样可以方便的在表中进行筛选 bak_db_table.sh &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211; # bak_db_table.sh db db_host db_user db_passwd > log.txt # by fallseir at 20081010 if [ $1 ] # 如果没有参数 then echo database $1; else echo 'backup database tables to gzip files sh bak_db_table.sh db [db_host] [db_user] [db_passwd] '; exit; fi # 参数赋值 [ $1 ] &#038;&#038; db=$1 [ $2 ] [...]]]></description>
			<content:encoded><![CDATA[<p>写了一个shell脚本 对数据库中每个表进行备份 这样可以方便的在表中进行筛选</p>
<p>bak_db_table.sh<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</p>
<pre>
# bak_db_table.sh db db_host db_user db_passwd > log.txt
# by fallseir at 20081010

if [ $1 ] # 如果没有参数
then
echo database $1;
else
echo 'backup database tables to gzip files
sh bak_db_table.sh db [db_host] [db_user] [db_passwd]
'; exit;
fi

# 参数赋值
[ $1 ] &#038;&#038; db=$1
[ $2 ] &#038;&#038; dbh=$2
[ $3 ] &#038;&#038; dbu=$3
[ $4 ] &#038;&#038; dbp=$4

# 配置数据库参数
[ $dbh ] &#038;&#038; dbh="-h"$dbh
[ $dbu ] &#038;&#038; dbu="-u"$dbu
[ $dbp ] &#038;&#038; dbp="-p"$dbp

#如果不存在 以db命名的目录 则创建
[ -a $db ] || mkdir $db; echo "mkdir $db"

# 获取数据库中的表列表
echo 'list=(`echo "show tables;"|mysql -h$dbh -u$dbu -p$dbp $db`)'
list=(`echo "show tables;"|mysql $dbh $dbu $dbp $db`)
# 获取表个数
tbcount=$((${#list[@]}-2))
if [ $tbcount= -2 ] # 如果表不存在 或数据库连接失败
then
  echo empty tables in $db or connent failed! ; exit 1;
fi
echo table count: $tbcount

# 对每个表进行备份 并压缩
# 使用gzip -d $file 进行解压
# 使用 mysql $database < $bakfile 进行恢复
for (( i = 1 ; i < ($tbcount+1) ; i ++ ))
do
  table=${list[$i]}
  echo back table $table
  mysqldump $dbh $dbu $dbp $db $table | gzip -c > $db/177.6.db.$db.$table.gz
# $? 前一命令的返回值, 0 为成功 1为失败 但mysqldump没有遵守这个约定
  echo back table $table $?
  sleep 10
done
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.fallseir.com/2008/10/mysqldump_tables/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
