54SA.COM|专注于系统运维管理,为中国SA提供动力!
Getting online shouldn't be tough. $7.99 .COMs
系统管理员之家Banner
当前位置: 主页 > Linux > Linux编程 > Shell编程 >

怎么用shell处理二进制文件

时间:2011-07-05 16:20来源:未知 编辑:admin

一个shell script(脚本),其中有一部分是转换十六进制到十进制。道理差不多,应该和这个有点象,是Solaris环境下的。 用来转换Solaris下的Sybase interfaces file 为windows环境下的Sybase的sql.ini。

脚本源码:

[code:1:8fab55483b]
#!/bin/sh
# This is a script to convert the interfaces file of sybase server to sql.ini of
sybase client on PC.
# Illusion/ICIL
# Intialize sql.ini
(
echo ";; Sybase Interfaces file"
echo ";;"
echo ";; [<database_server_name>]"
echo ";; <link_type>=<network_driver>,<connection_info>"
echo ";;"
echo ";; Examples:"
echo ";; [JUPITER]"
echo ";; QUERY=NLMSNMP,\\JUPITER\pipe\sybase\query"
echo ";; WIN3_QUERY=WNLNMP,\\JUPITER\pipe\sybase\query"
echo ";;\n\n\n"
)>/tmp/sql
# May ignore the backup server for sybase
servers=`grep -i '^[a-z]' /opt/sybase11/interfaces | sed '/_BACKUP/d'`
for server in ${servers}; do
echo "Converting ${server} info ..."
server_info=`grep -A 2 \^"${server}"\$ /opt/sybase11/interfaces`
master_info=`echo "${server_info}" | grep "master" | awk '{ print $5 }'`
# May use a perl script to convert the number of IP too.
master_ip1=`echo "${master_info}" | cut -c11-12`
master_ip1=`echo "${master_ip1}" | tr '[a-z]' '[A-Z]'`
master_ip1=`echo "obase=10; ibase=16; ${master_ip1}" | bc`
master_ip2=`echo "${master_info}" | cut -c13-14`
master_ip2=`echo "${master_ip2}" | tr '[a-z]' '[A-Z]'`
master_ip2=`echo "obase=10; ibase=16; ${master_ip2}" | bc`
master_ip3=`echo "${master_info}" | cut -c15-16`
master_ip3=`echo "${master_ip3}" | tr '[a-z]' '[A-Z]'`
master_ip3=`echo "obase=10; ibase=16; ${master_ip3}" | bc`
master_ip4=`echo "${master_info}" | cut -c17-18`
master_ip4=`echo "${master_ip4}" | tr '[a-z]' '[A-Z]'`
master_ip4=`echo "obase=10; ibase=16; ${master_ip4}" | bc`
master_ip=`echo "${master_ip1}.${master_ip2}.${master_ip3}.${master_ip4}
`
master_port=`echo "${master_info}" | cut -c7-10`
master_port=`echo "${master_port}" | tr '[a-z]' '[A-Z]'`
master_port=`echo "obase=10; ibase=16; ${master_port}" | bc`
# add the server info to sql.ini
(
echo "[${server}]"
echo "master=NLWNSCK,${master_ip},${master_port}"
echo "query=NLWNSCK,${master_ip},${master_port}\n\n"
)>>/tmp/sql
done
# convert to PC filesystem
unix2dos /tmp/sql > /tmp/sql.ini[/code:1:8fab55483b]

以上就是shell处理二进制文件的方法,可以作为参考。

[责任编辑:admin]


------分隔线----------------------------
发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
评价:
用户名:
最新评论 进入详细评论页>>