Archive

Archive for the ‘Linux’ Category

moves files in unix from a date range to a different directory

June 7, 2013 2 comments
you can achive your date-based move with the following commands. (But
beware, find reports also files in sub directories, which will cause possible
problems with the mv command)

touch -t 201204192359 limit_begin  [YYYYMMDDHHSS]
touch -t 06082359 limit_end        [MMDDHHSS] If not year is specified it take current year

find . -newer limit_begin -a ! -newer limit_end -a -type f -exec mv {}
/otherdir \;

if you have many subdirs you could use sed to handle your task. In this case
the strings limit_begin and limit_end must be unique in the output of
ll -tr.

for file in `ll -tr | sed -n '/limit_begin/,/limit_end/p' | sed -n '/^-/p' |
awk '{ print $9}'`
do
mv $file /otherdir
done

Find files that a 14 days old from the current time and tar the files up , do not descend into directories

find . -maxdepth 1 -type f -mtime -14   | xargs tar cvf EMGC_OMS1_logs.tar
Advertisements
Categories: Linux

create ssh trust between HP-UX and Tru64

January 28, 2011 Leave a comment

On HP-UX


su - oracle

cd .ssh

ssh-keygen -t dsa

ssh-keygen -e -f id_dsa.pub > id_dsa2_`hostname`.pub

cat id_dsa2_`hostname`.pub

On Tru64


su - oracle

cd .ssh2

vi id_dsa2_<hp-ux-servername>.pub

Copy and paste the output of the cat id_dsa2_`hostname`.pub command from hp-ux in to this file and save it

echo "Key id_dsa2_<hp-ux-servername>.pub" >> authorization

This should allow login to tru64 from hp-ux without prompting you for a password. However scp wont work due to the incompatibilities between hp-ux and Tru64.

If you need to transfer files you can use sftp but it no good if you want to tranfer directories and subdirectories. The way round it is to do the following

If you have secure shell (ssh) access to both hosts, there is a pretty easy way to move an entire directory structure from host A to host B in one line:

from host A:
tar -cf - directory | ssh user@hostB "cd target_dir; tar -xf -"

Where directory is the directory you want to move and target_dir is the destination directory on the remote host.</div>

Another option would be to setup rsync


rsync -aE -e ssh directory user@hostB:target_dir

or from hostB

rsync -aE -e ssh user@hostA:directory target_dir

You can also use the z (--compress) switch to rsync if network throughput is an issue.

Categories: Linux

/bin/rm: Argument list too long.

October 11, 2010 Leave a comment

Guess rm cant handle more than 1024 arguments

Workaround

Filename with no spaces 
find . -name '*.aud' | xargs rm 
Filename with spaces 
find . -name '*.aud' -print0 | xargs -0 rm
Categories: Linux

making rman backups available to standby server

April 12, 2010 Leave a comment

primary server: linuxdbpr

dr server: linuxdbdr

Create an NFS mount from the target (primary) server to the standby (auxiliary) database server

Logged in as root on the primary server

edit /etc/exports

Add the following for themachine you want to be able to mount

/dbbackup/dbpr01    linuxdbpr(rw,no_root_squash)

After making chages to the /etc/export file , you need to restart the NFS daemon  on the primary server


[root@linuxdbpr init.d]# /etc/init.d/nfs restart
Shutting down NFS mountd:                                  [FAILED]
Shutting down NFS daemon:                                  [FAILED]
Shutting down NFS quotas:                                  [FAILED]
Shutting down NFS services:                                [FAILED]
Starting NFS services:                                     [  OK  ]
Starting NFS quotas:                                       [  OK  ]
Starting NFS daemon:                                       [  OK  ]
Starting NFS mountd:                                       [  OK  ]

log on to the standby server as the root user


#mkdir -p /dbbackup/dbpr01

[root@linuxdbdr dbpr01]# /etc/init.d/nfs start
Starting NFS services:                                     [  OK  ]
Starting NFS quotas:                                       [  OK  ]
Starting NFS daemon:                                       [  OK  ]
Starting NFS mountd:                                       [  OK  ]

[root@linuxdbpr init.d]# mount -t nfs linuxdbpr:/dbbackup/dbpr01  /dbbackup/dbpr01

[root@linuxdbdr dbpr01]# ls -lrt
total 1497016
-rw-rw---- 1 10617 dba 1401839616 Apr 11 21:00 53laspf4_1_1
-rw-rw---- 1 10617 dba   99670016 Apr 11 21:00 56laspgb_1_1
-rw-rw---- 1 10617 dba    9994240 Apr 11 21:01 c-757662351-20100411-01
-rw-r----- 1 10617 dba    9912320 Apr 12 09:31 snapcf_STRIPEPR.f
-rw-r----- 1 10617 dba    9994240 Apr 12 09:31 c-757662351-20100412-00
Categories: Linux

Using Rlwrap for Sqlplus

January 26, 2010 Leave a comment

rpm package for SUSE compatible    (x86_64) distribution you can download here.

su –

# rpm -ivh rlwrap-0.30-suse.x86_64.rpm
# exit
echo “alias sqlplus=’rlwrap sqlplus'” >> /home/oracle/.bash_profile
. /home/oracle/.bash_profile
Categories: Linux, Oracle

Kill all Oracle sessions

November 13, 2009 Leave a comment
set pagesize 0
spool kill_all.sql
select 'alter system kill session '''||sess.sid||', '||sess.serial#||''';' from v$session sess where username = 'OLASADM';
spool off
spool kill_all.log
@kill_all.sql
spool off
ps -ef |grep AEGDWHPR | grep NO | grep -v grep | awk '{print $2}' | xargs kill -9 
SELECT c.sid, c.serial#, p.spid,
'ALTER SYSTEM KILL SESSION '''||c.sid||', '||c.serial#||
''' IMMEDIATE;' as ''KILL in ORACLE'',
'kill -9 '||p.spid as ''KILL in UNIX '',
c.STATUS, c.program, c.osuser,  c.machine, c.process, c.username
FROM
sys.v_$session c,
sys.v_$process p,
sys.user$ u
WHERE c.paddr = p.addr
AND u.user# = c.user#
AND c.username is not null
ORDER BY c.sid
/
Categories: Linux

Cleanup any unwanted trace files

November 13, 2009 Leave a comment

Cleanup any unwanted trace files more than seven days old

find . *.trc -mtime +7 -exec rm {} \;

If you get the following error

-bash: /usr/bin/find: Argument list too long

Move one level up and run the following command

find ./trace  -type f  -name *.trc -mtime +3 -exec rm {} \;

Categories: Linux