crontab实现每秒执行
crontab:
#!/bin/bash step=$ #每多少秒执行一次 for (( i = ; i < ; i++ )); do
date +%Y%m%d' '%H:%M:%S >> s.log
curl https://car.etaiping.com:6004/ecms2/portal/gwzt/carType &> s.log
echo >> s.log
sleep $step
done
log backup:
#!/bin/bash
#author:xiluhua
#since: #####################################################################
# $:the frequency to do log backup
# $:only if the number of log files reach v_count,log files will be backuped
# $:target directory that needs to do log backup
# $:the directory to put bakuped logs
##################################################################### v_step=$
v_count=$
v_targDir=$
v_histDir=$ if [ -z $v_targDir ]
then
echo "exception: argu 'v_targDir' is empty!"
exit
fi if [ -d $v_targDir ]
then
# do nothing
echo > /dev/null
else
echo "exception: argu 'v_targDir' is not exist!"
exit
fi if [ -z $v_histDir ]
then
echo "exception: argu 'v_histDir' is empty!"
exit
fi if [ -d $v_histDir ]
then
# this is the key step to make the .gz file without directory
cd $v_histDir
else
echo "exception: argu 'v_histDir' is not exist!"
exit
fi if [ -z $v_step ]
then
echo "v_step is empty!"
exit
fi if [ -z $v_count ]
then
echo "exception: argu 'v_count' is empty!"
exit
fi let isProcExist=
# recycle endlessly
while [ "" = "" ]
do
# if same job process already exists,sleep sometime
while [ "" = "" ]
do
if [ $isProcExist -gt ]
then
sleep $v_step
else
break
fi
done let isProcExist= files=$(find $v_targDir -name "*.log")
count=$(ls $files | wc -l) #echo "count:"$count
#echo "v_count:"$v_count if [ $count -ge $v_count ]
then
dir=$(date +%Y%m%d'_'%H%M%S)
# give the value to bakDir
bakDir=$dir mkdir $bakDir
mv $files $bakDir
#echo $bakDir'.tar.gz'
tar -Pczf $bakDir'.tar.gz' $bakDir if [ $bakDir = "/" ]
then
clear
else
rm -r $bakDir
fi
fi
sleep $v_step let isProcExist=
done
autoCreateFile:
#!/bin/bash
#author:xiluhua
#since: v_step=$
if [ -z $v_step ]
then
echo "exception: argu 'v_step' is empty!"
exit
fi cd ~/auto for (( i = ; i < ; i=(i+step) )); do
file1=$(date +%Y%m%d'_'%H%M%S)'_1.log'
file2=$(date +%Y%m%d'_'%H%M%S)'_2.log'
file3=$(date +%Y%m%d'_'%H%M%S)'_3.log' touch $file1 $file2 $file3
sleep $v_step
done
batchRename:
#!/bin/bash
#author:xiluhua
#since:
#####################################################################
# $:the dir to do batch file rename
# $:name before rename
# $:name after rename
##################################################################### dir=$
targ=$
repl=$ #check arguments is not empty and valid
if [ -z $dir ]
then
echo "exception: argu 'dir' is empty!"
exit
fi if [ $dir = "/" ]
then
echo "exception: argu 'dir' is invalid!"
exit
fi if [ -d $dir ]
then
cd $dir
else
echo "exception: argu 'dir' is not exist!"
exit
fi if [ -z $targ ]
then
echo "exception: argu 'targ' is empty!"
exit
fi if [ -z $repl ]
then
echo "exception: argu repl is empty!"
exit
fi # begin the main business
for i in $(ls *."$targ");do
# echo $i
tmp=${i/"$targ"/"$repl"}
# echo $tmp
mv -f $i $tmp
done
crontab实现每秒执行的更多相关文章
- Linux crontab 实现每秒执行
Linux crontab 实现每秒执行 linux crontab 命令,最小的执行时间是一分钟.如需要在小于一分钟内重复执行,可以有两个方法实现. 1.使用延时来实现每N秒执行 创建一个php做执 ...
- linux crontab 实现每秒执行(转)
linux crontab 命令,最小的执行时间是一分钟.如需要在小于一分钟内重复执行,可以有两个方法实现. 1.使用延时来实现每N秒执行 创建一个php做执行动作,非常简单,就是把当前时间写入log ...
- linux中crontab实现以秒执行任务
用crontab+sleep实现以秒执行任务 crontab -e * * * * * /bin/date >>/tmp/date.txt * * * * * sleep 10s; /bi ...
- 【Linux】 crontab 实现每秒执行
linux crontab 命令,最小的执行时间是一分钟, 如果要在小于一分钟执行.就要换个方法来实现 1 crontab 的延时: 原理:通过延时方法 sleep N 来实现每N秒执行. cr ...
- linux crontab 实现每秒执行的实例
linux crontab 命令,最小的执行时间是一分钟.如需要在小于一分钟内重复执行,可以有两个方法实现. 1.使用延时来实现每N秒执行 原理:通过延时方法 sleep N 来实现每N秒执行. 创 ...
- crontab每秒执行URL接口
首先crontab -e打开进行编辑 添加以下代码(默认为每秒执行一次脚本crontab.sh): * * * * * /bin/sh /var/www/aa/crontab.sh 下面是/var/w ...
- 如何让linux定时任务crontab按秒执行
如何让linux定时任务crontab按秒执行? linux定时任务crontab最小执行时间单位为分钟如果想以秒为单位执行,应该如何设置呢?思路 正常情况是在crontab中直接定义要执行的任务,现 ...
- 每10秒执行定时任务-crontab
* * * * * /data/crontab.sh * * * * * sleep 10; /data/crontab.sh * * * * * sleep 20; /data/crontab.sh ...
- [日常] crontab的秒执行和串行化和多进程实现
1. crontab的最低运行频率是,按照每分钟执行一次,通过在脚本中简单实现按秒级别运行 比如这条cron规则 , 每分钟执行一次脚本 * * * * * php /var/www/html/tes ...
随机推荐
- php Memcache
<?php $mem = new Memcache();//实例化一个对象 $mem->connect("localhost",11211);//连接memcache服 ...
- Linux 中的零拷贝技术,第 1 部分
概述 本系列由两篇文章组成,介绍了当前用于 Linux 操作系统上的几种零拷贝技术,简单描述了各种零拷贝技术的实现,以及它们的特点和适用场景.本文是本系列文章的第一部分,主要是介绍一些零拷贝技术的相关 ...
- [转]如何在Windows下使用WebMatrix+IIS开发PHP程序
原文: http://www.cnblogs.com/lucienbao/p/webmatrix_php.html
- 使用NSURLSession请求需要AD认证的HTTPS服务器
关键代码:使用后台下载PDF文件 - (void)startDownloadPDF{ NSURLSession *session = [self session]; NSString *downloa ...
- loadview 方法调用
从官方文档看 不应该直接调用此方法,当控制器当前的view为空的时候,这个方法就会被调用,并且会创建一个空白的view,如果viewcontroller绑定了storyboard或者xib就不用说了. ...
- CentOS安装Git
准备安装Gityum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel perl-devel #下载git-1 ...
- WPF 面试题及答案(二)
一 · WPF中什么是样式? 首先明白WPF中样式属于资源中重要的一种. 同时样式也是属性值的集合,能被应用到一个合适的元素中,或者说能将一组属性应用到多个元素. WPF中样式可以设置任何依赖属性. ...
- Lintcode: Singleton && Summary: Synchronization and OOD
Singleton is a most widely used design pattern. If a class has and only has one instance at every mo ...
- JavaScript——DOM操作——Window.document对象
一.找到元素: docunment.getElementById("id"):根据id找,最多找一个: var a =docunment.getElementById(&qu ...
- using gulp
原 荐 gulp构建前端工程 半张一块 发布时间: 2016/07/27 16:22 阅读: 895 收藏: 4 点赞: 4 评论: 2 摘要 Gulp 是一个自动化工具,前端开发者可以使用它来处理常 ...