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 ...
随机推荐
- 集群中用Memcached来实现session共享
这几天在实现nginx集群的过程中,发现session使用存在问题,登录页面后有时候需要重复登录,和开发部沟通后,决定采用memcached来实现session的共享,这也是各大型网站推荐的方式.开发 ...
- 第六篇 Replication:合并复制-发布
本篇文章是SQL Server Replication系列的第六篇,详细内容请参考原文. 合并复制,类似于事务复制,包括一个发布服务器,一个分发服务器和一个或多个订阅服务器.每一个发布服务器上可以定义 ...
- nginx 414 Request-URI Too Large
症状 nginx 414 Request-URI Too Large #客户端请求头缓冲区大小,如果请求头总长度大于小于128k,则使用此缓冲区, #请求头总长度大于128k时使用large_clie ...
- ipmi使用
1.安装ipmitool Linux: yum -y install OpenIPMI-tools 备注:Linux机器也可以安装ipmi yum -y install OpenIPMI OpenI ...
- C# web api 返回类型设置为json的两种方法
每次写博客,第一句话都是这样的:程序员很苦逼,除了会写程序,还得会写博客!当然,希望将来的一天,某位老板看到此博客,给你的程序员职工加点薪资吧!因为程序员的世界除了苦逼就是沉默.我眼中的程序员大多都不 ...
- SQL注入攻击之关键字检测
最近悟出来一个道理,在这儿分享给大家:学历代表你的过去,能力代表你的现在,学习代表你的将来.我们都知道计算机技术发展日新月异,速度惊人的快,你我稍不留神,就会被慢慢淘汰!因此:每日不间断的学习是避免被 ...
- ps 简介
1. ps 简介ps 命令就是最根本相应情况下也是相当强大地进程查看命令.运用该命令可以确定有哪些进程正在运行和运行地状态. 进程 是否结束.进程有没有僵死.哪些进程占用了过多地资源等等.总之大部分信 ...
- JAVA的JVM虚拟机工作原理.V.1.0.0
注意:一下内容纯属个人理解,如有错误,欢迎批评指正. (90度弯腰)谢谢. java在JVM上的运行过程: 1,编辑好的java代码(IDE无报错,测试运行无错误): 2,java源代码通过javac ...
- centos python nginx uwsgi
先更新系统,并安装编译环境等等. yum update yum install python python-devel libxml2 libxml2-devel python-setuptools ...
- struts局部、全局类型转换器
第01步:编写bean package com.self.bean; import java.util.Date; public class User { private Date birthday ...