Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

KSH script to retrieve data from crontab file

Posted on 2013-05-23
6
Medium Priority
?
641 Views
Last Modified: 2013-06-03
I have a script retrieving a list servers from Oracle database and now I need to add code to my KSH script to read crontab file, or in other words just execute

crontab -l

Open in new window


on each of the servers retrieve with my SQL query and spool the results to a file.
Can anyone help?

My script is below:

#!/usr/bin/ksh

export ORACLE_SID=DBName
ORAENV_ASK=NO
. oraenv
sqlplus -s /nolog <<EOF
CONNECT usr1/pwd
SET LINES 4000 TRIMS ON FEED OFF PAGES 0
SET MARKUP HTML ON SPOOL ON HEAD "<TITLE>Server Name Report</title> -
<STYLE TYPE='TEXT/CSS'><!--BODY {background: ffffc6} --></STYLE>"
SET ECHO OFF
SPOOL myfile.html
SELECT HOST_NAME FROM TABLE1;
SPOOL OFF
EOF

Open in new window

0
Comment
Question by:YZlat
  • 2
  • 2
  • 2
6 Comments
 
LVL 78

Accepted Solution

by:
slightwv (䄆 Netminder) earned 750 total points
ID: 39192113
So you want to loop through your list of servers from the database and execute 'crontab -l' on each one?

Do you have remote shell set up so you can execute remote commands?

If not, you probably can't get there from here.

Most organizations don't allow remote shell because of the security risks.

If you are logged into server1 and server2 comes from the database can you:
rsh server2 crontab -l
0
 
LVL 35

Author Comment

by:YZlat
ID: 39192212
Thanks, I am going to find out about the remote shell.

The thing is that I am executing the script from OEM to get the data on all backup jobs for every database server and every database, but some databases are not tracked via OEM, so in the future I will need to loop through server names list in a text file and retrieve crontab data from each server
0
 
LVL 78

Expert Comment

by:slightwv (䄆 Netminder)
ID: 39192237
Even if you can remote shell, it still likely won't be easy to get the output of the crontab into the results of your spool file but we'll cross that when we need to.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 35

Assisted Solution

by:Duncan Roe
Duncan Roe earned 750 total points
ID: 39192900
You could likely use expect to do this. If you code to use ssh to contact each server, there would be no need to include passwords in your script.
Can you post an example of how you would do this by hand? Then I could show you how to automate it with expect.
0
 
LVL 35

Author Comment

by:YZlat
ID: 39208832
I am using ksh script. Is it possible with ksh?
0
 
LVL 35

Expert Comment

by:Duncan Roe
ID: 39209488
Yes you can run expect from ksh. In fact you can make a ksh script which morphs into running expect so only 1 script. I always do that (in sh (bash) but at work it had to be ksh).
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Shell script to create broker configuration file using current broker Configuration, solely for purpose of backup on Linux. Script may need to be modified depending on OS-installation. Please deploy and verify the script in a test environment.
This video shows information on the Oracle Data Dictionary, starting with the Oracle documentation, explaining the different types of Data Dictionary views available by group and permissions as well as giving examples on how to retrieve data from th…
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Suggested Courses

877 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question