zoukankan      html  css  js  c++  java
  • crontab实现每秒执行

    crontab:

    #!/bin/bash
    
    step=$1   #每多少秒执行一次
     
    for (( i = 0; i < 60000000000; 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:20160619
     
    #####################################################################
    # $1:the frequency to do log backup
    # $2:only if the number of log files reach v_count,log files will be backuped
    # $3:target directory that needs to do log backup
    # $4:the directory to put bakuped logs
    #####################################################################
     
    v_step=$1
    v_count=$2
    v_targDir=$3
    v_histDir=$4
     
    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=0
    # recycle endlessly
    while [ "1" = "1" ]
    do
        # if same job process already exists,sleep sometime
        while [ "1" = "1" ]
        do
            if [ $isProcExist -gt 0 ]
            then
                sleep $v_step
            else
                break
            fi
        done
    
        let isProcExist=1
    
        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=0
    done

     autoCreateFile:

    #!/bin/bash
    #author:xiluhua
    #since:20160619
     
    v_step=$1
    if [ -z $v_step ]
    then
        echo "exception: argu 'v_step' is empty!"
        exit
    fi
     
    cd ~/auto
     
    for (( i = 0; i < 60000000000; 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:20160619
    #####################################################################
    # $1:the dir to do batch file rename
    # $2:name before rename
    # $3:name after rename
    #####################################################################
     
    dir=$1
    targ=$2
    repl=$3
    
    #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
  • 相关阅读:
    unnitest简单场景应用
    接口基础之request
    docker常用命令
    管理之心理学
    管理团队挑战和提升
    如何留下核心成员
    管理之面试技巧
    复杂接口请求怎样写http请求
    gitlab使用(一)
    不使用AutoLayout快速兼容适配iPhone6/6 Plus
  • 原文地址:https://www.cnblogs.com/xiluhua/p/5592197.html
Copyright © 2011-2022 走看看