awk output yields error: awk:can't open job_name (Autosys)

Good evening, Im newbie at unix specially with awk
From an scheduler program called Autosys i want to extract some data reading an inputfile that comprises jobs names, then formating the output to columns for example

This is the inputfile:

$ more MapaRep.txt
ds_extra_nikira_usuarios
ds_extra_ordenesserv
ds_extra_recargajuste
ds_extra_score_dinamico
ds_ftp_ciclo_migr_05
  1. This is the script
[validate_process
#!/bin/ksh
for i in `cat \home\autosys\MapaRep.txt`
do
  autorep -J $i -q
done]
  1. the output is something like listing n jobs name proprties
/* ----------------- ds_extra_nikira_usuarios ----------------- */ 
insert_job: ds_extra_nikira_usuarios   job_type: c 
box_name: ds_rep_nikira
command: /archivos/Shells/dwhExtraNikiraUsuarios.sh
machine: proetldb01c
owner: dsadm@proetldb01c
permission: gx,wx,mx
date_conditions: 1
days_of_week: all
start_times: "13:00"
alarm_if_fail: 1
max_exit_success: 2

/* ----------------- ds_extra_ordenesserv ----------------- */ 
insert_job: ds_extra_ordenesserv   job_type: c 
box_name: ds_rep_nikira
command: /archivos/Shells/dwhExtraccion.sh ordenesserv
machine: proetldb01c
owner: dsadm@proetldb01c
days_of_week: all
start_times: "12:00"
condition: d(ds_extra_recargajuste) & s(dwh_finalizacion)
description: "Genera el plano hacia nikira ORDENES_SERV_ en /archivos/InputFiles"
alarm_if_fail: 1
max_exit_success: 2

Is is OK up to know but i want to extract some data for each job sorted and formated as below:

insert_job                   command                                                         machine
ds_extra_ordenesserv: /archivos/Shells/dwhExtraccion.sh ordenesserv proetldb
..
job n name                  /command.sh n                                                server n

So in the loop i added the command

 [ autorep -J $i -q|awk '{printf("%s ", $1,$2)}' $i]

but it yields an error:

awk: can't open ds_extra_nikira_usuarios
awk: can't open ds_extra_ordenesserv
awk: can't open ds_extra_recargajuste
awk: can't open ds_extra_score_dinamic

So Ive got some questions:

  1. why Ive got this error
  2. I know the output of autorep command is not tabulated, so its neccessary to debug this output by trimming blanks spaces or sth like that before being proccessed ?
  3. any other sugesstions according to your expertise or knowledege ?
  1. The error is due to the $i after the awk command, which makes awk try to read a file named accordingly.
  2. I don't understand your question, but your awk script won't achive your desired result, even if the errors will be removed. Try instead
awk     'BEGIN          {HD="insert_job\tcommand\tmachine"
                         print HD
                         MX=split (HD, COLHD)}
                        {gsub (/:/, "")}
         HD ~ $1        {O[$1]=$2}
         /exit/         {for (i=1; i<=MX; i++) printf "%s\t", O[COLHD]
                         printf "\n"
                        }
        '
insert_job    command    machine
ds_extra_nikira_usuarios    /archivos/Shells/dwhExtraNikiraUsuarios.sh    proetldb01c    
ds_extra_ordenesserv    /archivos/Shells/dwhExtraccion.sh    proetldb01c    
  1. You may want to consider rewriting your script like
while read i
   do   autorep -J $i -q
   done < \home\autosys\MapaRep.txt | awk ... above script ...

ok thanks a lot for your support

What im trying to do is extract some data for each job from the autorep command as a normailized table with 4 columns as below:

insert_job(jobname)   command                      machine   days_of_week
ds_extra_ordenesserv: /Shells/dwhExtraccion.sh proetldb   all
..
job n name                  /command.sh n             machine n all

dont know if the above script you kindly post does the desired results as i described ?

Thanks for your help in advanced

This is not what you sort of specified in post#1. And, did you try the proposal?

Good afternon, i tested in a script but failed yielding errors:

awk: syntax error near line 4
awk: illegal statement near line 4
awk: syntax error near line 5
awk: bailing out near line 5

Here is the code

[autosys@proauto01 :PRO >more testing_v1.sh
#!/bin/ksh
#Validate Definition Autosys
while read i
   do   autorep -J $i -q
   done < /auto/autosys/MapaRep.txt |awk     'BEGIN          {HD="insert_job\tcommand\tmachine"
                         print HD
                         MX=split (HD, COLHD)}
                        {gsub (/:/, "")}
         HD ~ $1        {O[$1]=$2}
         /exit/         {for (i=1; i<=MX; i++) printf "%s\t", O[COLHD]
                         printf "\n"
                        }
        '
]

Thanks for your help in advanced

Try removing the space between the function names and the following open parenthesis:

#!/bin/ksh
#Validate Definition Autosys
while read i
do   autorep -J $i -q
done < /auto/autosys/MapaRep.txt |awk     '
         BEGIN          {HD="insert_job\tcommand\tmachine"
                         print HD
                         MX=split(HD, COLHD)
                        }
                        {gsub(/:/, "")}
         HD ~ $1        {O[$1]=$2}
         /exit/         {for (i=1; i<=MX; i++) printf "%s\t", O[COLHD]
                         printf "\n"
                        }
        '

Thanks, i already removed the space between the function names and the following open parenthesis but the error remains:

awk: syntax error near line 4
awk: illegal statement near line 4
awk: syntax error near line 5
awk: bailing out near line 5
autosys@proauto01 :PRO >

If you're using a Solaris/SunOS system, change awk to /usr/xpg4/bin/awk , /usr/xpg6/bin/awk , or nawk . If not; what operating system are you using?

Are there any <carriage-return> characters in your script? (There shouldn't be.)

I forgot telling u the Unix vesrion SunOS proauto01 5.10 Generic_148888-03 sun4u sparc SUNW,Sun-Fire-15000

I heard the version of awk in a SunOS is differente ? if so how to replace the command ?

Thanks a lot

You failed to mention the system and tool versions you use.

Quoting Don Cragun:

I thought I already said that in post #8 in this thread. :confused: Oh, well...

Good morning, instead using i am using nawk but the outptut yields:

insert_job      command machine
nawk: empty regular expression
 input record number 1
 source line number 5

but if i run testing this way; yield the same error but it continues the loop cycle

 read i
+ autorep -J ds_extra_nikira_usuarios -q

Thans for your help in advanced

insert_job      command machine
nawk: empty regular expression
 input record number 1
 source line number 5
autosys@proauto01 :PRO >+ read i
+ autorep -J ds_extra_ordenesserv -q
+ read i
+ autorep -J ds_extra_recargajuste -q
+ read i
+ autorep -J ds_extra_score_dinamico -q
+ read i
+ autorep -J ds_ftp_ciclo_migr_05 -q
+ read i
+ autorep -J ds_ftp_ciclo_migr_09 -q
+ read i

Is it possible your sample did not represent the real data? Try adding /^$/ {next} before the HD ~ $1 .
Should that not work, try modifying / commenting out script lines around line 5.

Thanks for your support, but ive got some questions:

1st /^$/ {next} before the HD ~ $1
would it be this way:?
/^$/ {next} HD ~ $1
what are we tryng to do with this line?

2nd try modifying / commenting out script lines around line 5
would it be commenting out lines 4 and 6?
what are we trying to do ? debug every line to trap the error ?

3rd dont konw about awk arrays and before i get documented and have a deeper knowledge, could u please explain to me a little bit about code lines ?
with your explanation i would have a better perspective to debug error i think

Thanks for your support again
:confused:

Please show us your complete current script (in CODE tags). There have been several suggestions on changes that could be made to your script and I am no longer sure that I know what your current script is doing.

Please show us the output that is being fed into the awk script (in CODE tags) from the autorep command. (Run the autorep command manually with the arguments it is given in the script and redirect the output to a file. Then show us the contents of that file.)

ok Thanks a lot for your help,
Notes:

  1. i dont see control characters in the scrip using cat -v
  2. The input File calles MapaRep contains jobs names (arguments) that is read from autorep comamnd
  3. Operating system SunOS (when use awk yileds error:
awk: syntax error near line 4
awk: illegal statement near line 4
awk: syntax error near line 5
awk: bailing out near line 5

whern using nawk:

nawk: empty regular expression
 input record number 1
 source line number 5

here you go

[#!/bin/ksh
#Validate Definition Autosys

while read i
   do   autorep -J $i -q
   done < /auto/autosys/MapaRep.txt | nawk 'BEGIN          {HD="insert_job\tcommand\tmachine"
                         print HD
                         MX=split(HD, COLHD)}
                        {gsub(/:/, "")}
         HD ~ $1        {O[$1]=$2}
         /exit/         {for (i=1; i<=MX; i++) printf "%s\t", O[COLHD]
                         printf "\n"
                        }
        '
]

As an example i run autorep command manually:

[autorep -J ds_extra_nikira_usuarios -q > output1.txt]

then i show u the contents of that file:

autosys@proauto01 :PRO >more output1.txt


/* ----------------- ds_extra_nikira_usuarios ----------------- */

insert_job: ds_extra_nikira_usuarios   job_type: c
box_name: ds_rep_nikira
command: /archivos/Shells/dwhExtraNikiraUsuarios.sh
machine: proetldb01c
owner: dsadm@proetldb01c
permission: gx,wx,mx
date_conditions: 1
days_of_week: all
start_times: "13:00"
description: "Genera el plano hacia nikira USUARIOS_"
std_out_file: > /archivos/WRK_DWHEXT/ds_extra_nikira_usuarios.out
std_err_file: > /archivos/WRK_DWHEXT/ds_extra_nikira_usuarios.err
alarm_if_fail: 1
max_exit_success: 2
autosys@proauto01 :PRO >bc

:confused:

With that output from your autorep program, it is highly likely that nawk is very picky and doesn't like to match HD to the (empty) $1 . Try putting /^$/ {next} into the line just above the HD match, and post the result.

Thats awesome, thanks you very much, seem to be working but in the input files didnt shw up all job names for each line, what is missing ?

autosys@proauto01 :PRO >./test5_old.sh
insert_job      command machine
ds_extra_nikira_usuarios        /archivos/Shells/dwhExtraNikiraUsuarios.sh      proetldb01c
ds_extra_ordenesserv    /archivos/Shells/dwhExtraccion.sh       proetldb01c
ds_extra_recargajuste   /archivos/Shells/dwhExtraccion.sh       proetldb01c
ds_extra_score_dinamico /archivos/Shells/dwhExtraccion.sh       proetldb01c
ds_ftp_ciclo_migr_20    /archivos/Shells/PREP_CAMBIO_MIGRATORIO_PREPAGO_FTP.sh  proetldb01c
ds_ftp_ciclo_migr_23    /archivos/Shells/PREP_CAMBIO_MIGRATORIO_PREPAGO_FTP.sh  proetldb01c
ds_ftp_ciclo_migr_26    /archivos/Shells/PREP_CAMBIO_MIGRATORIO_PREPAGO_FTP.sh  proetldb01c
ds_mover_nikira_taps    /archivos/Shells/NikiraMoverTaps.sh     proetldb01c
ds_preactivados_sms     /archivos/Shells/wedoExtraccion.sh      proetldb01c
ds_prep_altasbajas_H1   /archivos/Shells/PREP_ALTASYBAJAS_H1.sh proetldb01c
autosys@proauto01 :PRO >more Mapa*
ds_extra_nikira_usuarios
ds_extra_ordenesserv
ds_extra_recargajuste
ds_extra_score_dinamico
ds_ftp_ciclo_migr_05
ds_ftp_ciclo_migr_09
ds_ftp_ciclo_migr_12
ds_ftp_ciclo_migr_16
ds_ftp_ciclo_migr_20
ds_ftp_ciclo_migr_23
ds_ftp_ciclo_migr_26
ds_mover_nikira_taps
ds_preactivados_sms
ds_prep_186_ciclo_01
ds_prep_186_ciclo_05
ds_prep_186_ciclo_09
ds_prep_186_ciclo_12
ds_prep_186_ciclo_16
ds_prep_186_ciclo_20
ds_prep_186_ciclo_23
ds_prep_186_ciclo_26
ds_prep_altasbajas_H1

Look into the output files, and you'll see.

1 Like