尝试设置 bash 脚本来查找二进制文件中的版本,所有版本都包含在内,所以我想我必须删除 AUDIT_TRAIL_#_##_A-Z,1-9
这就是我迄今为止的任何建议
#!/bin/bash
echo searching fmx files AUDIT_TRAIL FOR FORM VERSION
for file in `/bin/ls *.fmx`
do
current_release=`strings $file |sed "s/\"AUDIT_TRAIL/NOTNEEDED/" |grep -i "AUDIT_TRAIL_8" |sed "s/AUDIT\_TRAIL\_/AUDIT\-TRAIL /" |sed "s/\_/\./g" |sed "s/\.[A-Z,a-z]/\.00/" |awk '{print substr($0,0,18)}' |awk '{print $2}'`
export form=$(echo "$file" | cut -f1 -d'.')
export dbform=`echo $form |awk '{print toupper($0)}'`
echo "FORMNAME" $form
sqlplus -s /nolog <<EOF
connect system/xxx@xxxxx
set echo on
whenever oserror exit 88
whenever sqlerror exit 1
spool forms.lst
select GURAOBJ_CURRENT_VERSION from bansecr.GURAOBJ where GURAOBJ_OBJECT = '$dbform';
spool off
exit
EOF
echo $file $current_release
done
输出
bash-4.1$ ./find_current_release_fmx_db.shl
+ ./find_current_release_fmx_db.shl
./find_current_release_fmx_db.shl: line 1: !/bin/bash: No such file or directory
searching fmx files AUDIT_TRAIL FOR FORM VERSION
FORMNAME peaempl
来自数据库
GURAOBJ_CU
----------
8.11.2
peaempl.fmx
来自已编译的表格
8.0 8.0 8.0.00 8.0.00 8.1.0. 8.1.0. 8.2.00 8.2.00 8.3 8.3 8.4 8.4 8.7.1 8.7.1 8.7.1. 8.7.1. 8.8.0. 8.8.0. 8.8.1. 8.8.1. **THE ONE I NEED 8.11.2** 8.11.2 8.1.0. 8.8.0. 8.7.1. 8.11.2 8.0.00 8.2.00 8.0 8.3 8.4 8.8.1. 8.7.1
期望输出
8.11.2
任何帮助将不胜感激
最佳答案
让我们首先整理一下脚本,不要使用太多的管道和命令,变得更加健壮,等等:
#!/bin/bash
printf 'searching fmx files AUDIT_TRAIL FOR FORM VERSION\n'
for file in *.fmx
do
current_release=$(strings "$file" | awk '<something>')
form="${file%%.}"
dbform="${form^^}"
printf 'FORMNAME %s\n' "$form"
sqlplus -s /nolog <<EOF
connect system/xxx@xxxxx
set echo on
whenever oserror exit 88
whenever sqlerror exit 1
spool forms.lst
select GURAOBJ_CURRENT_VERSION from bansecr.GURAOBJ where GURAOBJ_OBJECT = '$dbform';
spool off
exit
EOF
printf '%s %s\n' "$file" "$current_release"
done
现在我们需要知道的是<something>
是什么。在 awk 命令中应该是。我无法从您的管道命令链中弄清楚它,因为它们似乎在添加内容,然后再次删除它并转义不需要转义的内容,等等,但是一旦您显示 strings
的示例输出您希望 awk 脚本将其转换成什么内容应该是显而易见的。
关于linux - 需要 bash 脚本来剥离二进制文件中的版本并与数据库版本进行比较,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30243851/