Solved

KSH script to retrieve data from crontab file

Posted on 2013-05-23
6
613 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Have you ever had to make fundamental changes to a table in Oracle, but haven't been able to get any downtime?  I'm talking things like: * Dropping columns * Shrinking allocated space * Removing chained blocks and restoring the PCTFREE * Re-or…
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.
This video shows how to recover a database from a user managed backup
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

744 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

11 Experts available now in Live!

Get 1:1 Help Now