1. 低成本和高性能MySQL云架构探索2. WebApp开放平台的系统架构设计-腾讯于涛3. 云固基础
智算未来——构建完美基础架构4. 微软私有体验云之旅5. 360 Cassandra实践分享6.
【linux】 【安全】 【架构】 【性能优化】 【mysql】 【高可用】 …
如何避免shell脚本被同时运行多次
http://astellar.com/2012/10/backups-running-at-the-same-time/
http://www.davidpashley.com/articles/writing-robust-shell-scripts.html
比如说有一个周期性(cron)备份mysql的脚本,或者rsync脚本,
如果出现意外,运行时间过长,
很有可能下一个备份周期已经开始了,当前周期的脚本却还没有运行完,
显然我们都不愿意看到这样的情况发生。
其实只要对脚本自身做一些改动,就可以避免它被重复运行。
#!/bin/bash
LOCK_NAME="/tmp/my.lock"
if [[ -e $LOCK_NAME ]] ; then
echo "re-entry, exiting"
exit 1
fi
### Placing lock file
touch $LOCK_NAME
echo -n "Started..."
### 开始正常流程
### 正常流程结束
### Removing lock
rm -f $LOCK_NAME
echo "Done."
|
当脚本开始运行时, …
[获取更多]使用xargs在shell中多进程并发运行程序
从这里看来的:
http://www.xaprb.com/blog/2012/10/12/implementing-sql-with-unix-utilities/
http://www.xaprb.com/blog/2009/05/01/an-easy-way-to-run-many-tasks-in-parallel/
太帅了,不得不转载。
[root@H209 tmp]# seq 10 20 | xargs -n 1 -P 5 sleep 按ctrl+z [1]+ Stopped seq 10 20 | xargs -n 1 -P 5 sleep [root@H209 tmp]# bg [1]+ seq 10 20 | xargs -n 1 -P 5 sleep & [root@H209 tmp]# [root@H209 tmp]# ps aux|grep sleep root 7327 0.0 0.0 4312 508 pts/1 S 13:56 0:00 xargs -n 1 -P 5 sleep root 7328 0.0 0.0 4052 476 pts/1 S 13:56 0:00 sleep 10 root 7329 0.0 0.0 4052 476 pts/1 S 13:56 0:00 sleep 11 root 7330 0.0 0.0 4052 472 pts/1 S 13:56 0:00 sleep 12 root 7331 0.0 0.0 4052 476 pts/1 S 13:56 0:00 sleep 13 root 7332 0.0 0.0 … |