Solved

KSH script to retrieve data from crontab file

Posted on 2013-05-23
6
626 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 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
From implementing a password expiration date, to datatype conversions and file export options, these are some useful settings I've found in Jasper Server.
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 video shows how to recover a database from a user managed backup

679 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