Solved

KSH script to retrieve data from crontab file

Posted on 2013-05-23
6
620 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 76

Accepted Solution

by:
slightwv (䄆 Netminder) earned 250 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 76

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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 34

Assisted Solution

by:Duncan Roe
Duncan Roe earned 250 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 34

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

This post first appeared at Oracleinaction  (http://oracleinaction.com/undo-and-redo-in-oracle/)by Anju Garg (Myself). I  will demonstrate that undo for DML’s is stored both in undo tablespace and online redo logs. Then, we will analyze the reaso…
Every server (virtual or physical) needs a console: and the console can be provided through hardware directly connected, software for remote connections, local connections, through a KVM, etc. This document explains the different types of consol…
This video explains at a high level with the mandatory Oracle Memory processes are as well as touching on some of the more common optional ones.
Via a live example show how to connect to RMAN, make basic configuration settings changes and then take a backup of a demo database

911 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now