#!/bin/bash
################################################################################ #@brief 功能:初始化日志,从配置文件读取相应的配置信息 #@param in "$config_name" 配置文件绝对路径 #@param in "$section" 类型 #@param in "$key" 关键值名称 #@param ot value 返回关键值对应的值 #@return 0 成功 1失败 #@example get_ini "$config_name" "$section" "$key" value #author: lijianhua #date: 2010-6-23 14:45 ################################################################################ function get_ini() { local FILE=$1 local SECTION=$2 local KEY=$3
local LINE=" " local var1=" " local var2=" " local section=" " local section_flag=NO #echo $FILE #echo $SECTION #echo $KEY
while read LINE do # trim preceding & trailing spaces LINE=` echo $LINE | sed 's/ //g' |sed 's/[[:space:]]*//g' ` #echo $LINE #过滤空行 以及以';'或'#'开头的行 if [ -z "$LINE" -o "${LINE:0:1}" = ";" -o "${LINE:0:1}" = "#" ]; then # skip null line & comment line #echo $LINE continue; fi #echo $LINE #echo "$section_flag" #查找section并赋值给section_flag if [ "$section_flag" = "NO" ]; then #echo $LINE; if [ "${LINE:0:1}" = "[" ]; then section=` echo $LINE|awk '{print substr($0, 2, index($0,"]")-2 )}' `; #echo $section; if [ "$section" = "$SECTION" ]; then #echo "this section"; #echo $section; section_flag=YES; continue; else #echo "no section"; #echo $section; continue; fi else continue; fi fi #echo "find section" #找到了section 开始查找key值 if [ "${LINE:0:1}" = "[" ]; then # skip null line & comment line #在找到的 section内没有找到对应配置 return -1; fi #echo $LINE var1=`echo $LINE | awk -F "=" '{print $1}'` if [ "$KEY" = "$var1" ]; then # skip null line & comment line #echo $LINE #echo "this key" var2=`echo $LINE | awk -F "=" '{print $2}'` eval $4=\"$var2\" #echo $var1 #echo $var2 return 0; else #echo $var1 #echo "not this key" continue; fi
done < $FILE; return 1; }
################################################################################ #@brief 功能:从配置文件初始化主机信息 #@return 0 成功 1失败 #@example init_info #gl_var gl_s_ip,gl_s_port,gl_s_user,gl_s_passwd,gl_config_name,gl_section #author: lijianhua #date: 2010-6-23 14:45 ################################################################################ function init_info() { ##获取 get_ini "$gl_config_name" "$gl_section" "s_ip" gl_s_ip if [ $? = 0 ];then echo " "; echo "succ"; echo $gl_s_ip; else echo $?; echo "err"; return 1; fi ##获取 get_ini "$gl_config_name" "$gl_section" "s_port" gl_s_port if [ $? = 0 ];then echo " "; echo "succ"; echo $gl_s_port; else echo $?; echo "err"; return 1; fi ##获取 get_ini "$gl_config_name" "$gl_section" "s_user" gl_s_user if [ $? = 0 ];then echo " "; echo "succ"; echo $gl_s_user; else echo $?; echo "err"; return 1; fi ##获取 get_ini "$gl_config_name" "$gl_section" "s_passwd" gl_s_passwd if [ $? = 0 ];then echo " "; echo "succ"; #echo $gl_s_passwd; else echo $?; echo "err"; return 1; fi return 0; }
##################################################################### #生成ftp脚本 #author: lijianhua #date: 2010-6-23 14:45 ##################################################################### function init_ftpfile() { #F="tmpxxxx.ftp" echo "open $gl_s_ip $gl_s_port" > $F echo "user $gl_s_user $gl_s_passwd" >> $F echo "bin" >> $F #echo "dir" >> $F echo "cd $gl_s_filepath" >> $F echo "lcd $gl_c_filepath" >> $F echo "mput $gl_c_filename" >> $F echo "bye" >> $F return 0; }
############################脚本执行开始######################### ###服务器主机信息 gl_s_ip= gl_s_port= gl_s_user= gl_s_passwd=
##文件目录信息 gl_s_filepath=/home/sand/ftp/ # gl_c_filepath=/home/topn_ljh/sbin/ # gl_c_filename=" *.sh " #需要ftp的文件
##配置文件信息 gl_config_name=ftp.ini gl_section=test245
###ftp脚本临时文件 F="tmpxxxx.ftp"
####调用初始化函数 init_info; if [ $? != 0 ];then echo " "; echo "error init_info"; fi echo "ok init_info";
####初始化ftp脚本文件 init_ftpfile; if [ $? != 0 ];then echo " "; echo "error init_ftpfile"; fi echo "ok init_ftpfile";
#####执行ftp脚本 ftp -i -in < $F rm -rf $F
echo "cmd run end !!!!!!!!!result
|
阅读(1691) | 评论(0) | 转发(0) |