Help with Expect script for pulling log files size larger than 500Mb;

I am new at developing EXPECT scripts. I'm trying to create a script that will automatically connect to a several UNIX (sun solaris and HPUX) database server via FTP and pull the sizes of the listener/alert log files from specified server directory on the remote machines.

  1. I want the script to only pull files larger than 500Mb and the decimal places rounded off.
  2. I used 'du -sk' because it works both on Sun Solaris and HPUX.
  3. Here is a sample output
[----------------------------------------------------------------------------------------------------------------------------------
[Server00
            Alert Log 12c: /oracle/DEV/saptrace/diag/rdbms/dev/DEV/trace/alert_DEV.log - 126.368 (MB)
            Listener Log: /oracle/DEV/saptrace/diag/tnslsnr/Server00/listener/trace/listener.log - 444.785 (MB)]
----------------------------------------------------------------------------------------------------------------------------------[

a. With this comnand, out put looks like this..(i want it rounded to full full numbers say 234mb)

# command for gathering Listener Log 
[set v_listener_command "; echo '            Listener Log' | tr '\\n' ':'; echo '' | tr '\\n' ' ' ; lsnrctl status | grep Log | awk '{ print \$4 }' | sed 's/alert\\/log.xml/trace\\/listener.log/g' | tr '\\n' ' '; echo '-' | tr '\\n' ' ' ; du -sk `lsnrctl status | grep Log | awk '{ print \$4 }' | sed 's/alert\\/log.xml/trace\\/listener.log/g'` | awk '{ print \$1 /1024 }' | tr '\\n' ' ' ;  echo '(MB)'"]

b. With this command, i get the error below:

# NEW command for gathering Listener Log
[set v_listener_command "; m=\$(du -sk `lsnrctl status | grep Log | awk '{ print \$4 }' | sed 's/alert\\/log.xml/trace\\/listener.log/g'` | awk '{ print \$1/1024 }');m=\${m%%.*};if test \$m -ge 0 ; then echo ' Listener Log' | tr '\\n' ':'; echo '' | tr '\\n' ' ' ; lsnrctl status | grep Log | awk '{ print \$4 }' | sed 's/alert\\/log.xml/trace\\/listener.log/g' | tr '\\n' ' '; echo '-' | tr '\n' ' ' ;echo \${m}Mg; fi "]

extra characters after close-quote
while executing

"set v_listener_command "; m=\$(du -sk `lsnrctl status | grep Log | awk '{ print \$4 }' | sed 's/alert\\/log.xml/trace\\/listener.log/g'` | awk '{ prin..."

Can anyone help me to try and get this resolved?

Welcome to the forum.

Please with every new thread post your OS, shell, and used tools' versions, and compose a careful, precise, and detailed specification.
Your's above leaves me utmost confused.
Where do you use / intend to use the expect command?
How did you produce your sample output?
How do you connect to the remote servers?

Please be aware that expect is a last resort tool - it's better to tailor a solution with standard tools, evaluating their results and exit codes.

In the working command replace the awk '{ print \$1 /1024 }' with awk '{ print int ( \$1 / 1024 + 0.5 ) }' .

Thanks to MadeInGermany, your proposed modification fixed my issue. I am grateful.

I have one more question, is it possible to modify the working command to only pull files larger than 500Mb?

thanks in advance.

Like you did in your unsuccessful attempt, I have moved the echo's into an if branch and assumed a /bin/sh compatible shell:

[set v_listener_command "; set -f ; f=`lsnrctl status | awk '/Log/{ print \$4 }' | sed 's|alert/log.xml|trace/listener.log|'` ; du -sk $$f | awk '{ x= int ( \$1 / 1024 + 0.5 ) }'` ; if [ $$m -gt 500 ] ; then echo '            Listener Log:' \$f '-' \$m 'MB'; fi"]

Looking at your error message the ] character might clash with the embracing [set ] , then try to \escape it: [ $$m -gt 500 \] or \[ $$m -gt 500 \] .

Thanks again for the input... the above mod seems to be clashing. Will it be possible to modify this code to only select log files >500Mb:
[# command for gathering Listener Log

set v_listener_command "; echo '           [ Listener Log' | tr '\\n' ':'; echo '' | tr '\\n' ' ' ; lsnrctl status | grep Log | awk '{ print \$4 }' | sed 's/alert\\/log.xml/trace\\/listener.log/g' | tr '\\n' ' '; echo '-' | tr '\\n' ' ' ; du -sk `lsnrctl status | grep Log | awk '{ print \$4 }' | sed ]'s/alert\\/log.xml/trace\\/listener.log/g'` | awk '{ print int ( \$1 / 1024 + 0.5 )  }' | tr '\\n' ' ' ;  echo '(Mb)'"

]]

Here is a sample output from the command that you helped me modify:

[----------------------------------------------------------------------------------------------------------------------------------]
[server100
            Alert Log 12c: /oracle/DG/saptrace/diag/rdbms/dg/DG/trace/alert_DG.log - 14 (Mb)
            Listener Log: /oracle/DG/saptrace/diag/tnslsnr/server100/listener/trace/listener.log - 530 (Mb)]
[----------------------------------------------------------------------------------------------------------------------------------]
[server200
            Alert Log 12c: /oracle/PG/saptrace/diag/rdbms/pg/PG/trace/alert_PG.log - 48 (Mb)
            Listener Log: /oracle/PG/saptrace/diag/tnslsnr/server200/listener/trace/listener.log - 451 (Mb)]
[----------------------------------------------------------------------------------------------------------------------------------]
[server3d00
            Alert Log 12c: /oracle/DG/saptrace/diag/rdbms/dg/DG/trace/alert_DG.log - 8 (Mb)
            Listener Log: /oracle/DG/saptrace/diag/tnslsnr/server3d00/listener/trace/listener.log - 521 (Mb)]
[----------------------------------------------------------------------------------------------------------------------------------]

Now i just want to be able to only pull the log files from Server100 and Server3d00.

Could somebody please help me, i am trying to print only listener log files larger than 500Mb and i am getting the error listed below....!! I really do not know what to do next.....Please i need some help!!

[# command for gathering Listener Log ]
[set v_listener_command "; echo ' Listener Log' | tr '\\n' ':'; echo '' | tr '\\n' ' ' ; lsnrctl status | grep Log | awk '{ print \$4 }' | sed 's/alert\\/log.xml/trace\\/listener.log/g' | tr '\\n' ' '; echo '-' | tr '\\n' ' ' ; du -sk `lsnrctl status | grep Log | awk '{ print \$4 }' | sed 's/alert\\/log.xml/trace\\/listener.log/g'` | awk '{if ( \$1 / 1024 + 0.5 > 500 ) print $1 }' | tr '\\n' ' ' ;  echo '(MB)'"]


[can't read "1": no such variable
    while executing

"set v_listener_command "; echo '            Listener Log' | tr '\\n' ':'; echo '' | tr '\\n' ' ' ; lsnrctl status | grep Log | awk '{ print \$4 }' | s..."]

Bumping up posts or double posting is not permitted in these forums.

Please read the rules, which you agreed to when you registered, if you have not already done so.

You may receive an infraction for this. If so, don't worry, just try to follow the rules more carefully. The infraction will expire in the near future

Thank You.

The UNIX and Linux Forums.