Solved

KSH script to retrieve data from crontab file

Posted on 2013-05-23
6
631 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
6 Comments
 
LVL 77

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 77

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
Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

 
LVL 35

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 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Cursors in Oracle: A cursor is used to process individual rows returned by database system for a query. In oracle every SQL statement executed by the oracle server has a private area. This area contains information about the SQL statement and the…
Configuring and using Oracle Database Gateway for ODBC Introduction First, a brief summary of what a Database Gateway is.  A Gateway is a set of driver agents and configurations that allow an Oracle database to communicate with other platforms…
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 take different types of Oracle backups using RMAN.
Suggested Courses

623 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