Showing posts with label skrypt. Show all posts
Showing posts with label skrypt. Show all posts

Monday, 11 December 2017

Ansible - multiple if else statement or case alternative

Ansible prefer to use when: statement and not have classic implementation of if else or case statement

To use many if statement you can use simple trick.
Example check many variables and depend of this value (if variable is different than empty string '') counting latest occurrence of "not null" value


- name: count number of nic
  vars:
    count_nic: "{{ 5 if NETWORK_5 != '' else '4' if NETWORK_4 != '' else '3' if NETWORK_3 != '' else '2' if NETWORK_2 != '' else '1'}}"
#import playbook based on variable
  include: tasks/nic_{{ count_nic }}.yml
  register: count_nic

Ansible - Restart server and wait until available

Since ansible 2.3 you can use wait_for_connection function to check when host will be available

Example:

- name: Reboot server
  shell: ( sleep 2 && shutdown -r now & )
  async: 1
  poll: 0
  ignore_errors: true

- name: Waiting for host {{ ansible_default_ipv4.address }} after reboot
  wait_for_connection:
    timeout: 300
    delay: 30


This example solve your problem :-)

Ansible "The destination directory (/etc) is not writable"

I've used ansible playbook:

- name: copy resolv.conf
  become: root
  become_method: sudo
  copy:
    src: "resolv.conf"
    dest: "/etc/resolv.conf"
    owner: root
    group: root
    mode: 0644
    force: yes


Error "The destination directory (/etc) is not writable" occur

The problem is with function become - this function require true or false as parameter

Working configuration is  (SOLVED)

- name: copy resolv.conf
  become: yes
  become_method: sudo
  copy:
    src: "resolv.conf"
    dest: "/etc/resolv.conf"
    owner: root
    group: root
    mode: 0644
    force: yes
roles/os_conf_dn

Monday, 29 December 2014

Configure bamboo with NEXUS - Sonatype

I use for configuration bamboo 5.7.1 and all configuration will be done from script - I not use plugins

First I prepare build project consists from 2 stages
- one for prepare package - for example zip file
- two for update package to repository - NEXUS

When I have zip file to upload to NEXUS I use NEXUS api to upload file
#use timestamp to versioning
VERSION=`echo "${bamboo.buildTimeStamp}" | sed 's/:/-/g' | cut -f 1 -d "."`
#uploadcurl -v \
   -F "r=releases" \ 
   -F "g=pl.company.sql" \ 
   -F "hasPom=false" \
   -F "a=db" \
   -F "c=${bamboo.buildResultKey}" \
   -F "p=zip" \    -F "v=$VERSION" \
   -F "file=@./$f" \
   -u  deployment:${bamboo.nexuspassword}\ 
   http://service/nexus/service/local/artifact/maven/content
important is use classifier

or You can use MAVEN

Second - download script for deployment project

#Fix mapping between buildResultKey
CLASS=`echo ${bamboo.buildResultKey} | sed 's/-/-RDP-/2'`
-For more information see post below and continue
#find package by classifier
VERSION=`curl -u  deployment:${bamboo.nexuspassword} "http://service/nexus/service/local/lucene/search?g=$GROUP&a=$ARTIFACT&c=$CLASS&r=$REPO" | sed -n 's|<version>\(.*\)</version>|\1|p' | sed -e 's/^[ \t]*//' -e 's/[ \t]*$//'`

#Download by wget
wget -O db-sprint.zip --user deployment --password=${bamboo.nexuspassword} "http://service/nexus/service/local/artifact/maven/content?r=$REPO&g=$GROUP&a=$ARTIFACT&v=$VERSION&p=zip&c=$CLASS"



Configure mapping between build project and deployment project in Bamboo

Atlassian Bamboo don't have formal mapping between build project and deployment project but you can use buildResultKey - it constain number of build which is constant.

I create build plan and deployment plan in deployment plan set to update buildResultKey to be correct for deployment plan

echo ${bamboo.buildResultKey} | sed 's/-/-JOB1-/2'

You shoud list buildResultKey variable in build project and deployment project and check difference - for me it is JOB1

Monday, 13 January 2014

FC target configuration - Targetcli as open source SAN (debian)

Installation on debian wheezy with kernel 3.10.25

Download rpm
apt-get install targetcli 

Or install without recommended packages
apt-get install --no-install-recommends targetcli

Create file for datastore
dd if=/dev/zero of=/opt/test1 bs=1024 count=6000000



targetcli

Create datastore on targetcli
cd backstores/fileio
create itest1 /opt/test1 6144000000B

Create iSCSCI target instance
cd /iscsi
create

Map LUN to datastore (based on FILEIO)
cd luns
create /backstores/fileio/itest1

Configure ACL (check WWN in openiscsi section)
cd ../../acls
create
create iqn.1993-08.org.debian:01:dcb3d359cc91

Save configuration
cd /
saveconfig

Disable athentication
cd iscsi/
set set discovery_auth enable=0
cd /iscsi/iqn.2003-01.org.linux-iscsi.sc-azl-001.x8664:sn.8b4b5e8c13a2/tpgt1
set attribute authentication=0

Configure interface
cd portals
create
cd /
saveconfig
All config should looks like:

targetcli
ls
o- / ......................................................................................................... [...]
  o- backstores .............................................................................................. [...]
  | o- fileio ................................................................................... [1 Storage Object]
  | | o- idisk ............................................................................. [/opt/test1 activated]
  | o- iblock ................................................................................... [0 Storage Object]
  | o- pscsi .................................................................................... [0 Storage Object]
  | o- rd_dr .................................................................................... [0 Storage Object]
  | o- rd_mcp ................................................................................... [0 Storage Object]
  o- iscsi .............................................................................................. [1 Target]
  | o- iqn.2003-01.org.linux-iscsi.sc-azl-001.x8664:sn.8b4b5e8c13a2 ........................................ [1 TPG]
  |   o- tpgt1 ........................................................................................... [enabled]
  |     o- acls ........................................................................................... [1 ACLs]
  |     | o- iqn.1993-08.org.debian:01:dcb3d359cc91 ................................................. [1 Mapped LUN]
  |     |   o- mapped_lun0 ............................................................................. [lun0 (rw)]
  |     o- luns ............................................................................................ [1 LUN]
  |     | o- lun0 ..................................................................... [fileio/idisk (/home/test1)]
  |     o- portals ...................................................................................... [1 Portal]
  |       o- 192.168.42.135:3260 .............................................................................. [OK]
  o- loopback ........................................................................................... [0 Target]
  o- qla2xxx ............................................................................................ [0 Target]
  o- tcm_fc ............................................................................................. [0 Target]


OpeniSCSI installation - client (initiatior)

aptitude install open-iscsi
/etc/init.d/open-iscsi restart

Search target name:
iscsiadm -m discovery -t sendtargets -p 192.168.42.135

Check your initiator name

cat /etc/iscsi/initiatorname.iscsi
## DO NOT EDIT OR REMOVE THIS FILE!
## If you remove this file, the iSCSI daemon will not start.
## If you change the InitiatorName, existing access control lists
## may reject this initiator.  The InitiatorName must be unique
## for each iSCSI initiator.  Do NOT duplicate iSCSI InitiatorNames.
InitiatorName=iqn.1993-08.org.debian:01:dcb3d359cc91



iscsiadm -m node

Connect to iscsi target:
iscsiadm -m node --targetname "iqn.2003-01.org.linux-iscsi.sc-azl-001.x8664:sn.8b4b5e8c13a2" --portal "192.168.42.135:3260" --login

Verify new block device
dmesg | tail

Debian wheezy kernel upgrade to 3.10 installation

Install packages needed to compile:

apt-get install fakeroot build-essential ncurses-dev

Download and unpack kernel

wget https://www.kernel.org/pub/linux/kernel/v3.x/linux-3.10.25.tar.bz2
tar -xvf linux-3.10.25.tar.bz2
cd linux-3.10.25/

Configure kernel base on old configuration
cat /boot/config-`uname -r` > .config
cat .config
make oldconfig
make menuconfig

Compile kernel

time make deb-pkg -j2

Install
dpkg -i ../linux-firmware-image_3.10.25-1_amd64.deb ../linux-headers-3.10.25_3.10.25-1_amd64.deb ../linux-libc-dev_3.10.25-1_amd64.deb ../linux-image-3.10.25_3.10.25-1_amd64.deb
apt-cache policy linux-libc-dev

restart debian

Tuesday, 29 October 2013

Convert logs to cvs with exclude some columns

Param (

$FILE_IN="access.log",
$FILE_OUT="access.csv",
$FILE_TMP="tmp.csv"
)

$datetime = get-date -f yyddMM-hhmm

cat $FILE_IN | where { $_ -match "^[0-9]"} | % { $_ -replace '\s+',"," } | foreach {Write-output "$(($_ -split ',')[1,4,5])" } | % { $_ -replace '\s+',"," } | Out-File -append -filePath $FILE_TMP

$FILE_OUT=$FILE_OUT.replace("csv",$datetime + ".csv")
Write-output $FILE_OUT
Copy-Item $FILE_TMP $FILE_OUT


Tuesday, 25 September 2012

Loop xargs

$ find . -iname "*.mp3" -print0 | xargs -0 -I mp3file mplayer mp3file

Connect to iscsi disk debian

List device
iscsiadm -m discovery -t st -p 192.168.42.236

192.168.42.236:3260,1 iqn.2012-08.sc-nas-004.istgt:disk1

Connect:
iscsiadm -m discovery -t st -p 192.168.42.236 "iqn.2012-08.sc-nas-004.istgt:disk2" --portal "192.168.42.236:3260" --login

Monday, 24 September 2012

Recreate controlfile - change oracle database sid

From sqlplus
alter database backup controlfile to trace;


From trace (trace location you can find in alert_log)

#change reuse to set and remove controlfile

STARTUP NOMOUNT
CREATE CONTROLFILE SET DATABASE "DM02DEV" RESETLOGS  NOARCHIVELOG
    MAXLOGFILES 16
    MAXLOGMEMBERS 3
    MAXDATAFILES 100
    MAXINSTANCES 8
    MAXLOGHISTORY 292
LOGFILE
  GROUP 1 '/data/s_ora01dmdev/oradata/dm02dev/redo01.log'  SIZE 50M BLOCKSIZE 512,
  GROUP 2 '/data/s_ora01dmdev/oradata/dm02dev/redo02.log'  SIZE 50M BLOCKSIZE 512,
  GROUP 3 '/data/s_ora01dmdev/oradata/dm02dev/redo03.log'  SIZE 50M BLOCKSIZE 512
-- STANDBY LOGFILE
DATAFILE
  '/data/s_ora01dmdev/oradata/dm02dev/system01.dbf',
  '/data/s_ora01dmdev/oradata/dm02dev/sysaux01.dbf',
  '/data/s_ora01dmdev/oradata/dm02dev/undotbs01.dbf',
  '/data/s_ora01dmdev/oradata/dm02dev/users01.dbf'
CHARACTER SET AL32UTF8
;


ALTER DATABASE OPEN RESETLOGS;

ALTER TABLESPACE TEMP ADD TEMPFILE '/data/s_ora01dmdev/oradata/dm02dev/temp01.dbf'
     SIZE 39845888  REUSE AUTOEXTEND ON NEXT 655360  MAXSIZE 32767M;

Rman backup script

#!/bin/bash

export ORACLE_SID=orcl_1
export ORACLE_BASE=/u01/app/oracle
export PATH=/u01/app/oracle/database/product/11.2.0/dbhome_1/bin:/u01/app/11.2.0/grid/bin:/usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:/home/oracle/bin
export ORACLE_HOME=/u01/app/oracle/database/product/11.2.0/dbhome_1

basedir=/u01/app/oracle/backup
host=`hostname`
backup_dir=`date '+%Y.%m.%d'`

filename=`date '+%Y.%m.%d_%H.%M.%S'`

test -d ${basedir}/${host}/${backup_dir} || mkdir -p ${basedir}/${host}/${backup_dir}


if [ "x$1" = "x0" -o "x$1" = "x1" ]; then
inclevel=$1

rman target / log=${basedir}/${host}/${backup_dir}/backup_${filename}.log << !
run {
allocate channel c1 device type disk;
allocate channel c2 device type disk;
allocate channel c3 device type disk;
allocate channel c4 device type disk;
backup as compressed backupset incremental level ${inclevel} database format '${basedir}/${host}/${backup_dir}/data_lv${inclevel}_${filename}.%U';
backup as compressed backupset archivelog all delete all input format '${basedir}/${host}/${backup_dir}/arch_${filename}.%U';
backup as compressed backupset current controlfile format '${basedir}/${host}/${backup_dir}/control_${filename}.%U';
backup spfile format '${basedir}/${host}/${backup_dir}/spfile_${filename}.%U';
delete noprompt obsolete recovery window of 7 days;
}
!

else

rman target / log=${basedir}/${host}/${backup_dir}/backup_${filename}.log << !
run {
allocate channel c1 device type disk;
allocate channel c2 device type disk;
backup as compressed backupset archivelog all delete all input format '${basedir}/${host}/${backup_dir}/arch_${filename}.%U';
backup as compressed backupset current controlfile format '${basedir}/${host}/${backup_dir}/control_${filename}.%U';
backup spfile format '${basedir}/${host}/${backup_dir}/spfile_${filename}.%U';
delete noprompt obsolete recovery window of 7 days;
}
!

fi

Friday, 4 November 2011

Wylistowanie userów i ich dropowanie

select 'drop user ' || username || ' cascade; ' FROM DBA_USERS;

odświeżenie statystyk na bazie danych oracle

dbms_utility.analyze_schema(schema=>'INSIS',method=>'ESTIMATE',estimate_percent=>5);

Odblokowanie statystyk na tabelach oracle'a

select 'exec DBMS_STATS.UNLOCK_TABLE_STATS(''' || owner ||''' ,''' || table_name || '''); ' from dba_tab_statistics where stattype_locked is not null and owner not in ('SYS','SYSTEM');

Czyszczenie REDO logów

run {
crosscheck archivelog all;
delete expired archivelog all;
}

run {
BACKUP ARCHIVELOG ALL;
DELETE COPY OF ARCHIVELOG ALL COMPLETED BEFORE 'SYSDATE-1';
}

run {
DELETE NOPROMPT ARCHIVELOG ALL COMPLETED BEFORE
'sysdate-10/24'; ---kasuje wszystkie z przed 13h
}

uruchomienie RMANa

rman TARGET sys/

Oznaczenie w rmanie przeterminowanych redo logów na sysdate -1

set serveroutput on;

spool /tmp/output_del_logs.txt

declare CURSOR cur IS
SELECT a.name
FROM v$asm_alias a, v$asm_file b
where a.group_number = b.group_number
and b.creation_date < sysdate-1
and a.file_number = b.file_number
and b.type='ARCHIVELOG'
and a.name like '%.arc'
order by a.name;

sqlstr VARCHAR2(250);

BEGIN
FOR cur_rec IN cur
LOOP
sqlstr := 'alter diskgroup ASM_BACKUP drop file ''+ASM_BACKUP/DB1/' || cur_rec.name || '''';
DBMS_OUTPUT.PUT_LINE(sqlstr);
EXECUTE IMMEDIATE sqlstr;
END LOOP;
END;
/

spool off;
exit

Zamiana ciągu znaków w plikach o podanej nazwie

Aby zmienić ciąg znakow w plikach o nazwie name*, można użyć poniższego polecenia.

find . -name 'name*' -exec sed -i 's/first/second/g' '{}' \;

Można dodać opcję wyszukiwania w plikach
find . -type f -name '*.xdo' -exec sed -i 's/first/second/' '{}' \;

Tuesday, 27 September 2011

Zmiana hasła weblogic

Zmiana hasła dla konta administracyjnego weblogica w wersji 10.3


# set environment variables
export MWHOME=/u01/app/oracle/product/middleware
export DOMAIN_HOME=$MWHOME/user_projects/domains/base_domain
export CLASSPATH=$CLASSPATH:$MWHOME/wlserver_10.3/server/lib/weblogic.jar
cd $DOMAIN_HOME/bin
. ./setDomainEnv.sh
 
# creating a new default authenticator
 
cd ../security
mv DefaultAuthenticatorInit.ldift oldDefaultAuthenticator
java weblogic.security.utils.AdminAccount weblogic mynewpass .
 
# removing boot.properties if exists
cd ../servers/AdminServer
mv data data_old
cd security/
mv boot.properties oldboot.properties
 
# restart the admin server with the new password
cd $DOMAIN_HOME
./startWebLogic.sh