我正在尝试解析我负责管理的所有 300 多个 Autosys 作业,并且希望能够解析一个 300 多个 autosys 作业 JIL 文件以自动化一些报告。
我被允许使用的软件受到严格限制。我最近发现了这个 awk 脚本。我尝试了一个 SAS 解决方案,但这只得到了 1/2 的数据。Perl 脚本可以工作,但我并不精通 perl。awk 对我来说似乎更容易理解和使用
awk -F ' *[[:alnum:]_]*: *' 'BEGIN {h="insert_job;box_name;machine;command;owner;permission;date_conditions;days_of_week;run_calendar;start_times;condition;description;std_out_file;std_err_file;alarm_if_fail;profile;priority;alarm_if_terminated;timezone;group;application;resources;"; print h; n=split(h,F,/;/)}
function pr() {if(F[1] in A) {for(i=1;i<=n;i++)printf "%s%s",A[F[i]],(i<n)?";":RS}}
/insert_job/ {pr(); delete A}
{for(i in F){if($0~"^"F[i])A[F[i]]=$2}}
END {pr()}' /foo/bar/all.jil > /foo/bar/outfile2.txt
样本 Jil(这是输入):
/* ----------------- somejob ----------------- */
insert_job: somejob job_type: CMD
command: SAS ${AUTO_ROOT}/pgms/somejob.sas
machine: someserver.com
owner: user1
permission: gx,wx
date_conditions: 1
run_calendar: 1st_bus_dom
start_times: "07:00"
condition: s(someotherjob)
description: "Send email notification."
std_out_file: "${AUTO_JOB_LOG}.out"
std_err_file: "${AUTO_JOB_LOG}.err"
alarm_if_fail: 1
profile: "/foo/bar/etc/app1"
alarm_if_terminated: 1
timezone: CST6CDT
group: grp1
application: app1
resources: (someresource,QUANTITY=2,FREE=A)
/* ----------------- somejob2 ----------------- */
insert_job: somejob2 job_type: CMD
command: SAS ${AUTO_ROOT}/pgms/somejob2.sas
machine: someserver.com
owner: user1
permission: gx,wx
date_conditions: 1
run_calendar: 1st_bus_dom
start_times: "07:00"
condition: s(someotherjob)
description: "Send email notification."
std_out_file: "${AUTO_JOB_LOG}.out"
std_err_file: "${AUTO_JOB_LOG}.err"
alarm_if_fail: 1
profile: "/foo/bar/etc/app1"
alarm_if_terminated: 1
timezone: CST6CDT
group: grp1
application: app1
resources: (someresource,QUANTITY=2,FREE=A)
样本输出
insert_job;box_name;machine;command;owner;permission;date_conditions;days_of_week;run_calendar;start_times;condition;description;std_out_file;std_err_file;alarm_if_fail;profile;priority;alarm_if_terminated;timezone;group;application;resources;
somejob;;someserver.com;SAS ${AUTO_ROOT}/pgms/somejob.sas;user1;gx,wx;1;;1st_bus_dom;"07:00";s(someotherjob);"Send email notification.";"${AUTO_JOB_LOG}.out";"${AUTO_JOB_LOG}.err";1;"/foo/bar/etc/app1";;1;CST6CDT;grp1;app1;(someresource,QUANTITY=2,FREE=A);
somejob2;;someserver.com;SAS ${AUTO_ROOT}/pgms/somejob2.sas;user1;gx,wx;1;;1st_bus_dom;"07:00";s(someotherjob);"Send email notification.";"${AUTO_JOB_LOG}.out";"${AUTO_JOB_LOG}.err";1;"/foo/bar/etc/app1";;1;CST6CDT;grp1;app1;(someresource,QUANTITY=2,FREE=A);
我想弄清楚为什么 start_times 没有被正确解析到 outfile2.txt 中。我只收到该行的第一个 " 。
编辑:看起来 printf 的 RegExpression 部分没有读取和打印数字字符。我现在不确定如何解决这个问题。
编辑2:看起来类似的问题需要“start_times”内容。我一直在努力思考如何解决这个问题,但我没有运气。当前输出只添加第一个“我们应该为 start_times 输出整行:“07:00”
我正在使用的当前 awk 返回如下内容:
somejob;;;;user1;gx,wx;1;;1st_bus_dom;";;
我想要这个
somejob;;;;user1;gx,wx;1;;1st_bus_dom;"7:00";;