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开发脚本过程中 ...
随机推荐
- kubernetes-身份与权限认证(十四)
Kubernetes的安全框架 https://kubernetes.io/docs/reference/access-authn-authz/rbac/ •访问K8S集群的资源需要过三关:认证.鉴权 ...
- Eclipse Python插件 PyDev
PyDev for Eclipse 是一个功能强大且易用的 Eclipse Python IDE 插件.本文将向读者介绍 PyDev 开源项目及其安装配置方法,并在此基础上详细介绍如何利用 PyDev ...
- 使用maven搭建ssm项目配置+tomact
一.代码自动配置:https://www.cnblogs.com/weibanggang/p/10043201.html 二.手动配置 1.创建好maven项目,在pom.xml配置文件 <!- ...
- CUDA三维数组
http://hpcbbs.it168.com/forum.php?mod=viewthread&tid=1643 根据上面链接的帖子研究了下三维数组,就像他自己说的一样是有问题的,我自己修改 ...
- SqlServer和Oracle修改表结构语句
SQL Server:1.增加列 ALTER TABLE users ADD address varchar(30);2.删除列 ALTER TABLE users DROP COLUMN add ...
- 树梅派3B kali2.0 启用SSH进行远程登录
工具/原料 kali 2.0 ssh SSH连接工具(XShell)or PUTTY vi /etc/ssh/sshd_config 将#PasswordAuthentication no的注释去掉, ...
- lintcode_397_最长上升连续子序列
最长上升连续子序列 描述 笔记 数据 评测 给定一个整数数组(下标从 0 到 n-1, n 表示整个数组的规模),请找出该数组中的最长上升连续子序列.(最长上升连续子序列可以定义为从右到左或从左到 ...
- mysql5.6 配置 文件
mysql 3306 主库配置文件 [client] port = 3306 default-character-set=utf8mb4 socket = /ssd/mysql/3306/tmp/my ...
- datatable设置动态宽度,超过一定长度出现滚动条
获得宽度:var tableAutoWidth = $('.dataTable_wrapper').width();if (tableAutoWidth < 1200) { tableAutoW ...
- 一次完整的http请求处理过程
一次完整的HTTP请求需要的7个步骤 HTTP通信机制是在一次完整的HTTP通信过程中,Web浏览器与Web服务器之间将完成下列7个步骤: 1:建立TCP连接 在HTTP工作开始之前,Web浏览器首先 ...