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


 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Help with Expect script for pulling log files size larger than 500Mb;
# 1  
Old 02-19-2019
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
Code:
[----------------------------------------------------------------------------------------------------------------------------------
[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)
Code:
# 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:
Code:
# 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
Code:
"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?

Moderator's Comments:
Mod Comment MOD's comment: Kindly wrap your samples, codes in [CODE]...........[/CODE] tags as per forum rules.

Last edited by RavinderSingh13; 02-19-2019 at 08:07 PM..
# 2  
Old 02-20-2019
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.

Last edited by RudiC; 02-20-2019 at 05:20 PM..
# 3  
Old 02-20-2019
In the working command replace the awk '{ print \$1 /1024 }' with awk '{ print int ( \$1 / 1024 + 0.5 ) }'.
# 4  
Old 02-20-2019
Quote:
Originally Posted by MadeInGermany
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.
# 5  
Old 02-20-2019
Like you did in your unsuccessful attempt, I have moved the echo's into an if branch and assumed a /bin/sh compatible shell:
Code:
[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 \].
# 6  
Old 02-20-2019
Quote:
Originally Posted by MadeInGermany
Like you did in your unsuccessful attempt, I have moved the echo's into an if branch and assumed a /bin/sh compatible shell:
Code:
[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
Code:
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:

Code:
[----------------------------------------------------------------------------------------------------------------------------------]
[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.
Moderator's Comments:
Mod Comment Please use CODE tags when displaying sample input, sample output, and code segments.

Last edited by mikebantor; 02-21-2019 at 10:01 AM..
# 7  
Old 03-01-2019
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!!

Code:
[# 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..."]


Last edited by Corona688; 03-01-2019 at 11:39 AM.. Reason: Code tags for code please
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Need to select files larger than 500Mb from servers

I need help modifying these two scripts to do the following: - print files in (MB) instead of (KB) - only select files larger than 500MB -> these will be mailed out daily - Select all files regardless of size all in (MB) -> these will be mailed out once a week this is what i have so far and... (5 Replies)
Discussion started by: donpasscal
5 Replies

2. Shell Programming and Scripting

Script to show alert when today's total download has exceeded 500mb, 1 gb, 1500mb and 1800mb

Hey, I'm new to learning scripting with linux bash shell. And, I was thinking I'd learn linux by learning to solve a problem. So, I currently use a internet connection which allots me 2GB starting from 12:01 am in my timezone to 11.59pm. But, occasionally when I watch videos from youtube, my... (1 Reply)
Discussion started by: vishnuajit
1 Replies

3. Shell Programming and Scripting

Backingup larger files with TAR command

I need to backup my database but the files are very large and the TAR command will not let me. I searched aids and found that I could do something with the mknod, COMPRESS and TAR command using them together. I appreciate your help. (10 Replies)
Discussion started by: frizcala
10 Replies

4. UNIX for Dummies Questions & Answers

Using UNIX Commands with Larger number of Files

Hello Unix Gurus, I am new to Unix so need some help on this. I am using the following commands: 1) mv -f Inputpath/*. outputpath 2) cp Inputpath/*. outputpath 3) rm -rf somepath/* 4) Find Inputpath/*. Now I get the following error with... (18 Replies)
Discussion started by: pchegoor
18 Replies

5. Shell Programming and Scripting

How to compare if the size of the directory is more than 500MB in unix

I use du -sk command to find the size of the directory but when i use the result of 'du -sk' into if statement its throwing error.. Could u solve with this..? (14 Replies)
Discussion started by: shaal89
14 Replies

6. AIX

Tar files larger than 2GB

Hi, Does anyone know if it is possible to tar files larger than 2GB? The reason being is they want me to dump a single file (which is around 20GB) to a tape drive and they will restore it on a Solaris box. I know the tar have a limitation of 2GB so I am thinking of a way how to overcome this.... (11 Replies)
Discussion started by: depam
11 Replies

7. Solaris

Directory size larger than file system size?

Hi, We currently have an Oracle database running and it is creating lots of processes in the /proc directory that are 1000M in size. The size of the /proc directory is now reading 26T. How can this be if the root file system is only 13GB? I have seen this before we an Oracle temp file... (6 Replies)
Discussion started by: sparcman
6 Replies

8. Shell Programming and Scripting

Pulling a list of files from FTP site in a shell script

Hi, I am writting a shell script which will pull a list files (mentioned in one file 1.txt) from external FTP site (for ex: ftp://abcd.efghijk.com/). The 1.txt is in my local unix directory. I have username and password to connect the external FTP site. Also before I pull the files, I need... (0 Replies)
Discussion started by: spatra
0 Replies

9. Shell Programming and Scripting

bash script working for small size files but not for big size files.

Hi, I have one file stat. Stat file contents are as follows: for example. H50768020040913,00260100,507680,13,0000000643,0000000643,00000,0000 H50769520040808,00260100,507695,13,0000000000,0000000000,00000,0000 H50770620040611,00260100,507706,13,0000000000,0000000000,00000,0000 Now i... (1 Reply)
Discussion started by: davidpreml
1 Replies

10. UNIX for Advanced & Expert Users

sending larger files via ftp

hi all, i am looking for ways to make ftp efficient by tuning the parameters currently, tcp_max_buf is 1 MB tcp_xmit_hiwat is 48 KB say to transmit multiple 2 gb files from unix server to mainframe sys, will increasing the window size or the send buffer size of the current TCP/IP... (6 Replies)
Discussion started by: matrixmadhan
6 Replies
Login or Register to Ask a Question