shell脚本
来源:互联网 发布:汉语网络在线老师招聘 编辑:程序博客网 时间:2024/06/03 04:19
我们写shell脚本的时候,可能会遇到交互式的情况,如果不想在执行脚本的时候出现交互式,怎么做呢?很简单,写个expect脚本就能轻易解决,下面是我写的一个简单的shell。
1、写好expect脚本,解决交互式问题,在后面的shell中将会引用expect
#!/usr/bin/expect
spawn kinit hdfs
expect{
"PASSWORD*" {send "testpassword"}
}
这样一个最简单的expect脚本就写好了!
2、下面是shell脚本,用Hadoop下载一定时间范围内的数据
#!/bin/bashdate_start=$1
date_end=$2
date_process=${date_start}
hdfs_dir=/TEST/ZMER
local_dir=/tmp/test
log_dir=/tmp/logs
#引用expect脚本
cd /opt/fi_client
source bigdata_env
expect /opt/fi_client/hdfs_expect
#date_increament.sh 2016010100 2016040100
while [ "${date_process}" -le "${date_end}" ]do
#call your shell scripts ${date_process}
dd_date=${date_process:0:8}
if [ ! -d $local_dir/$dd_date ]
then mkdir -p $local_dir/$dd_date
fi
for i in $(cat $local_dir/test.txt)
do
hadoop fs -get $hdfs_dir/TEST_$dd_date.dat $local_dir/$dd_date 1>/dev/null 2>&1
if [[ $? == 0 ]]
then touch $hdfs_dir/TEST_$dd_date.verf
date=`date +"%Y%m%d %H%M%S"`
log_rec="[TIME]: "$date" [MGS]:"$hdfs_dir/TEST_$dd_date.dat
echo $log_rec "is load succed" >> $log_dir/test_$dd_date.log
fi
done
#时间循环时间格式为yyyymmddhh
date_process=`date +%Y%m%d%H -d "1 hours $dd_date ${date_process:0-2}"`done
0 0
- shell脚本
- shell脚本
- shell脚本
- shell脚本
- shell脚本
- shell脚本
- shell脚本
- shell 脚本
- SHELL 脚本
- shell脚本
- shell脚本
- shell 脚本
- shell脚本
- shell脚本
- shell脚本
- shell脚本
- shell脚本
- shell脚本
- 电子相册系统(一)Dao的组件设计
- REST资源地址和作用域 学习笔记
- Android 网络请求
- python语法基础归纳(2)--序列对象
- 前言
- shell脚本
- sql事务(Transaction)用法介绍及回滚实例
- TCP连接的状态详解以及故障排查
- hiho 37 二分查找k小数
- 每周小结 parallel coordinate version 1.0
- iOS App性能优化
- C++第四次实验
- 11、初步使用roswtf
- Android--帧动画