shell之一些测试脚本
# !/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
#!/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
#!/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之一些测试脚本的更多相关文章
- Linux CAN Shell 测试脚本程序
2012-01-13 22:57:14 为我的开发板2440做二次开发,添加了can驱动,做了驱动测试程序,没理由不添加一个测试脚本程序啊!修改了测试程序,使应用程序更加灵活,添加了一下传递参数.接着 ...
- shell编程之服务脚本编写,文件锁以及信号捕获
shell脚本编程是linux运维工程师必备的技能,也是非常重要的一个技能,所以把shell编程学好,只有好处.基础语法我也就不讲了,学过C语言这些语言的,稍微看一下就能明白shell编程的基础,所以 ...
- Linux shell编写端口扫描脚本
Linux shell编写端口扫描脚本 需求: 扫描特定主机 扫描特定主机的特定端口 扫描特定网段 扫描特定网段中哪些主机开放了特定的端口 源码如下: #/bin/bash #该脚本用于对特定目标主机 ...
- Appium环境的安装与配置,Python测试脚本测试
Appium自动化测试系列1 - Appium环境的安装与配置 发表于4个月前(2015-01-27 14:34) 阅读(803) | 评论(0) 0人收藏此文章, 我要收藏 赞0 寻找 会’偷懒 ...
- shell编写一个判断脚本
shell编写一个判断脚本 4.1问题 本例要求在虚拟机server0上创建/roo ...
- SPF邮件伪造漏洞测试脚本
测试脚本: # -*- coding: utf-8 -*- import socket,select,base64,os,re,time,datetime class mail: def __init ...
- Shell文件权限和脚本执行
一.预备知识 1.shell的作用 2.常识 (1)Tab键自动补全 使用Terminal时,输入命令的前几个字母,敲tab会自动补全命令或文件名.目录等. 好处:操作速度更快:不容易出错: ...
- 用BlazeMeter录制JMeter测试脚本
工具: 1,JMeter 2,Chrome 3,BlazeMeter 4,SwitchyOmega(如果需要代理) 步骤: 以上工具准备好以后就可以录制JMeter的测试脚本了, 在Chrome中点击 ...
- Loadrunner开发测试脚本
Loadrunner开发测试脚本 开发测试脚本可以通过录制,也可以手动开发,建议能录制的尽量录制,省时省力,不能录制的只能费力自己开发了,具体看项目情况来决定. 使用Loadrunner开发脚本过程中 ...
随机推荐
- 2018.7.9 Android—显式Intent和隐式Intent的区别
1:都是用来在一个activity中启动另外一个activity 2:显示Intent直接指明要启动activity的定义,即activity.class:隐式intent通过在androidmani ...
- 2017.10.14 Java的流程控制语句switch&&随机点名器
今日内容介绍 1.流程控制语句switch 2.数组 3.随机点名器案例 ###01switch语句解构 * A:switch语句解构 * a:switch只能针对某个表达式的值作 ...
- 【转】使用webmagic搭建一个简单的爬虫
[转]使用webmagic搭建一个简单的爬虫 刚刚接触爬虫,听说webmagic很不错,于是就了解了一下. webmagic的是一个无须配置.便于二次开发的爬虫框架,它提供简单灵活的API,只需少量代 ...
- Redis 命令学习
每天不学习点新的东西,感觉就有点会被社会淘汰掉了.也许现在学习的知识会很快忘记,下次学习用到这个知识点的时候,再回来翻记录的笔记,我想这样会比从头再学,效率会高点吧. 闲话不多聊,回归正题.今天学习r ...
- HTTP head meta
HTTP(HyperTextTransferProtocol)即超文本传输协议,目前网页传输的的通用协议.HTTP协议采用了请求/响应模型,浏览器或其他客户端发出请求,服务器给与响应.就整个网络资源传 ...
- fcc初级算法方法总结
var arr = str.split("分隔符"): var newArr = arr.reverse(); var str = arr.join("连接符" ...
- 使用免费公开的api接口示例(iOS)
做项目难免需要测试,要测试就需要一些接口,现在网上的很多接口都是需要收费的. 以下是目前找到的免费 JSON API免费接口 云聚数据 网吧数据 其中选取了一个百度百科的接口 百度接口 百度百科接口: ...
- 【ODT】cf896C - Willem, Chtholly and Seniorious
仿佛没用过std::set Seniorious has n pieces of talisman. Willem puts them in a line, the i-th of which is ...
- spring-bean(注解方式-管理及依赖注入)
Bean管理(注解方式) 1.添加注解的依赖包:Spring-aop.jar 2.配置spring的XML文件的引入(查官方源码) 3.开启注解的扫描 <context:component-sc ...
- PLC状态机编程第六篇-优化PLC程序生成
还记得第一篇博客中,我们在状态机中手写上升沿来处理有别于传统的一键启停程序,那个手写的上升沿就是优化手段.stateflow状态机是带事件的,事件本身支持上升沿和下降沿等事件,在这里,如果我们选择用事 ...