Skip to Main Content

Oracle Database Discussions

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Shell script for Automatic Awr Report

1000194Apr 17 2013 — edited Apr 17 2013
Hi Good Morning,


I have a requirement to generate the AWR report daily between (10AM - 06PM , 10AM - 01PM , 01PM - 10PM) . I have the below script for this . But the issue is this script is working only when i run it two times and before running i have to delete snap_list.lst file. Please let me know what is the problem in this script and how to resolve it.


Script :
-------------

dt=`date +%d%m%Y`


cd /orabkp/awr_report

chmod 777 *

rm -rf snap_list.lst


touch snap_list.lst

#rm -rf snap_list.lst
#rm -rf snap_list.lst


sqlplus -s " /as sysdba " <<EOF > snap_list.lst

host sleep 10

@/oracle/scripts/cron_scripts/rpt1.sql;

@?/rdbms/admin/awrrpt.sql
HTML
1
`cat snap_list.lst | grep "10:0" | awk '{print $1}'`
`cat snap_list.lst | grep "13:0" | awk '{print $1}'`
awrrpt\_$dt\_10AM\-01PM.html


prompt 2
@?/rdbms/admin/awrrpt.sql
HTML
1
`cat snap_list.lst | grep "13:0" | awk '{print $1}'`
`cat snap_list.lst | grep "18:0" | awk '{print $1}'`
awrrpt\_$dt\_01PM\-06PM.html


@?/rdbms/admin/awrrpt.sql
HTML
1
`cat snap_list.lst | grep "10:0" | awk '{print $1}'`
`cat snap_list.lst | grep "18:0" | awk '{print $1}'`
awrrpt\_$dt\_10AM\-06PM.html
@?/rdbms/admin/addmrpt.sql
`cat snap_list.lst | grep "06:0" | awk '{print $1}'`
`cat snap_list.lst | grep "12:0" | awk '{print $1}'`
ADDM_REPORT\_$dt\_10AM\-06PM.txt

EOF
exit


#########################################

cat /oracle/scripts/cron_scripts/rpt1.sql


host echo 1

host sleep 10

@?/rdbms/admin/awrrpt.sql
HTML
1
`cat snap_list.lst | grep "10:0" | awk '{print $1}'`
`cat snap_list.lst | grep "13:0" | awk '{print $1}'`
awrrpt\_$dt\_10AM\-01PM.html



Regards
Rajasekar

Comments

Gaz in Oz
Answer

In answer to your questions:

|  Variables from js scripts live on in SQLcl past execution of the script?

Yes. Of course.

is there a way to 'clear' all previous variables etc at the end of a script, or start of the next script, without having to exit and restart?

Yes.

Use javascript delete operator to remove the variable.

For example:

SQL> $type test_1.js

test_variable = "this is a test";

delete test_variable;

SQL> $type test_2.js

ctx.write(test_variable + "\n");

SQL> script test_1.js

SQL> script test_2.js

javax.script.ScriptException: ReferenceError: "test_variable" is not defined in <eval> at line number 1

        at jdk.nashorn.api.scripting.NashornScriptEngine.throwAsScriptException(NashornScriptEngine.java:470)

...

Caused by: <eval>:1 ReferenceError: "test_variable" is not defined

        at jdk.nashorn.internal.runtime.ECMAErrors.error(ECMAErrors.java:57)

...etc.

Marked as Answer by ptfl · Sep 27 2020
ptfl

Interesting, this is standard behaviour?

Is there no way to reset the entire environment, rather than variable by variable?

I'm curious about situations where you might be running scripts from different developers, any of which might clash on a variable name in an unexpected way.

ptfl

Gaz in Oz

Interesting, this is standard behaviour?

Yes. A UI session that gets a variable defined, I would expect it to stay defined until it is explicitly undefined or the UI session is terminated/ended.

Is there no way to reset the entire environment, rather than variable by variable?

Yes, there is a way, which is also standard, terminate and restart the UI session.

Instead of keeping your single session "running" and worrying about how the "developers" have defined javscript variables as "local" or "global", review the script/s before running, approve them, then run  them up in their own sqlcl instances:

I'm curious about situations where you might be running scripts from different developers, any of which might clash on a variable name in an unexpected way.

If a developer "uses" a variable before defining it, then the script is run in a UI session that already had that variable defined and NOT undefined, then sure, it will pick up the value that is already defined. That is a bug in the developers code that used a variable before defining it (and thus not setting/resetting/changing its value). Not the UI's fault, the developers.

To make sure that sort of bug is picked up, run all scripts in their own sqlcl instance. No big deal.

If there were two different UI sessions running at the same time, then those variables would be exclusive to the individual UI session.

For example, if you had 5 scripts to run, from different developers, who's code you haven't reviewed and so can not trust, you could loop through each, in a shell script and run them one by one.

1 - 3
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on May 15 2013
Added on Apr 17 2013
6 comments
8,676 views