Shell scripts maintenance tasks for DBA
Most of companies use shell scripts to monitor DB activities, i just want to make myself familier with the main scripts, and how to manage them. If someone can send me some help material.
Sorry, I should have been more explicit and not only point to the initial page but directly, where the script library is. And I should have made clear it is not a final product, but the base to build your own library.
First link (orasnap) refers to the work made by Stewart McGlaughlin, who created a comprehensive collection of frequently used dba scripts. He compiled those scripts into an utility named orasnap. This you can download it from his yahoo site, if you take enough time to follow the links. Out from this collection of scripts I have personally taken several to tailor them into specific Unix/Dos shell maintenance scripts. I mean the homework is not finished, Out from his work I have taken a good base to build my own most frequently used Shell Maintenance Library.
The second link belongs to Tim Hall (http://www.oracle.com/technology/community/oracle_ace/ace1.html#hall) whose remarkable work has greatly contributed to the Oracle technical community daily job. Once again, this site doesn't have finished shell scripts for you simply to cut and paste, but the dba scripts I pointed plus a little effort and several interesting concepts and tips you can find navigating through his site turn this site into a first hand reference.
Similar Messages
-
Trying to run Power shell Script on task schedule
My case is i'm trying to run a power shell script through the task schedule.
Note if i run the script locally it is working fine but from the task schedule it is not working.
More information:
script function: Password Change Notification
Task name : test3
Time to do the task: 9:08 am every day
the status : running
.ps1 file location: under C\windows\system32\
some actions in the task history after the dated time to run:
1 Task Scheduler launched "{3023b1eb-9b29-47b9-ace2-e6083e2f00cc}" instance of task "\test3" due to a time trigger condition
2 Task Engine "S-1-5-21-60622444-1628707926-2526327935-500: enviroment\Admin:S4U:LUA" received a message from Task Scheduler service requesting to launch task "\test3" .
3 Task Scheduler started "{3023b1eb-9b29-47b9-ace2-e6083e2f00cc}" instance of the "\test3" task for user "enviroment\admin
4 Task Scheduler launched action ""C:\Windows\System32\Password Change Notification\Password Change Notification.ps1"" in instance "{3023b1eb-9b29-47b9-ace2-e6083e2f00cc}" of task "\test3
5 Task Scheduler launch task "\test3" , instance "C:\Windows\System32\notepad.exe" with process ID 5052Hi MeipoXu,
First of all i would like to thank you for your answer, i followed the URL that you posted already in the previous comment and unfortunately it didn't work, and please find my ps1 file
content as typed below and give me your feedback on that.
# # Version 1.1 May 2014
# Robert Pearman (WSSMB MVP) # TitleRequired.com
# Script to Automated Email Reminders when Users Passwords due to Expire.
# # Requires: Windows PowerShell Module for Active Directory
# # For assistance and ideas, visit the TechNet Gallery Q&A Page. http://gallery.technet.microsoft.com/Password-Expiry-Email-177c3e27/view/Discussions#content
# Please Configure the following variables....
$smtpServer="outlook. myDomain " $expireindays = 7
$from = "الدعم الفني
<ITHelpDesk@myDomain>"
$logging = "Enabled" # Set to Disabled to Disable Logging
$logFile = "PassExpireNotlog.csv" # ie. c:\mylog.csv
$testing = "Enabled" ## "Enabled" # Set to Disabled to Email Users
$testRecipient = "MyEmail@MyDomain"
$encoding = [System.Text.Encoding]::Unicode $date = Get-Date -format ddMMyyyy
# Check Logging Settings if (($logging) -eq "Enabled")
{ # Test Log File Path
$logfilePath = (Test-Path $logFile) if (($logFilePath) -ne "True")
{ # Create CSV File and Headers
New-Item $logfile -ItemType File
Add-Content $logfile "Date,Name,EmailAddress,DaystoExpire,ExpiresOn,MsgBody"
} } # End Logging Check
# Get Users From AD who are Enabled, Passwords Expire and are Not Currently Expired
Import-Module ActiveDirectory $users = get-aduser -filter * -SearchScope Subtree -SearchBase "OU=UsersOU,DC=MyDomain,DC=MyrootDomain,DC=MYrootNS" -properties Name, PasswordNeverExpires, PasswordExpired, PasswordLastSet,
EmailAddress |where {$_.Enabled -eq "True"} | where { $_.PasswordNeverExpires -eq $false } | where { $_.passwordexpired -eq $false }
$maxPasswordAge = (Get-ADDefaultDomainPasswordPolicy).MaxPasswordAge
# Process Each User for Password Expiry foreach ($user in $users)
{ $Name = (Get-ADUser $user | foreach { $_.Name})
$emailaddress = $user.emailaddress
$passwordSetDate = (get-aduser $user -properties * | foreach { $_.PasswordLastSet })
$PasswordPol = (Get-AduserResultantPasswordPolicy $user)
# Check for Fine Grained Password
if (($PasswordPol) -ne $null) {
$maxPasswordAge = ($PasswordPol).MaxPasswordAge
$expireson = $passwordsetdate + $maxPasswordAge
$today = (get-date) $daystoexpire = (New-TimeSpan -Start $today -End $Expireson).Days
# Set Greeting based on Number of Days to Expiry.
# Check Number of Days to Expiry
$messageDays = $daystoexpire if (($messageDays) -ge "2")
{ $messageDays = "خلال
" + "$daystoexpire" + " ايام"
} elseif (($messageDays) -eq "2")
{ $messageDays = "خلال يومين
} else
{ $messageDays = "اليوم."
} # Email Subject Set Here
$subject="كلمة المرور الخاصة بك ستنتهي
$messageDays"
# Email Body Set Here, Note You can use HTML, including Images.
$body = "<P style='font-family: Arial; font-size: 16pt' />
<center> الاستاذ/ $name
</center>
<br> <center>
كلمة المرور الخاصة بك ستنتهي $messageDays </center>
<br> <center>
نأمل تغييرها في أقرب فرصة حتي تتمكن من الدخول على النظام
</center>
<br> <center>
مع تحيات الادارة العامة لتقنية المعلومات
</center>
<br> </P>"
# If Testing Is Enabled - Email Administrator
if (($testing) -eq "Enabled")
{ $emailaddress = $testRecipient
} # End Testing # If a user has no email address listed
if (($emailaddress) -eq $null)
{ $emailaddress = $testRecipient
}# End No Valid Email # Send Email Message
if (($daystoexpire -ge "0") -and ($daystoexpire -lt $expireindays))
{ # If Logging is Enabled Log Details
if (($logging) -eq "Enabled")
{ Add-Content $logfile "$date,$Name,$emailaddress,$daystoExpire,$expireson,$body"
} # Send Email Message
Send-Mailmessage -smtpServer $smtpServer -from $from -to $emailaddress -subject $subject -body $body -bodyasHTML -priority High -Encoding $encoding
} # End Send Message
} # End User Processing
# End -
Enable Re-Indexing Maintenance Task for SCCM 2012 R2 Database?
If I use the
MaintenanceSolution.sql script provided by Ola Hallengren here:
http://ola.hallengren.com/sql-server-index-and-statistics-maintenance.html
and then use this SQL script weekly to rebuild the SCCM 2012 R2 indexes:
EXECUTE dbo.IndexOptimize
@Databases = 'USER_DATABASES',
@FragmentationLow = NULL,
@FragmentationMedium = 'INDEX_REORGANIZE,INDEX_REBUILD_ONLINE,INDEX_REBUILD_OFFLINE',
@FragmentationHigh = 'INDEX_REBUILD_ONLINE,INDEX_REBUILD_OFFLINE',
@FragmentationLevel1 = 5,
@FragmentationLevel2 = 30,
@UpdateStatistics = 'ALL',
@OnlyModifiedStatistics = 'Y'
Then do I still need to enable the built-in database re-indexing maintenance task in the SCCM 2012 R2 console?
ThanksIn the Channel9 video, the statement is made that the built in Rebuild Indexes "maintenance task does not always work and that it is kind of broken, but it works sometimes and not always." Can anyone provide further
details regarding the state of the Rebuild Indexes
maintenance task? Why does it only sometimes work? Should it be used at all? Has it been fixed with a CU since the video came out? Are there plans to fix it?
I need to defrag my database, and I am trying to determine the best approach.
Thanks!
-Tony -
New to shell script need help for script
Hi,
I have following shell script which takes database name from file sql.config. this file has names of all staging database. I want to modify this script to run below analyze index commands if database is staging and if its production database then i want to run different set of commands say analyze user schemas. How can i implement this in below script (something like if then else)?
connstr=`grep "gemsit_staging" /cronacle/tools/informatica/sql.config`
sqlplus -S<<EOF1
$connstr
whenever sqlerror exit failure;
ANALYZE TABLE GEMSIT_STAGING.AR_TRANS_DETAIL_STG COMPUTE STATISTICS;
ANALYZE TABLE GEMSIT_STAGING.GLOBAL_SET_S COMPUTE STATISTICS;
ANALYZE INDEX GEMSIT_STAGING.AR_DEL_TRANS_DETAIL_STG_PK COMPUTE STATISTICS;
ANALYZE INDEX GEMSIT_STAGING.AR_DEL_TRANS_DETAIL_STG_01 COMPUTE STATISTICS;
ANALYZE INDEX GEMSIT_STAGING.AR_TRANS_DETAIL_STG_PK COMPUTE STATISTICS;
ANALYZE INDEX GEMSIT_STAGING.AR_TRANS_DETAIL_STG01_IX COMPUTE STATISTICS;
ANALYZE INDEX GEMSIT_STAGING.AR_TRANS_DETAIL_STG02_IX COMPUTE STATISTICS;
ANALYZE INDEX GEMSIT_STAGING.AR_TRANS_DETAIL_STG03_IX COMPUTE STATISTICS;
ANALYZE INDEX GEMSIT_STAGING.AR_TRANS_DETAIL_STG04_IX COMPUTE STATISTICS;
ANALYZE INDEX GEMSIT_STAGING.AR_TRANS_DETAIL_STG05_IX COMPUTE STATISTICS;
ANALYZE INDEX GEMSIT_STAGING.AR_TRANS_DETAIL_STG06_IX COMPUTE STATISTICS;
ANALYZE INDEX GEMSIT_STAGING.AR_TRANS_DETAIL_STG07_IX COMPUTE STATISTICS;
ANALYZE INDEX GEMSIT_STAGING.GLOBAL_SET_S_PK COMPUTE STATISTICS;
ANALYZE INDEX GEMSIT_STAGING.GLOBAL_SET_S_PK1 COMPUTE STATISTICS;
EOF1
thanksif test $? -ne 0 ; then
echo 'Processing Error' >> $Log_Dir/$Log_File
exit 1
else
echo 'Processing Completed' >> $Log_Dir/$Log_File
rm -f $Script_Dir/$Flag_File
exit 0
ficreate two sql files one form test and for prod say test.sql and prod.sql with relevant sql statements
this is a sample if else construct, you nned to get the env using "host"/"hostname" cmd on linux and assign this to a variable say envname
if envname $? -ne 'PR' ; then
echo 'Processing Test SQL' >> $Log_Dir/$Log_File
<call the test sql here>
exit 1
else
echo 'Processing Prod SQL' >> $Log_Dir/$Log_File
<call the Prod sql here>
fi -
Wait for a "do shell script" command to finish
i have an applescript that has to call a few external applications. i currently do this by setting the exact syntax of the external command in a string variable, then issue a "do shell script cmd" (seen many examples across the net using this standard)
my applescript continues beyond these commands. how do i set the applescript to either wait for the above external command to finish, or not?
regards
jingo_manUsually AppleScript will wait for a shell script to complete before it continues, but adding an ampersand (&) at the end of the shell script command will make it run in the background, which allows the AppleScript to continue. See Technical Note 2065: do shell script in AppleScript for more information.
-
How to Prompt for User/Pass Running Shell Script Remotely through ARD
So I finally got my Active Directory Script working! However, I realized that I'm not the only one going to be running this script and to have my user name and password in the script itself is beyond foolish. While I know it's possible just to have whoever's running the script to manually add their username and password, I'd prefer to have prompts to make things easier for the rest of my team.
Here's my current script. I've tested it on the machine I'm connecting to Active Directory and it works fine if you run it on the machine itself in terminal. However, I'm going to be doing this on about 150 machines and the whole point of the script is to do it remotely.
#! /bin/bash
MACNAME=$(scutil --get ComputerName)
read -p "User Name: " USER
read -p "Password for $USER: " PASS
dsconfigad -add "CORP.DOMAIN.NET" \
-username $USER \
-password $PASS \
-computer $MACNAME \
-mobile disable \
-mobileconfirm disable \
-localhome enable \
-useuncpath enable \
-shell /bin/bash \
-ou OU=Macs,CN=Computers,DC=corp,DC=DOMAIN,DC=net \
-force \
-localpassword "PASSWORD" \
-groups "GROUPS"
When I run the UNIX script through ARD to a machine, I get no prompts for USER or PASS. In fact, it gives me the following error "dsconfigad: Authentication server encountered an error while attempting the requested operation. (5202)" So it's not asking for a user name and password.
Is there any way to make a shell script prompt you for a User Name and Password when you're sending commands remotely through ARD? Or is there another way to do this?
Any suggestions would be greatly appreciated.
-rksBest solution is to create an account that is exclusive to binding machines. By doing this, you can embed the user name and password in the script. Heck, you can post it on your website. If the account is configured properly, it will only be able to create machine records in a defined container. If you are mixing Macs and PCs in your AD domain, I also recommend creating an isolated container for your Mac records. Now, the account has even less access rights as you can make it so it only has rights to the Mac container.
Otherwise, ARD does not prompt. You can play around with an expect script but the reality is that you are still embedding the credentials in the script so it really does not achieve what you want. ARD is not an interactive shell scripting tool. It is more a fire and forget.
Reid
Apple Consultants Network
Apple Professional Services
Author "Mavericks Server – Foundation Services" :: Exclusively available in Apple's iBooks Store -
Hi,
I dont know about shell scripting .since iam involved in the database administration side i dont know have much knowledge in unix shell scripting.
so, wat part does this shell scripting taked in database administration.so wat are all the things which i should get familiar to gain good knowledge in shell scripting.
so kindly provide me some docs/metalink IDS which will enrich my knowledge in shell scripting.
As a DBA upto wat level i should be good in shell scriptingHi;
I dont know about shell scripting .since iam involved in the database administration side i dont know have much knowledge in unix shell scripting.
As a DBA upto wat level i should be good in shell scriptingI belive atleast you have to learn until u can write some control or backup script or when you see some scripts you can understand what they are doing. There is no level or limitation to say "My information enough".
For instance i can type some scripts here but when i go some client they have wirtten and run scripts which can has more than 300-500 line scripts. Its mean its depend your workaround and company or clients needs&requests.
so, wat part does this shell scripting taked in database administration.so wat are all the things which i should get familiar to gain good knowledge in shell scripting.You can type many scripts as:
For backup
For check tablespace status
For check alert log error
For compiling invalid objects
and so on.
so kindly provide me some docs/metalink IDS which will enrich my knowledge in shell scripting.I suggest check first Hussein Sawwan previous greatest post about similar topic:
Shell Script
Shell Script
Also check below search:
http://forums.oracle.com/forums/search.jspa?threadID=&q=shell+scripting&objID=c3&dateRange=all&userID=&numResults=15
Hope it helps
Regard
Helios -
Reg: UNIX shell script at File Adapter
Hi all,
I am doing a File to file scenario and using command line arguments in Sending file adapter. I am using UNIX shell script ".sh" file for executing the command.
I gave the following path at "Run OS command before message processing" parameter:
/temp/xidelivery/send/FILOSC004_shell.sh
and this file contains following code:
<b>#!/user/bin/sh cp /temp/xidelivery/send/FILOSC004_in.txt /temp/xidelivery/send/FILOSC004_input_copy4.txt</b>
I put the source file, FILOSC004_in.txt and shell script files at the respective paths.
If I give "cp" command directly in command line it is working fine. But I could not execute this with shell script. Can any body give me the reason where I gone wrong.
Regards,
Pavani.Hi,
can you try this,
bash /temp/xidelivery/send/FILOSC004_shell.sh
let me know.
hey you can check the blog below to catch the OS errors,
/people/michal.krawczyk2/blog/2005/08/17/xi-operation-system-command--error-catching
Prasad Babu.
Message was edited by:
PrasadBabu Koribilli -
Hi Friends ,
I have run shell scripts for importing from my local system through TELNET It was running fine on the server.But now I need to import the same dump file into my local database.The ORACLE_SID refering to the database in the server is same as the database in my local system.
So how to tell through the scripts that I need to connect to my local system.
If anyone could explain this it could be of great help.
Regards
Marlon.Hi
It depends on how your script is taken care on syntax of import/export. I can tell you exaxtly if you can past me your import/export shell script. However for your knowlege, you can specify ORACLE_SID with export/import with following ways
1) exp user/pass@ORACLE_SID file=<file_name> log=<logfile>
imp user/password@ORACLE_SID file=<dumpfile> fromuser=<username> touser=username
if you are at same box where oracle server is intalled then you need not to mention oracle_SID but make sure that ORACLES_SID is configured in environment variable.
All the best
Alok -
new to shell scripting, and looking for good source to learn this, if someone can guide me...
Re: shell scripting for oracle DBs
-
Hi all,
I need to run shell script on one of linux servers while executing some IdM workflow.
There is no need to manage that server/ provision accounts / reset passwords etc but just to run the script and to process the result.
I have IdM 8.04 installed on Windows Machine.
What are my options to achieve that mission?
Thank You,
Alex.I was considering a situation similar to AD after actions where sometimes we execute a dos batch file for any specific purpose like creating home folder using mkdir. I was thinking on similar lines if your shell script is also for a specifc function similar to the one I mentioned above and if it is applicable in windows environment, you might covert that into a dos batch and do similar to an after action.
Since you need your shell script to be run in UNIX / LINUX machine, I do not see any other way other than writing a java class and invoke within a wf as it was mentioned by etech or if you are planning on using any of the out of the box resource adapters, the AIX resource adapter reference might help, but I have not worked with that -
Need advice on shell scripting
If my message is better suited for a more specific group, please suggest it.
I have a job opportunity: managing a lab of mixed Windows and Macintosh desktops. Two job requirements are:
* Experience administering and deploying server hardware and software
* Proficiency with scripting languages, e.g. perl, python, shell
My question: what sort of shell scripting is typical for this sort of work?
I'll be grateful for any help.
Cheers,
noob81At the entry level, administering operating systems via scripting involves managing filesystems, applications and users.
I would suggest to pick a book on "Administration" and on "Scripting" and this should provide an idea on what is being administered and what could be scripted.
For Windows, look for guides on "command-line administration" and "vbscript/powershell scripting".
For Mac, the below link should get you started.
http://images.apple.com/server/macosx/docs/IntroCommand_Line_Adminv10.6.pdf -
Can we call shell script from oracle 9i?
Hi experts,
I wanted to know can we call shell script from oracle 9i procedures? If yes,how
Thanks
ShaanNo. I can't think of a way to do this...
If you want you can use DBMS_SCHEDULER to call OS SHELL scripts within.
For e.g.
CREATE PROGRAM
begin
dbms_scheduler.create_program
program_name => 'CHECK_TIME',
program_type => 'EXECUTABLE',
program_action => '/opt/oracle/chk_date.sh',
enabled => TRUE,
comments => 'Check the Time'
end;
CREATE A SHELL SCRIPT
opt/oracle> cat chk_date.sh
#!/usr/bin/ksh
echo "The date is :`date`"
CREATE SCHEDULE
begin
dbms_scheduler.create_schedule
schedule_name => 'EVERY_30_MINS',
repeat_interval => 'FREQ=MINUTELY; INTERVAL=30',
comments => 'Every 30-mins'
end;
CREATE JOB
begin
dbms_scheduler.create_job
job_name => 'RUN_CHECK_TIME',
program_name => 'CHECK_TIME',
schedule_name => 'EVERY_30_MINS',
comments => 'Run the program CHECK_TIME every 30 minutes',
enabled => TRUE
end;
MANUALLY RUN A JOB
exec dbms_scheduler.run_job('RUN_CHECK_TIME'); -
Hi,
We had the shell script below created for our school last year to keep the students from jumping off of our wireless network so they had to go through our content filters. We put the script on all of the student laptops (MacBooks and MacBook pros) so it ran as a process in the background. It worked beautifully for the whole year.
Now we are in the process of upgrading our laptops from Snow Leopard to Lion and we've discovered that the script no longer works in Lion. I am guessing it is something simple but I don't see it. Does anyone know what about the OS changed that would cause this script to stop working?
Thanks
Tim
#!/bin/sh
currentSSID=`networksetup -getairportnetwork Airport | awk {'print $4'}`
if [ "$currentSSID" = "optimumwifi" ] ; then
echo "Disassociating.."
/System/Library/PrivateFrameworks/Apple80211.framework/Versions/A/Resources/ai rport --disassociate
networksetup -setairportnetwork Airport "Student" "only4study!"
fi
if [ "$currentSSID" = "timewarnercablewifi" ] ; then
echo "Disassociating.."
/System/Library/PrivateFrameworks/Apple80211.framework/Versions/A/Resources/ai rport --disassociate
networksetup -setairportnetwork Airport "Student" "only4study!"
fi
if [ "$currentSSID" = "xfinitywifi" ] ; then
echo "Disassociating.."
/System/Library/PrivateFrameworks/Apple80211.framework/Versions/A/Resources/ai rport --disassociate
networksetup -setairportnetwork Airport "Student" "only4study!"
fiBrilliant, that worked perfectly! Thanks for the your help Linc.
Coincidentally, I found a posting on the website stackexchange.com that helped explain why it stopped working in the first placed and why "Airport" alone used to work in Snow Leopard.
Note what it says at the bottom:
"the port name is Wi-Fi on 10.7 and AirPort on 10.6. The device name can be at least en0,en1, or en2 depending on your setup."
http://apple.stackexchange.com/questions/36891/bash-script-to-toggle-wifi-in-lio n -
About shell scripts for large-scale automation of encoding tasks
in the user menu of Compressor, it said that we can use the command line to write shell scripts for large-scale automation of encoding tasks.
I would like to have more information about the shell script for compressor, is that any document link?
ThanksYou can use a script function to set-up a more secure environment that you call at the start of every admin script. This could be your main stamp album for stuff that can be moved there.
A few more stamps to add to the collection (be sure to read up on them before use):
1) reset the command hash
hash -r
2) prevent core dumps
ulimit -H -c0
3) set the IFS
4) clear all aliases (see unalias -a)
Also you can remove the ALL from sudo and add explicit commands to the the sudoers file. There's a lot of fine tuning you can do in sudoers - inc. env variables as teekay said.
But I'm no expert so best to check all of the above.
Maybe you are looking for
-
No longer able to save Word documents - older Macbook
When I have tried to save multiple Word documents recently, I get this message: "Word cannot save or create this file. The disk may be full or write-protected. Try one or more of the following: *Free more memory *Make sure that the disk you want to s
-
2 optical drives on a powermac G4?
I see 2 optical drive 'doors' on the front of my G4. I use only one (CD - DVD) What is the other one for?
-
Photos app on 10.10.3 and on iOS 8.3 shows wrong location
I have a set of photos shot in my living room in Riverside, CA, and all of them have similar GPS coordinates stored in the photos, around 33 deg 59' N, 117 deg 19' W, which is right in Riverside. For some strange reason, two of the photos register as
-
Freeform shapes in Keynote/Mac Editable on Keynote/iPad
I need to create editable freeform shapes on the iPad. Keynote/iPad does not do this, but Keynote '09/Mac does. Are freeform shapes created on Keynote/Mac editable (move, change points of shape, edit text, change color/border) on Keynote/iPad?
-
Hi All , I am new to Oracle SOA management pack , We have a requirement to install SOA management pack , for that we have a CD which contains the below folders , can any one suggest us how to proceed ? EM 10-2-0-5-V16512-01_1of2 EM 10-2-0-5-V16512-01