Strange question, right? You should know you applications and databases and how everything works, right?
Happen that some days ago a client requested me to identify from which database is a service_name. Easy? Not if the server have 46 database instances running…
Ok, now how can I can this information as quick as possible?
I know that the command below give me all distinct databases in CRS:
/u01/app/188.8.131.52/grid/bin/crsctl stat res -t -w "TYPE = ora.database.type"
Now, lets make some sed magic:
[root@nprd01dbadm01 ~]# /u01/app/184.108.40.206/grid/bin/crsctl stat res -t -w "TYPE = ora.database.type" |grep ora. |sed 's/ora./srvctl status service -d /' |sed 's/.db/ |grep \$1/' | head -1
srvctl status service -d dba |grep $1
As you know, since 11g we have a Automatic Diagnostic Repository (ADR). To better manage it, we also have a Command-line Interface, called ADRCI.
ADR contains all diagnostic information for database (logs, traces, incidents, problems, etc).
It’s not so pretty and Oracle has the Oracle Restart services for that. But to a temporary and quick need, this script solve the problem:
if ps -fu oracle | grep -v grep | grep ora_smon_orcl >/dev/null
echo "orcl instance is up and running"
echo "orcl instance is down"
sqlplus /nolog > /dev/null 2>&1 <<EOF
conn / as sysdba
cat /var/log/mysqld.log |grep `date +%y%m%d` | grep "\[Warning\]"
cat /var/log/mysqld.log |grep `date +%y%m%d` | grep "\[ERROR\]"
And a Bonus!
To get entries from X days ago:
cat /var/log/mysqld.log |grep `date --date="46 days ago" +%y%m%d`
We all faced that situation when we have to make a logical backup/export and haven’t so much area to do that, right?
We know the export usually compress a lot on zip/gzip… It wouldn’t be great if we can export directly to compressed file?
This situation become much more common because of Datapump, that requires a directory accessible by database server. If you have not possibility to make a mounting point or any other area, this can help…
## BKP with MKNOD
mknod bkp_$DATE.dmp p
gzip bkp_$DATE.dmp.gz &
### Uncomment and Ajust one of:
#mysqldump -u $user -p$password $database > bkp_$DATE.dmp
## Oracle (Datapump or EXP)
expdp \"/ as sysdba\" dumpfile=bkp_$DATE.dmp full=y directory=DIRECTORY_EXAMPLE logfile=log_bkpzipped.log compress=y
#expdp $user/$password dumpfile=bkp_$DATE.dmp full=y directory=DIRECTORY_EXAMPLE logfile=log_bkpzipped.log
#exp \"/ as sysdba\" file=bkp_$DATE.dmp log=log_bkpzipped.log compress=y [tables=owner.table,..] [owner=schema1,..] [...]
I frequently have to search about shellscript syntax (things like conditions and comparatives).
Shellscripting is not a daily routine, but sometimes it’s needed and I never remmember from the last time…
For those kind of people, this link/book shall be very helpful 🙂
(it’s in portguese, but everyone will understand…)
Thanks for this tools, Aurelio!
Have a nice week guys!
You want recursive change one string to another, it’s simple, you need a list with full file name path called ‘output_list’, and run command bellow:
cat output_list|while read line;
cp -p $line $line.bkp;
cat $line |sed ‘s/SOURCE_STRING/TARGET_STRING/g’ > $line.bkp && mv $line.bkp $line;
Keep in mind it’s a DANGEROUS command, double check your file list, and if necessary, make a full backup from you system.
It will run on UNIX(ES) and Linux.