比较文件有无修改,通过修改时间判别
# !/bin/bash
dir=$ for file in `ls $dir`
do
if [ -d $dir/$file ]
then
echo $file is dir
else
time=`stat $file | tail - | head - | cut -d' ' -f2- | cut -d. -f1`
name=$file
currentTime=`date "+%Y-%m-%d %H:%M:%S"`
echo "$name $time $currentTime"
oldtime=`date +%s -d "$time"`
newtime=`date +%s -d "$currentTime"`
# echo $(($newtime-$oldtime))
if [ $(($oldtime-$newtime)) -ge ]
then
echo "$file is a new file"
else
echo "$file not modify"
fi
fi
done
自动创建n的测试文件
#!/bin/bash
#echo $#
if [ $# -eq 1 ]
then
nums=$
# echo $nums
for((i=;i<$nums;i++))
do
#sleep 1
touch ./file-`date +%F-%H-%M-%S`-$i.txt
done else
echo "you need input nums like ./app nums,bye"
exit -
fi
判断时段内文件有无更新
# !/bin/bash
dir=$ for file in `ls $dir`
do
if [ -d $dir/$file ]
then
echo $file is dir
else
file=$dir/$file
#获取最后修改时间,并截取成 y-m-d h:m:s
time=`stat -c %y $file | cut -d. -f1`
name=$file
currentTime=`date "+%Y-%m-%d %H:%M:%S"`
echo "$name $time $currentTime"
#将字符串时间转换成数字,距1970年的时间
#文件当前的最后修改时间
oldtime=`date +%s -d "$time"`
#系统当前时间
newtime=`date +%s -d "$currentTime"`
#时间偏移量,这里定义为一天24*60*60,意味着一天扫描一次,如需修改扫描次数,修改这个地方就行
shifttime=
#这里用当前文件最后修改时间,与一天前的时刻做比较,如果大于0,说明文件在从昨天这个时刻到今天这个时刻之间发生了变化,偏移量不是一天时,代表的是这段时间内
#测试 shifttime=600 10分钟
#shifttime=600
if [ $(($oldtime-$newtime+$shifttime)) -ge ]
then
echo "$file is a new file"
else
echo "$file not modify"
fi
fi
done
统计history信息
#!/bin/bash
USER_IP=`who -u am i >/dev/null | awk '{print $NF}' | sed -e 's/[()]//g'`
HISTDIR=/usr/share/.history
if [ -z $USER_IP ]
then
USER_IP=`hostname`
fi
if [ ! -d $HISTDIR ]
then
mkdir -p $HISTDIR
chmod $HISTDIR
fi if [ ! -d $HISTDIR/${LOGNAME} ]
then
mkdir -p $HISTDIR/${LOGNAME}
chmod $HISTDIR/${LOGNAME}
fi export HISTSIZE=
DT=`date +%Y%m%d_%H%M%S`
export HISTFILE="$HISTDIR/${LOGNAME}/${USER_IP}.history.$DT"
export HISTTIMEFORMAT="[%Y.%m.%d %H:%M:%S]"
chmod $HISTDIR/${LOGNAME}/*.history.* >/dev/null

捕获信号

#!/bin/bash

trap "echo sigint" SIGINT
echo "This is a test program"
count=
while [ $count -le ]
do
echo "Loop #$count"
sleep
count=$[ $count + ]
done
echo "This is the end of the test program"

read使用

#!/bin/bash

#simple read
echo -n "Enter your name:"
read name
echo "Hello $name,welcome!" #read 指定
read -p "Please enter your age:" age
days=$[ $age * ]
echo "That makes you over $days days old" #read 不带变量,存在默认变量REPLY中
read -p "Please enter your age:"
echo "your age is $REPLY" #read 延时选项
read -t -p "Please enter your age:"
echo "your age is $REPLY" #read 默读
read -s -p "Please enter your passwd:"
echo "your passwd is $REPLY" read读文件
#!/bin/bash #read file if [ $# -lt 1 ]
then
echo "Usage ./readfile.sh testfile"
exit -
fi echo "file name is $1" count=
cat $ | while read line
do
echo "Line $count:$line"
count=$[ $count+ ]
done
echo "Finished processing the file"

打开文件

--------------------------------------------------------------------------------
#!/bin/bash #open
exec > test
echo "This is a test line of data" >&
#close
exec >&-
echo "This won't work" >&

shell之一些测试脚本的更多相关文章

  1. Linux CAN Shell 测试脚本程序

    2012-01-13 22:57:14 为我的开发板2440做二次开发,添加了can驱动,做了驱动测试程序,没理由不添加一个测试脚本程序啊!修改了测试程序,使应用程序更加灵活,添加了一下传递参数.接着 ...

  2. shell编程之服务脚本编写,文件锁以及信号捕获

    shell脚本编程是linux运维工程师必备的技能,也是非常重要的一个技能,所以把shell编程学好,只有好处.基础语法我也就不讲了,学过C语言这些语言的,稍微看一下就能明白shell编程的基础,所以 ...

  3. Linux shell编写端口扫描脚本

    Linux shell编写端口扫描脚本 需求: 扫描特定主机 扫描特定主机的特定端口 扫描特定网段 扫描特定网段中哪些主机开放了特定的端口 源码如下: #/bin/bash #该脚本用于对特定目标主机 ...

  4. Appium环境的安装与配置,Python测试脚本测试

    Appium自动化测试系列1 - Appium环境的安装与配置 发表于4个月前(2015-01-27 14:34)   阅读(803) | 评论(0) 0人收藏此文章, 我要收藏 赞0 寻找 会’偷懒 ...

  5. shell编写一个判断脚本

                                                              shell编写一个判断脚本 4.1问题 本例要求在虚拟机server0上创建/roo ...

  6. SPF邮件伪造漏洞测试脚本

    测试脚本: # -*- coding: utf-8 -*- import socket,select,base64,os,re,time,datetime class mail: def __init ...

  7. Shell文件权限和脚本执行

    一.预备知识 1.shell的作用   2.常识 (1)Tab键自动补全   使用Terminal时,输入命令的前几个字母,敲tab会自动补全命令或文件名.目录等. 好处:操作速度更快:不容易出错: ...

  8. 用BlazeMeter录制JMeter测试脚本

    工具: 1,JMeter 2,Chrome 3,BlazeMeter 4,SwitchyOmega(如果需要代理) 步骤: 以上工具准备好以后就可以录制JMeter的测试脚本了, 在Chrome中点击 ...

  9. Loadrunner开发测试脚本

    Loadrunner开发测试脚本 开发测试脚本可以通过录制,也可以手动开发,建议能录制的尽量录制,省时省力,不能录制的只能费力自己开发了,具体看项目情况来决定. 使用Loadrunner开发脚本过程中 ...

随机推荐

  1. numpy中的inf

    numpy中的inf表示一个无限大的正数 import numpy x = numpy.inf x>9999999999999999999 结果为: True

  2. leetCode没那么难啦 in Java (一)

    前言    感觉写博客是一个很耗心力的东西T_T,简单的写了似乎没什么用,复杂的三言两语也只能讲个大概,呸呸...怎么能有这些消极思想呢QAQ!那想来想去,先开一个leetcode的坑,虽然已经工作了 ...

  3. 创建git及其初始化

    创建一个版本库非常简单,首先,选择一个合适的地方,创建一个空目录: $ mkdir learngit $ cd learngit $ pwd /Users/michael/learngit 初始化一个 ...

  4. Login用户登录(Python实现)

    username_fault = "isuperSun" #程序存储用户名和密码 password_fault = " counts = 0 while counts&l ...

  5. c++ 11 线程池的简单封装

    #include <condition_variable> #include <queue> #include <thread> #include <vect ...

  6. call()和apply()

    每个函数都包含apply和call方法. 相同点:都接收两个参数,一个是在其中运行函数的作用域,另一个是参数: 不同点:call方法和apply的不同之处在于接收参数的方式不同: apply方法第二个 ...

  7. Struts2之基于配置的字段校验

    上一篇struts2之输入校验介绍了手动完成输入校验,也即依靠重写validate方法和validateXxx方法,指定请求某个方法时对传入的参数进行校验. 本篇介绍基于配置的字段校验.下面是登录的常 ...

  8. rsync同步备份搭建

    Rsync 是 Unix/Linux 下的一款应用软 在平常的运维中进常要对一些数据进行备份,以防止意外的服务器故障导致不可避免的后果,tar,cp只能适应一些小范围backup,对于几T甚至几P的数 ...

  9. Python学习笔记:sqlite3(sqlite数据库操作)

    对于数据库的操作,Python中可以通过下载一些对应的三方插件和对应的数据库来实现数据库的操作,但是这样不免使得Python程序变得更加复杂了.如果只是想要使用数据库,又不想下载一些不必要的插件和辅助 ...

  10. Python的输入和输出问题详解

    输出用print()在括号中加上字符串,就可以向屏幕上输出指定的文字.比如输出'hello, world',用代码实现如下: >>> print('hello, world') pr ...