From 4c51d0091959e554043f9595bca526fbec0412fb Mon Sep 17 00:00:00 2001 From: support Date: Thu, 12 Mar 2026 21:51:59 +0100 Subject: [PATCH] 2026-03-12 20:51:59 --- bash/Readme.md | 1 + bash/adrci_purge.sh | 16 ++ bash/backup_tiddly_notes.sh | 11 ++ bash/cifs_veracrypt_resilio_start | 63 ++++++++ bash/cifs_veracrypt_resilio_stop | 13 ++ bash/clean_vm.sh | 19 +++ bash/crdb.sh | 135 ++++++++++++++++ bash/crdb.sh.2024-06-16 | 142 +++++++++++++++++ bash/crdb.sh.2026-02-21 | 135 ++++++++++++++++ bash/kvm_dump_guest_xml.sh | 2 + bash/oracle_path_swgalaxy.sh | 7 + bash/quemu-mount.sh | 17 ++ bash/vmclone.sh | 111 +++++++++++++ divers/oracle_RAT_01.md | 120 ++++++++++++++ divers/oracle_RAT_01.txt | 93 +++++++++++ divers/oracle_autoupgrade_01.txt | 139 +++++++++++++++++ divers/oracle_clone_using_lv_snap_01.txt | 43 +++++ divers/oracle_ressource_manager_01.txt | 128 +++++++++++++++ divers/sql_quarantine_01.md | 62 ++++++++ divers/tmp_script.sql | 30 ++++ divers/vminfo.txt | 19 +++ notes.txt | 0 push_all | 5 + python/01.py | 0 python/DomainUpdater/DomainUpdater.2019-07-01 | 128 +++++++++++++++ python/DomainUpdater/DomainUpdater.conf | 9 ++ .../DomainUpdater.conf.2020-12-23 | 8 + .../DomainUpdater.conf.2021-01-15 | 9 ++ python/DomainUpdater/DomainUpdater.py | 147 ++++++++++++++++++ .../DomainUpdater/DomainUpdater.py.2020-12-23 | 126 +++++++++++++++ .../DomainUpdater/DomainUpdater.py.2021-12-05 | 136 ++++++++++++++++ .../__pycache__/DomainUpdater.cpython-36.pyc | Bin 0 -> 3795 bytes python/Readme.md | 2 + python/scr_cod_dec/code.py | 15 ++ python/scr_cod_dec/decode.py | 34 ++++ 35 files changed, 1925 insertions(+) create mode 100644 bash/Readme.md create mode 100644 bash/adrci_purge.sh create mode 100644 bash/backup_tiddly_notes.sh create mode 100644 bash/cifs_veracrypt_resilio_start create mode 100644 bash/cifs_veracrypt_resilio_stop create mode 100644 bash/clean_vm.sh create mode 100644 bash/crdb.sh create mode 100644 bash/crdb.sh.2024-06-16 create mode 100644 bash/crdb.sh.2026-02-21 create mode 100644 bash/kvm_dump_guest_xml.sh create mode 100644 bash/oracle_path_swgalaxy.sh create mode 100644 bash/quemu-mount.sh create mode 100644 bash/vmclone.sh create mode 100644 divers/oracle_RAT_01.md create mode 100644 divers/oracle_RAT_01.txt create mode 100644 divers/oracle_autoupgrade_01.txt create mode 100644 divers/oracle_clone_using_lv_snap_01.txt create mode 100644 divers/oracle_ressource_manager_01.txt create mode 100644 divers/sql_quarantine_01.md create mode 100644 divers/tmp_script.sql create mode 100644 divers/vminfo.txt create mode 100644 notes.txt create mode 100644 push_all create mode 100644 python/01.py create mode 100644 python/DomainUpdater/DomainUpdater.2019-07-01 create mode 100644 python/DomainUpdater/DomainUpdater.conf create mode 100644 python/DomainUpdater/DomainUpdater.conf.2020-12-23 create mode 100644 python/DomainUpdater/DomainUpdater.conf.2021-01-15 create mode 100644 python/DomainUpdater/DomainUpdater.py create mode 100644 python/DomainUpdater/DomainUpdater.py.2020-12-23 create mode 100644 python/DomainUpdater/DomainUpdater.py.2021-12-05 create mode 100644 python/DomainUpdater/__pycache__/DomainUpdater.cpython-36.pyc create mode 100644 python/Readme.md create mode 100644 python/scr_cod_dec/code.py create mode 100644 python/scr_cod_dec/decode.py diff --git a/bash/Readme.md b/bash/Readme.md new file mode 100644 index 0000000..c6cac69 --- /dev/null +++ b/bash/Readme.md @@ -0,0 +1 @@ +empty diff --git a/bash/adrci_purge.sh b/bash/adrci_purge.sh new file mode 100644 index 0000000..1aae6f2 --- /dev/null +++ b/bash/adrci_purge.sh @@ -0,0 +1,16 @@ +#!/usr/bin/bash + +AGE1MIN=0 +AGE1DAYS=1440 +AGE7DAYS=10080 +AGE10DAYS=14400 +AGE15DAYS=21600 +AGE30DAYS=43200 + +PURGETARGET=$AGE1MIN + +for f in $( adrci exec="show homes" | grep -v "ADR Homes:" ); +do + echo "Purging ${f}:"; + adrci exec="set home $f; purge -age $PURGETARGET ;" ; +done diff --git a/bash/backup_tiddly_notes.sh b/bash/backup_tiddly_notes.sh new file mode 100644 index 0000000..a5fc5fc --- /dev/null +++ b/bash/backup_tiddly_notes.sh @@ -0,0 +1,11 @@ +#!/usr/bin/bash + +DIR=/app/persistent_docker/tiddlywiki +WIKI=mywiki +BACKUPDIR=/mnt/yavin4/data/a.Very_Important_Data/backup_TiddlyWiki +DATE=`date +%Y-%m-%d_%H-%M` +cd ${DIR} +tar -cvf - ${WIKI} | gzip > ${BACKUPDIR}/${WIKI}_${DATE}.tar.gz +cd ${BACKUPDIR} +find ./ -name '${WIKI}*.tar.gz' -mtime +45 -exec rm {} \; + diff --git a/bash/cifs_veracrypt_resilio_start b/bash/cifs_veracrypt_resilio_start new file mode 100644 index 0000000..7c57158 --- /dev/null +++ b/bash/cifs_veracrypt_resilio_start @@ -0,0 +1,63 @@ +#!/usr/bin/bash + +URL_ALIVE="https://public.databasepro.fr/.secrets/alive.txt" +URL_ENC_PASS="https://public.databasepro.fr/.secrets/linux.txt" +SECRET="For#LinuxM1ntVer@crypt" + + + +RUNTIME="1 minute" +ENDTIME=$(date -ud "$RUNTIME" +%s) + +while [[ $(date -u +%s) -le $ENDTIME ]] +do + echo -n "`date +%H:%M:%S`: waiting for remote encrypyted password file.. " + ALIVE=$(curl -s ${URL_ALIVE}) + if [ "$ALIVE" == "yes" ]; then + echo "OK" + break + fi + echo "retrying in 10 seconds.." + sleep 10 +done + +if [ "$ALIVE" != "yes" ]; then + echo "Remote encrypyted password file is not available, giving up" + exit -1 +fi + + + +# Get encrypted passwords JSON from URL +JSON_ENC_PASS=$(curl -s ${URL_ENC_PASS}) + +# Decode JSON +ENC_PASS_CIFS=$(jq '.cifs' <<< "${JSON_ENC_PASS}") +ENC_PASS_VERACRYPT=$(jq '.veracrypt' <<< "${JSON_ENC_PASS}") + +# Remove first and last double quote from values +AUX="${ENC_PASS_CIFS%\"}" +AUX="${AUX#\"}" +ENC_PASS_CIFS=${AUX} + +AUX="${ENC_PASS_VERACRYPT%\"}" +AUX="${AUX#\"}" +ENC_PASS_VERACRYPT=${AUX} + +# Uncrypt passwords +PASS_CIFS=$(echo ${ENC_PASS_CIFS} | openssl enc -aes-256-cbc -md sha512 -a -d -pbkdf2 -iter 100000 -salt -pass pass:${SECRET}) +PASS_VERACRYPT=$(echo ${ENC_PASS_VERACRYPT} | openssl enc -aes-256-cbc -md sha512 -a -d -pbkdf2 -iter 100000 -salt -pass pass:${SECRET}) + +# Mount CIFS +sudo mount -t cifs //192.168.0.9/share /mnt/yavin4 -o vers=2.0,uid=smbuser,gid=smbuser,file_mode=0775,dir_mode=0775,user=vplesnila,password=${PASS_CIFS},mfsymlinks + +# Mount Veracrypt volume +veracrypt --text --mount /home/vplesnila/data/veracrypt_01.volume /mnt/rslsync --pim 0 --keyfiles "" --protect-hidden no --slot 1 --password ${PASS_VERACRYPT} --verbose + +# Start Resilio Sync +systemctl --user start resilio-sync + +# Show FS +df -hT + + diff --git a/bash/cifs_veracrypt_resilio_stop b/bash/cifs_veracrypt_resilio_stop new file mode 100644 index 0000000..5668192 --- /dev/null +++ b/bash/cifs_veracrypt_resilio_stop @@ -0,0 +1,13 @@ +#!/usr/bin/bash + +# Stop Resilio Sync +systemctl --user stop resilio-sync + +# Dismount CIFS +sudo umount /mnt/yavin4 + +# Dismount Veracrypt volume +veracrypt --text --dismount --slot 1 + +# Show FS +df -hT diff --git a/bash/clean_vm.sh b/bash/clean_vm.sh new file mode 100644 index 0000000..11e2ac1 --- /dev/null +++ b/bash/clean_vm.sh @@ -0,0 +1,19 @@ +rm -rf /app/oracle/base/admin/* +rm -rf /app/oracle/base/dbs/* +rm -rf /app/oracle/base/homes/*/dbs/* + +rm -rf /app/oracle/product/11.2/dbs/* +rm -rf /app/oracle/product/12.1/dbs/* +rm -rf /app/oracle/product/12.2/dbs/* +rm -rf /app/oracle/product/19/dbs/* +rm -rf /app/oracle/product/21/dbs/* + +rm -rf /data/* +rm -rf /reco/* + +rm -rf /home/oracle/oradiag_oracle +rm -rf /app/oracle/base/homes/OraDB19Home1/network/admin/* + +> /etc/listener.ora +> /etc/tnsnames.ora + diff --git a/bash/crdb.sh b/bash/crdb.sh new file mode 100644 index 0000000..c511740 --- /dev/null +++ b/bash/crdb.sh @@ -0,0 +1,135 @@ +#!/bin/bash + +function usage { + echo "Usage: crdb -n|--name -v|--version <19|21>" +} + +######## +# MAIN # +######## + +# parameter processing +while [ "$1" != "" ]; do + case $1 in + -n | --name ) shift + DB_NAME="$1" + ;; + -v | --version ) shift + VERSION="$1" + ;; + * ) usage + exit 1 + esac + shift +done + +if [ -z "${DB_NAME}" ] || [ -z "${VERSION}" ] +then + usage + exit -2 +fi + +# version/template selection +if [ "$VERSION" == "21" ]; then + . oraenv < ${ORACLE_BASE}/dbs/init${ORACLE_SID}.ora +fi + +if [ "$VERSION" == "19" ]; then + . oraenv < ${ORACLE_BASE}/dbs/init${ORACLE_SID}.ora +fi + + +if [ -z "${BACKUP_DIR}" ] +then + echo "No template found for this database version" + exit -1 +fi + +# admin directories creation +mkdir -p ${ORACLE_BASE}/admin/${ORACLE_SID}/adump +mkdir -p ${ORACLE_BASE}/admin/${ORACLE_SID}/pfile +mkdir -p ${ORACLE_BASE}/admin/${ORACLE_SID}/spfile +mkdir -p ${ORACLE_BASE}/admin/${ORACLE_SID}/divers + + +# init and spfile creation +cp ${BACKUP_DIR}/init${BACKUP_DB_NAME}PRD.ora ${ORACLE_BASE}/admin/${ORACLE_SID}/pfile/init${ORACLE_SID}.ora +sed -i -r "s/${BACKUP_DB_NAME}/${DB_NAME}/" ${ORACLE_BASE}/admin/${ORACLE_SID}/pfile/init${ORACLE_SID}.ora + +echo ${ORACLE_SID} +sqlplus /nolog < -v|--version <11.2.0.4|12.1|12.2|19|21>" +} + +######## +# MAIN # +######## + +# parameter processing +while [ "$1" != "" ]; do + case $1 in + -n | --name ) shift + DB_NAME="$1" + ;; + -v | --version ) shift + VERSION="$1" + ;; + * ) usage + exit 1 + esac + shift +done + +if [ -z "${DB_NAME}" ] || [ -z "${VERSION}" ] +then + usage + exit -2 +fi + +# version/template selection +if [ "$VERSION" == "21" ]; then + . oraenv < ${ORACLE_BASE}/dbs/init${ORACLE_SID}.ora +fi + +if [ "$VERSION" == "19" ]; then + . oraenv < ${ORACLE_HOME}/dbs/init${ORACLE_SID}.ora +fi + + +if [ "$VERSION" == "11.2.0.4" ]; then + . oraenv < ${ORACLE_HOME}/dbs/init${ORACLE_SID}.ora +fi + + +if [ -z "${BACKUP_DIR}" ] +then + echo "No template found for this database version" + exit -1 +fi + +# admin directories creation +mkdir -p ${ORACLE_BASE}/admin/${ORACLE_SID}/adump +mkdir -p ${ORACLE_BASE}/admin/${ORACLE_SID}/pfile +mkdir -p ${ORACLE_BASE}/admin/${ORACLE_SID}/spfile +mkdir -p ${ORACLE_BASE}/admin/${ORACLE_SID}/divers + +# not automaticly created in 11.2.0.4 +mkdir -p /data/${ORACLE_SID} + +# init and spfile creation +cp ${BACKUP_DIR}/init${BACKUP_DB_NAME}PRD.ora ${ORACLE_BASE}/admin/${ORACLE_SID}/pfile/init${ORACLE_SID}.ora +sed -i -r "s/${BACKUP_DB_NAME}/${DB_NAME}/" ${ORACLE_BASE}/admin/${ORACLE_SID}/pfile/init${ORACLE_SID}.ora + +echo ${ORACLE_SID} +sqlplus /nolog < -v|--version <19|21>" +} + +######## +# MAIN # +######## + +# parameter processing +while [ "$1" != "" ]; do + case $1 in + -n | --name ) shift + DB_NAME="$1" + ;; + -v | --version ) shift + VERSION="$1" + ;; + * ) usage + exit 1 + esac + shift +done + +if [ -z "${DB_NAME}" ] || [ -z "${VERSION}" ] +then + usage + exit -2 +fi + +# version/template selection +if [ "$VERSION" == "21" ]; then + . oraenv < ${ORACLE_BASE}/dbs/init${ORACLE_SID}.ora +fi + +if [ "$VERSION" == "19" ]; then + . oraenv < ${ORACLE_BASE}/dbs/init${ORACLE_SID}.ora +fi + + +if [ -z "${BACKUP_DIR}" ] +then + echo "No template found for this database version" + exit -1 +fi + +# admin directories creation +mkdir -p ${ORACLE_BASE}/admin/${ORACLE_SID}/adump +mkdir -p ${ORACLE_BASE}/admin/${ORACLE_SID}/pfile +mkdir -p ${ORACLE_BASE}/admin/${ORACLE_SID}/spfile +mkdir -p ${ORACLE_BASE}/admin/${ORACLE_SID}/divers + + +# init and spfile creation +cp ${BACKUP_DIR}/init${BACKUP_DB_NAME}PRD.ora ${ORACLE_BASE}/admin/${ORACLE_SID}/pfile/init${ORACLE_SID}.ora +sed -i -r "s/${BACKUP_DB_NAME}/${DB_NAME}/" ${ORACLE_BASE}/admin/${ORACLE_SID}/pfile/init${ORACLE_SID}.ora + +echo ${ORACLE_SID} +sqlplus /nolog < /mnt/yavin4/tmp/_oracle_/tmp/{}.xml" + diff --git a/bash/oracle_path_swgalaxy.sh b/bash/oracle_path_swgalaxy.sh new file mode 100644 index 0000000..123af8f --- /dev/null +++ b/bash/oracle_path_swgalaxy.sh @@ -0,0 +1,7 @@ +P1=/mnt/yavin4/tmp/_oracle_/code_gitlab/oracle/tpt +P2=/mnt/yavin4/tmp/_oracle_/code_gitlab/oracle/idev +P3=/mnt/yavin4/tmp/_oracle_/code_gitlab/oracle/vg +P4=/mnt/yavin4/tmp/_oracle_/code_gitlab/oracle/vdh +P5=/mnt/yavin4/tmp/_oracle_/code_gitlab/oracle/Kevin_Meade +P6=/mnt/yavin4/tmp/_oracle_/code_gitlab/oracle/my +export ORACLE_PATH=${P1}:${P2}:${P3}:${P4}:${P5}:${P6} diff --git a/bash/quemu-mount.sh b/bash/quemu-mount.sh new file mode 100644 index 0000000..96e4e87 --- /dev/null +++ b/bash/quemu-mount.sh @@ -0,0 +1,17 @@ +#!/bin/bash +# usage: qemu-mount {imagefile} +# 1st argument: QEMU raw image file + +if [ $# -ne 1 ] ; then + echo 'usage: qemu-mount imagefile' + echo 'Mounts a QEMU raw image file to /mnt/temp' + exit 1 +fi + +start=$( fdisk -l -o Device,Start ${1} | grep "^${1}1" | gawk '{print $2}' ) +sectors=$( fdisk -l ${1} | grep '^Units: sectors of' | gawk '{print $(NF-1)}' ) +offset=$(( $start * $sectors )) + +[ -d /mnt/temp ] || mkdir /mnt/temp +sudo mount -o loop,offset=$offset ${1} /mnt/temp + diff --git a/bash/vmclone.sh b/bash/vmclone.sh new file mode 100644 index 0000000..77d898d --- /dev/null +++ b/bash/vmclone.sh @@ -0,0 +1,111 @@ +#!/usr/bin/bash + +function usage { + echo "Usage: vmclone -s|--source -t|--target -o|--scriptonly" + echo " o| --scriptonly, only clone script is generated, the clone command will not be executed" +} + +######## +# MAIN # +######## + +typeset SOURCE_VM +typeset TARGET_VM +typeset SCRIPTONLY +typeset CLONESCRIPT="/tmp/kvmclone.sh" +typeset -i DISK_COUNT_SOURCE +typeset -i I +typeset RC +typeset REPLACE + +# parameter processing +while [ "$1" != "" ]; do + case $1 in + -s | --source ) shift + SOURCE_VM="$1" + ;; + -t | --target ) shift + TARGET_VM="$1" + ;; + -o | --scriptonly ) SCRIPTONLY=true + ;; + -r | --replace ) REPLACE=true + ;; + -h | --help ) usage + exit + ;; + * ) usage + exit 1 + esac + shift +done + + +if [ -z "$SOURCE_VM" ] || [ -z "$TARGET_VM" ]; then + usage + exit +fi + +# check if source VM exists +I=$(virsh list --all | grep $SOURCE_VM | wc -l) +if (( I == 0 )); then + echo "Source VM ($SOURCE_VM) does not exists" + exit 1 +fi + +# check if source VM is shut off +RC=$(virsh domstate $SOURCE_VM) +if [ "$RC" != "shut off" ]; then + echo "Source VM ($SOURCE_VM) is $RC, please shut it down first" + exit 1 +fi + +# check if target VM exists +I=$(virsh list --all | grep $TARGET_VM | wc -l) +if (( I > 0 )); then + # -r|--replace option was used + if [ "$REPLACE" == true ] ; then + # destroy the VM and the underlayng storage + echo "Shutdown VM $TARGET_VM" + virsh destroy $TARGET_VM > /dev/null 2>&1 + echo "Remove VM $TARGET_VM" + virsh undefine $TARGET_VM --remove-all-storage > /dev/null 2>&1 + else + echo "Target VM ($TARGET_VM) already exists, use -r|--replace option to replace it" + exit 1 + fi +fi + +# generate KVM clone shell +rm -rf $CLONESCRIPT +echo -e "#!/usr/bin/bash"'\n' >> $CLONESCRIPT +chmod +x $CLONESCRIPT + +echo "virt-clone \\" >> $CLONESCRIPT +echo " --original $SOURCE_VM \\" >> $CLONESCRIPT +echo " --name $TARGET_VM \\" >> $CLONESCRIPT + +DISK_COUNT_SOURCE=$(virsh domblklist ${SOURCE_VM} --details | grep -v cdrom | grep "file" | wc -l) + +I=0 +for DISK in $(virsh domblklist ${SOURCE_VM} --details | grep -v cdrom | grep "file" | awk -F " " '{ print $4}') +do + I=$((I+1)) + NEWDISK=${DISK/$SOURCE_VM/$TARGET_VM} + if (( I < DISK_COUNT_SOURCE )); then + echo " --file $NEWDISK \\" >> $CLONESCRIPT + else + echo " --file $NEWDISK" >> $CLONESCRIPT + fi +done + +echo "KVM clone script [$SOURCE_VM -> $TARGET_VM] has been generated: $CLONESCRIPT" + +if [ "$SCRIPTONLY" != true ] ; then + # recreate VM storage directories + cat $CLONESCRIPT | grep '\-\-file' | xargs -I{} echo {} | sed "s/--file//g" | sed 's/ //g' | xargs -I{} dirname {} | sort -u | xargs -I{} rm -rf {} + cat $CLONESCRIPT | grep '\-\-file' | xargs -I{} echo {} | sed "s/--file//g" | sed 's/ //g' | xargs -I{} dirname {} | sort -u | xargs -I{} mkdir -p {} + # Run generated KVM clone shell + echo "Executing $CLONESCRIPT.." + $CLONESCRIPT +fi diff --git a/divers/oracle_RAT_01.md b/divers/oracle_RAT_01.md new file mode 100644 index 0000000..54e70e2 --- /dev/null +++ b/divers/oracle_RAT_01.md @@ -0,0 +1,120 @@ +> [Original article](https://oracle-base.com/articles/8i/resource-manager-8i) + +Create application users: + + create user web_user identified by "iN_j8sC#d!kX6b:_"; + create user batch_user identified by "r~65ktuFYyds+P_X"; + grant connect,resource to web_user; + grant connect,resource to batch_user; + + +Create a pending area: + + BEGIN + DBMS_RESOURCE_MANAGER.clear_pending_area; + DBMS_RESOURCE_MANAGER.create_pending_area; + END; + / + + +Create a plan: + + BEGIN + DBMS_RESOURCE_MANAGER.create_plan( + plan => 'hybrid_plan', + comment => 'Plan for a combination of high and low priority tasks.'); + END; + / + + +Create a web and a batch consumer group: + + BEGIN + DBMS_RESOURCE_MANAGER.create_consumer_group( + consumer_group => 'WEB_CG', + comment => 'Web based OTLP processing - high priority'); + + DBMS_RESOURCE_MANAGER.create_consumer_group( + consumer_group => 'BATCH_CG', + comment => 'Batch processing - low priority'); + END; + / + + +Assign the consumer groups to the plan and indicate their relative priority, remembering to add the OTHER_GROUPS plan directive: + + + BEGIN + DBMS_RESOURCE_MANAGER.create_plan_directive ( + plan => 'hybrid_plan', + group_or_subplan => 'web_cg', + comment => 'High Priority', + cpu_p1 => 80, + cpu_p2 => 0, + parallel_degree_limit_p1 => 4); + + DBMS_RESOURCE_MANAGER.create_plan_directive ( + plan => 'hybrid_plan', + group_or_subplan => 'batch_cg', + comment => 'Low Priority', + cpu_p1 => 0, + cpu_p2 => 80, + parallel_degree_limit_p1 => 4); + + DBMS_RESOURCE_MANAGER.create_plan_directive( + plan => 'hybrid_plan', + group_or_subplan => 'OTHER_GROUPS', + comment => 'all other users - level 3', + cpu_p1 => 0, + cpu_p2 => 0, + cpu_p3 => 100); + END; + / + + +Validate and apply the resource plan: + + BEGIN + DBMS_RESOURCE_MANAGER.validate_pending_area; + DBMS_RESOURCE_MANAGER.submit_pending_area; + END; + / + + +Assign our users to individual consumer groups: + + BEGIN + -- Assign users to consumer groups + DBMS_RESOURCE_MANAGER_PRIVS.grant_switch_consumer_group( + grantee_name => 'web_user', + consumer_group => 'web_cg', + grant_option => FALSE); + + DBMS_RESOURCE_MANAGER_PRIVS.grant_switch_consumer_group( + grantee_name => 'batch_user', + consumer_group => 'batch_cg', + grant_option => FALSE); + + DBMS_RESOURCE_MANAGER.set_initial_consumer_group('web_user', 'web_cg'); + + DBMS_RESOURCE_MANAGER.set_initial_consumer_group('batch_user', 'batch_cg'); + END; + / + + +Connect users: + + connect web_user/"iN_j8sC#d!kX6b:_" + connect batch_user/"r~65ktuFYyds+P_X" + +Check `resource_consumer_group` column in `v$session`: + +SELECT username, resource_consumer_group + FROM v$session + WHERE username IN ('WEB_USER','BATCH_USER'); + +Note that the value change for a connecte session if `RESOURCE_MANAGER_PLAN` change at instance level: + + alter system set RESOURCE_MANAGER_PLAN = 'hybrid_plan' scope=both sid='*'; + alter system set RESOURCE_MANAGER_PLAN = '' scope=both sid='*'; + diff --git a/divers/oracle_RAT_01.txt b/divers/oracle_RAT_01.txt new file mode 100644 index 0000000..3006f78 --- /dev/null +++ b/divers/oracle_RAT_01.txt @@ -0,0 +1,93 @@ +-- https://orabliss.blogspot.com/2016/02/oracle-rat-demo-part-1.html + +CREATE PLUGGABLE DATABASE KENOBI ADMIN USER pdbdmin IDENTIFIED BY "RunDatab1218ase#1985Go!"; +alter pluggable database KENOBI open; +alter pluggable database KENOBI save state; +alter session set container=KENOBI; +show con_name + +@?/rdbms/admin/utlrp + + + +CREATE PLUGGABLE DATABASE MAUL ADMIN USER pdbdmin IDENTIFIED BY "RunDatab1218ase#1985Go!"; +alter pluggable database MAUL open; +alter pluggable database MAUL save state; +alter session set container=MAUL; +show con_name + +@?/rdbms/admin/utlrp + + + + +run +{ + set nocfau; + allocate channel ch01 device type disk format '/mnt/yavin4/tmp/_oracle_/orabackup/temp/rat1/JEDIPRD/%d_%U_%s_%t.bck'; + allocate channel ch02 device type disk format '/mnt/yavin4/tmp/_oracle_/orabackup/temp/rat1/JEDIPRD/%d_%U_%s_%t.bck'; + allocate channel ch03 device type disk format '/mnt/yavin4/tmp/_oracle_/orabackup/temp/rat1/JEDIPRD/%d_%U_%s_%t.bck'; + allocate channel ch04 device type disk format '/mnt/yavin4/tmp/_oracle_/orabackup/temp/rat1/JEDIPRD/%d_%U_%s_%t.bck'; + backup as compressed backupset incremental level 0 database section size 2G include current controlfile plus archivelog delete input; + release channel ch01; + release channel ch02; + release channel ch03; + release channel ch04; + allocate channel ch01 device type disk format '/mnt/yavin4/tmp/_oracle_/orabackup/temp/rat1/JEDIPRD/%d_%U_%s_%t.controlfile'; + backup current controlfile; + release channel ch01; +} + +run +{ + set nocfau; + allocate channel ch01 device type disk format '/mnt/yavin4/tmp/_oracle_/orabackup/temp/rat1/SITHPRD/%d_%U_%s_%t.bck'; + allocate channel ch02 device type disk format '/mnt/yavin4/tmp/_oracle_/orabackup/temp/rat1/SITHPRD/%d_%U_%s_%t.bck'; + allocate channel ch03 device type disk format '/mnt/yavin4/tmp/_oracle_/orabackup/temp/rat1/SITHPRD/%d_%U_%s_%t.bck'; + allocate channel ch04 device type disk format '/mnt/yavin4/tmp/_oracle_/orabackup/temp/rat1/SITHPRD/%d_%U_%s_%t.bck'; + backup as compressed backupset incremental level 0 database section size 2G include current controlfile plus archivelog delete input; + release channel ch01; + release channel ch02; + release channel ch03; + release channel ch04; + allocate channel ch01 device type disk format '/mnt/yavin4/tmp/_oracle_/orabackup/temp/rat1/SITHPRD/%d_%U_%s_%t.controlfile'; + backup current controlfile; + release channel ch01; +} + + + +create or replace directory RAT_WORKLOAD as '/home/or + + + + +create or replace directory RAT_WORKLOAD as '/home/oracle/rat'; +execute dbms_workload_capture.start_capture('RAT_CAPTURE','RAT_WORKLOAD'); +-- execute Workload +execute dbms_workload_capture.finish_capture(); + +SQL> col name for a12 +SQL> col status for a10 +SQL> col dir_path for a25 +SQL> set lines 300acle/rat'; +execute dbms_workload_capture.start_capture('RAT_CAPTURE','RAT_WORKLOAD'); +-- execute Workload +execute dbms_workload_capture.finish_capture(); + +col name for a12 +col status for a10 +col dir_path for a25 +set lines 300 + +select id,name,status,start_time,end_time,connects,user_calls,dir_path from dba_workload_captures +where id = (select max(id) from dba_workload_captures) ; + + + + +set pagesize 0 long 30000000 longchunksize 1000 +select dbms_workload_capture.report(2,'TEXT') from dual; + +export PATH=$ORACLE_HOME/jdk/bin:$PATH +java -classpaexport PATH=$ORACLE_HOME/jdk/bin:$PATHth $ORACLE_HOME/jdbc/lib/ojdbc7.jar:$ORACLE_HOME/rdbms/jlib/dbrparser.jar:$ORACLE_HOME/rdbms/jlib/dbranalyzer.jar: oracle.dbreplay.workload.checker.CaptureChecker /home/oracle/rat jdbc:oracle:thin:@taris:1521/KENOBI \ No newline at end of file diff --git a/divers/oracle_autoupgrade_01.txt b/divers/oracle_autoupgrade_01.txt new file mode 100644 index 0000000..3de1748 --- /dev/null +++ b/divers/oracle_autoupgrade_01.txt @@ -0,0 +1,139 @@ +export PATH=/app/oracle/product/21/jdk/bin:$PATH +export JAVA_HOME=/app/oracle/product/21/jdk + +java -jar $ORACLE_HOME/rdbms/admin/autoupgrade.jar -version + + + + + +create spfile='/app/oracle/base/admin/WEDGEPRD/spfile/spfileWEDGEPRD.ora' from pfile='/app/oracle/base/admin/WEDGEPRD/pfile/initWEDGEPRD.ora'; + +startup nomount; + +rman auxiliary / + +run +{ + allocate auxiliary channel aux01 device type disk; + allocate auxiliary channel aux02 device type disk; + allocate auxiliary channel aux03 device type disk; + allocate auxiliary channel aux04 device type disk; + allocate auxiliary channel aux05 device type disk; + allocate auxiliary channel aux06 device type disk; + allocate auxiliary channel aux07 device type disk; + allocate auxiliary channel aux08 device type disk; + allocate auxiliary channel aux09 device type disk; + allocate auxiliary channel aux10 device type disk; + duplicate target database to WEDGE backup location '/mnt/yavin4/tmp/_oracle_/orabackup/_keep_/Standalone/11.2.0.4/WEDGE/'; +} + + +@$ORACLE_HOME/rdbms/admin/catbundle psu apply +@$ORACLE_HOME/rdbms/admin/utlrp + +java -jar /mnt/yavin4/tmp/autoupgrade.jar -version +java -jar /mnt/yavin4/tmp/autoupgrade.jar -config /home/oracle/myconfig.cfg -clear_recovery_data +java -jar /mnt/yavin4/tmp/autoupgrade.jar -config myconfig.cfg -mode analyze +java -jar /mnt/yavin4/tmp/autoupgrade.jar -config myconfig.cfg -mode fixups +java -jar /mnt/yavin4/tmp/autoupgrade.jar -config myconfig.cfg -mode deploy + + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +global.autoupg_log_dir=/home/oracle + +upg1.sid=WEDGEPRD # ORACLE_SID of the source DB/CDB +upg1.source_home=/app/oracle/product/11.2 # Path of the source ORACLE_HOME +upg1.target_home=/app/oracle/product/19 # Path of the target ORACLE_HOME +upg1.start_time=NOW # Optional. [NOW | +XhYm (X hours, Y minutes after launch) | dd/mm/yyyy hh:mm:ss] +upg1.upgrade_node=taris.swgalaxy # Optional. To find out the name of your node, run the hostname utility. Default is 'localhost' +upg1.run_utlrp=yes # Optional. Whether or not to run utlrp after upgrade +upg1.timezone_upg=yes # Optional. Whether or not to run the timezone upgrade +upg1.target_version=19 # Oracle version of the target ORACLE_HOME. Only required when the target Oracle database version is 12.2 + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +create spfile='/app/oracle/base/admin/ASTYPRD/spfile/spfileASTYPRD.ora' from pfile='/app/oracle/base/admin/ASTYPRD/pfile/initASTYPRD.ora'; + +startup nomount; + +rman auxiliary / + +run +{ + allocate auxiliary channel aux01 device type disk; + allocate auxiliary channel aux02 device type disk; + allocate auxiliary channel aux03 device type disk; + allocate auxiliary channel aux04 device type disk; + allocate auxiliary channel aux05 device type disk; + allocate auxiliary channel aux06 device type disk; + allocate auxiliary channel aux07 device type disk; + allocate auxiliary channel aux08 device type disk; + allocate auxiliary channel aux09 device type disk; + allocate auxiliary channel aux10 device type disk; + duplicate target database to ASTY backup location '/mnt/yavin4/tmp/_oracle_/orabackup/_keep_/Standalone/19.11/ASTY/'; +} + + + +cd $ORACLE_HOME/OPatch +./datapatch + +@$ORACLE_HOME/rdbms/admin/utlrp + + +global.autoupg_log_dir=/home/oracle + +# +# Database number 3 - Noncdb to PDB upgrade +# +upg3.sid=WEDGEPRD +upg3.source_home=/app/oracle/product/11.2 +upg3.target_cdb=ASTYPRD +upg3.target_home=/app/oracle/product/19 +upg3.target_pdb_name=PDBWEDGEPRD +upg3.start_time=NOW # Optional. 10 Minutes from now +upg3.upgrade_node=localhost # Optional. To find out the name of your node, run the hostname utility. Default is 'localhost' +upg3.run_utlrp=yes # Optional. Whether or not to run utlrp after upgrade +upg3.timezone_upg=yes # Optional. Whether or not to run the timezone upgrade + + +rman target / + +run +{ + set nocfau; + allocate channel ch01 device type disk format '/mnt/yavin4/tmp/_oracle_/orabackup/temp/upgrade1/ASTYPRD/%d_%U_%s_%t.bck'; + allocate channel ch02 device type disk format '/mnt/yavin4/tmp/_oracle_/orabackup/temp/upgrade1/ASTYPRD/%d_%U_%s_%t.bck'; + allocate channel ch03 device type disk format '/mnt/yavin4/tmp/_oracle_/orabackup/temp/upgrade1/ASTYPRD/%d_%U_%s_%t.bck'; + allocate channel ch04 device type disk format '/mnt/yavin4/tmp/_oracle_/orabackup/temp/upgrade1/ASTYPRD/%d_%U_%s_%t.bck'; + backup as compressed backupset incremental level 0 database section size 2G include current controlfile plus archivelog delete input; + release channel ch01; + release channel ch02; + release channel ch03; + release channel ch04; + allocate channel ch01 device type disk format '/mnt/yavin4/tmp/_oracle_/orabackup/temp/upgrade1/ASTYPRD/%d_%U_%s_%t.controlfile'; + backup current controlfile; + release channel ch01; +} + + +run +{ + set nocfau; + allocate channel ch01 device type disk format '/mnt/yavin4/tmp/_oracle_/orabackup/temp/upgrade1/WEDGEPRD/%d_%U_%s_%t.bck'; + allocate channel ch02 device type disk format '/mnt/yavin4/tmp/_oracle_/orabackup/temp/upgrade1/WEDGEPRD/%d_%U_%s_%t.bck'; + allocate channel ch03 device type disk format '/mnt/yavin4/tmp/_oracle_/orabackup/temp/upgrade1/WEDGEPRD/%d_%U_%s_%t.bck'; + allocate channel ch04 device type disk format '/mnt/yavin4/tmp/_oracle_/orabackup/temp/upgrade1/WEDGEPRD/%d_%U_%s_%t.bck'; + backup as compressed backupset incremental level 0 database section size 2G include current controlfile plus archivelog delete input; + release channel ch01; + release channel ch02; + release channel ch03; + release channel ch04; + allocate channel ch01 device type disk format '/mnt/yavin4/tmp/_oracle_/orabackup/temp/upgrade1/WEDGEPRD/%d_%U_%s_%t.controlfile'; + backup current controlfile; + release channel ch01; +} + + diff --git a/divers/oracle_clone_using_lv_snap_01.txt b/divers/oracle_clone_using_lv_snap_01.txt new file mode 100644 index 0000000..4526550 --- /dev/null +++ b/divers/oracle_clone_using_lv_snap_01.txt @@ -0,0 +1,43 @@ +On Dom0: + +qemu-img create -f raw /vm/hdd0/kamino/data_03.img 20G + +chown qemu:qemu /vm/hdd0/kamino/data_03.img +chmod 600 /vm/hdd0/kamino/data_03.img + +virsh attach-disk kamino /vm/hdd0/kamino/data_03.img vdh --driver qemu --subdriver raw --targetbus virtio --persistent + + +qemu-img create -f raw /vm/hdd0/kamino/fra_02.img 20G + +chown qemu:qemu /vm/hdd0/kamino/fra_02.img +chmod 600 /vm/hdd0/kamino/fra_02.img + +virsh attach-disk kamino /vm/hdd0/kamino/fra_02.img vdi --driver qemu --subdriver raw --targetbus virtio --persistent + + +On VM: + +pvcreate /dev/vdh +pvcreate /dev/vdi + +vgextend vg_data /dev/vdh +vgextend vg_fra /dev/vdi + + + +lvcreate -s -n lv_snap_data -L 19G vg_data/lv_data + + + + +mkdir /snap_data /snap_fra + +# On XFS add options: rw,nouuid, otherwise the mount fails +mount -o rw,nouuid /dev/vg_data/lv_snap_data /snap_data + +# try: xfs_admin -U generate /dev/vg_data/lv_snap_data + +umount /snap_data +lvremove vg_data/lv_snap_data + diff --git a/divers/oracle_ressource_manager_01.txt b/divers/oracle_ressource_manager_01.txt new file mode 100644 index 0000000..3ad2745 --- /dev/null +++ b/divers/oracle_ressource_manager_01.txt @@ -0,0 +1,128 @@ +https://oracle-base.com/articles/8i/resource-manager-8i + + +orapwd file=orapwHUTTPRD password="Urezesf7754#hhY7711#ab?" + + +create pluggable database DURGA admin user HUTTMASTER identified by "Ngfsf554#hhAZAR1#10!"; +alter pluggable database DURGA open; +alter pluggable database DURGA save state; + +alter session set container=DURGA; +show con_name +grant sysdba to starkiller identified by "VvvAv0332#00911HsqeZA?"; + + + +alias HUTTPRD='rlwrap sqlplus sys/"Urezesf7754#hhY7711#ab?"@taris/HUTTPRD as sysdba' +alias DURGA='rlwrap sqlplus starkiller/"VvvAv0332#00911HsqeZA?"@taris/DURGA as sysdba' + + +CREATE USER web_user identified by "iN_j8sC#d!kX6b:_"; +CREATE USER batch_user identified by "r~65ktuFYyds+P_X"; + +grant connect,resource to web_user; +grant connect,resource to batch_user; + +# create a pending area. + +BEGIN + DBMS_RESOURCE_MANAGER.clear_pending_area; + DBMS_RESOURCE_MANAGER.create_pending_area; +END; +/ + +# create a plan + +BEGIN + DBMS_RESOURCE_MANAGER.create_plan( + plan => 'hybrid_plan', + comment => 'Plan for a combination of high and low priority tasks.'); +END; +/ + +Create a web and a batch consumer group + +BEGIN + DBMS_RESOURCE_MANAGER.create_consumer_group( + consumer_group => 'WEB_CG', + comment => 'Web based OTLP processing - high priority'); + + DBMS_RESOURCE_MANAGER.create_consumer_group( + consumer_group => 'BATCH_CG', + comment => 'Batch processing - low priority'); +END; +/ + +# assign the consumer groups to the plan and indicate their relative priority, remembering to add the OTHER_GROUPS plan directive. + + +BEGIN + DBMS_RESOURCE_MANAGER.create_plan_directive ( + plan => 'hybrid_plan', + group_or_subplan => 'web_cg', + comment => 'High Priority', + cpu_p1 => 80, + cpu_p2 => 0, + parallel_degree_limit_p1 => 4); + + DBMS_RESOURCE_MANAGER.create_plan_directive ( + plan => 'hybrid_plan', + group_or_subplan => 'batch_cg', + comment => 'Low Priority', + cpu_p1 => 0, + cpu_p2 => 80, + parallel_degree_limit_p1 => 4); + + DBMS_RESOURCE_MANAGER.create_plan_directive( + plan => 'hybrid_plan', + group_or_subplan => 'OTHER_GROUPS', + comment => 'all other users - level 3', + cpu_p1 => 0, + cpu_p2 => 0, + cpu_p3 => 100); +END; +/ + +# validate and apply the resource plan. + +BEGIN + DBMS_RESOURCE_MANAGER.validate_pending_area; + DBMS_RESOURCE_MANAGER.submit_pending_area; +END; +/ + + +# assign our users to individual consumer groups. + +BEGIN + -- Assign users to consumer groups + DBMS_RESOURCE_MANAGER_PRIVS.grant_switch_consumer_group( + grantee_name => 'web_user', + consumer_group => 'web_cg', + grant_option => FALSE); + + DBMS_RESOURCE_MANAGER_PRIVS.grant_switch_consumer_group( + grantee_name => 'batch_user', + consumer_group => 'batch_cg', + grant_option => FALSE); + + DBMS_RESOURCE_MANAGER.set_initial_consumer_group('web_user', 'web_cg'); + + DBMS_RESOURCE_MANAGER.set_initial_consumer_group('batch_user', 'batch_cg'); +END; +/ + + + + +connect web_user/"iN_j8sC#d!kX6b:_"@taris/DURGA +connect batch_user/"r~65ktuFYyds+P_X"@taris/DURGA + +SELECT username, resource_consumer_group + FROM v$session + WHERE username IN ('WEB_USER','BATCH_USER'); + + +ALTER SYSTEM SET RESOURCE_MANAGER_PLAN = 'hybrid_plan'; + diff --git a/divers/sql_quarantine_01.md b/divers/sql_quarantine_01.md new file mode 100644 index 0000000..99935d3 --- /dev/null +++ b/divers/sql_quarantine_01.md @@ -0,0 +1,62 @@ +> [Original article](https://oracle-base.com/articles/19c/sql-quarantine-19c) + +We can manually quarantine a statement based on SQL_ID or SQL_TEXT. +Both methods accept a PLAN_HASH_VALUE parameter, which allows us to quarantine a single execution plan. +If this is not specified, all execution plans for the statement are quarantined. + + + -- Quarantine all execution plans for a SQL_ID. + DECLARE + l_sql_quarantine VARCHAR2(100); + BEGIN + l_sql_quarantine := sys.DBMS_SQLQ.create_quarantine_by_sql_id( + sql_id => 'gs59hr0xtjrf8' + ); + DBMS_OUTPUT.put_line('l_sql_quarantine=' || l_sql_quarantine); + END; + / + + +SQL quarantine display: + + set lines 256 + COLUMN sql_text FORMAT A50 TRUNC + COLUMN plan_hash_value FORMAT 999999999999 + COLUMN name FORMAT A30 + COLUMN enabled FORMAT A3 HEAD "Ena" + COLUMN cpu_time FORMAT A10 + COLUMN io_megabytes FORMAT A10 + COLUMN io_requests FORMAT A10 + COLUMN elapsed_time FORMAT A10 + COLUMN io_logical FORMAT A10 + + select + name, enabled,cpu_time, io_megabytes, io_requests, elapsed_time, io_logical, plan_hash_value, sql_text + from + dba_sql_quarantine; + + +The ALTER_QUARANTINE procedure allows us to alter the thresholds, to make them look more like automatically generated quarantines. +We can use the procedure to alter the following parameters: + +- CPU_TIME +- ELAPSED_TIME +- IO_MEGABYTES +- IO_REQUESTS +- IO_LOGICAL +- ENABLED +- AUTOPURGE + +Example of setting the CPU_TIME threshold for the manually created quarantines: + + BEGIN + DBMS_SQLQ.alter_quarantine( + quarantine_name => 'SQL_QUARANTINE_8zpc9pwdmb8vr', + parameter_name => 'CPU_TIME', + parameter_value => '1'); + END; + / + + + + diff --git a/divers/tmp_script.sql b/divers/tmp_script.sql new file mode 100644 index 0000000..dae8193 --- /dev/null +++ b/divers/tmp_script.sql @@ -0,0 +1,30 @@ +CREATE TABLE exemple_table ( + col1 INTEGER, + col2 INTEGER, + col3 INTEGER, + col4 VARCHAR2(20) +); + +DECLARE + v_col1 INTEGER; + v_col2 INTEGER; + v_col3 INTEGER; + v_col4 VARCHAR2(20); +BEGIN + FOR i IN 1..1000000 LOOP + v_col1 := TRUNC(DBMS_RANDOM.VALUE(1, 1000)); + v_col2 := TRUNC(DBMS_RANDOM.VALUE(1, 1000)); + v_col3 := TRUNC(DBMS_RANDOM.VALUE(1, 1000)); + v_col4 := DBMS_RANDOM.STRING('U', 10); -- 10 caractères aléatoires en majuscules + + INSERT INTO exemple_table (col1, col2, col3, col4) + VALUES (v_col1, v_col2, v_col3, v_col4); + + -- Commit toutes les 10 000 lignes pour éviter les problèmes de mémoire + IF MOD(i, 10000) = 0 THEN + COMMIT; + END IF; + END LOOP; + COMMIT; +END; +/ diff --git a/divers/vminfo.txt b/divers/vminfo.txt new file mode 100644 index 0000000..11dba69 --- /dev/null +++ b/divers/vminfo.txt @@ -0,0 +1,19 @@ +bakura Oracle +togoria Oracle +wayland Oracle + +exegol OEL9 - ogg21 +helska OEL9 - ogg21 + +# raxus PostgreSQL +belasco PostgreSQL + +jakku Windows 7 - Ciel Compta +utapau Windows 11 (vplesnila/secret) + +seedmachine Rocky Linux 9 generic VM +ivera Rocky Linux 9 - docker + +adega Windows Server 2022 SE vplesnila/Secret00! +atrisia Windows Server 2022 SE vplesnila/Secret00! + diff --git a/notes.txt b/notes.txt new file mode 100644 index 0000000..e69de29 diff --git a/push_all b/push_all new file mode 100644 index 0000000..615d889 --- /dev/null +++ b/push_all @@ -0,0 +1,5 @@ +NOW=$(date -u +"%Y-%m-%d %H:%M:%S" ) +git add . +git commit -m "${NOW}" +git push -u origin main + diff --git a/python/01.py b/python/01.py new file mode 100644 index 0000000..e69de29 diff --git a/python/DomainUpdater/DomainUpdater.2019-07-01 b/python/DomainUpdater/DomainUpdater.2019-07-01 new file mode 100644 index 0000000..268726f --- /dev/null +++ b/python/DomainUpdater/DomainUpdater.2019-07-01 @@ -0,0 +1,128 @@ +#!/app/python3/bin/python3 + +# vplesnila 2019-06-24: creation +# vplesnila 2019-06-25: build self.subdomains_list +# vplesnila 2019-07-01: finalize update subdomains procedure and email sending + +import os +import smtplib +from email.message import EmailMessage +from email.mime.text import MIMEText +import socket +import json +import requests +import logging + +# LOGGING initialization function +def start_logging(logfile): + logger = logging.getLogger(__name__) + logger.setLevel(logging.INFO) + + # create a file handler + handler = logging.FileHandler(logfile) + handler.setLevel(logging.INFO) + + # create a logging format + formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') + handler.setFormatter(formatter) + + # add the handlers to the logger + logger.addHandler(handler) + return logger + +class DomainUpdater: + def __init__(self, rootdir): + self.rootdir = rootdir + + # Load configuration + with open(self.rootdir + "/" + "DomainUpdater.conf", "r") as f: + self.config = json.load(f) + + # Get current IP + r = requests.get(self.config["get_current_ip_api_url"]) + self.current_ip = r.json()["ip"] + logger.info("__BEGIN_BATCH__") + logger.info("Current IP is " + self.current_ip) + + # Build subdomain list as a ist of (subdomain name, domain_id, subdomain_id) + self.subdomains_list = [] + + self.auth = (self.config["dnsmanager_id"], self.config["dnsmanager_key"]) + self.url_base = self.config["dnsmanager_api_url_base"] + + # Get domains dictionary + url_end = "/user/domains" + r = requests.get(self.url_base + url_end, auth = self.auth) + domain_dict = r.json()["results"] + + for domain in domain_dict: + domain_name = domain["domain"] + domain_id = domain["id"] + url_end = "/user/domain/" + str(domain["id"]) + "/records" + r = requests.get(self.url_base + url_end, auth = self.auth) + records_dict = r.json()["results"] + for record_dict in records_dict: + if record_dict["type"] == "A": + # Subdomain + subdomain_id = record_dict["id"] + subdomain_name = record_dict["name"] + subdomain_ip = record_dict["content"] + fqdn = "%s.%s" % (subdomain_name, domain_name) + record = (fqdn, domain_id, subdomain_id, subdomain_ip) + self.subdomains_list.append(record) + return + + def send_email_new_ip(self): + msg = EmailMessage() + msg["Subject"] = "Your public IP changed" + msg["From"] = "domain-updater@databasepro.fr" + msg["To"] = "vplesnila@gmail.com" + body = """ + Hello, + You have a new public IP: %s + Following subdomains has been updated: + %s + -------------- + Domain Updater + """ % (self.current_ip, "\n".join(self.updated_subdomain_list)) + msg.set_content(body) + s = smtplib.SMTP("localhost") + s.send_message(msg) + s.quit() + logger.info("Email sent to " + msg["To"]) + return + + def check_subdomains(self): + self.updated_subdomain_list=[] + for record in self.subdomains_list: + (fqdn, domain_id, subdomain_id, subdomain_ip) = record + if (subdomain_ip == self.current_ip): + logger.info(fqdn + " already set to " + subdomain_ip + ", nothing to do") + else: + logger.info("Updatting " + fqdn + " with the new IP value " + self.current_ip) + self.update_subdomain(domain_id, subdomain_id) + self.updated_subdomain_list.append(fqdn) + + logger.info("__END_BATCH__") + return + + def update_subdomain(self, domain_id, subdomain_id): + url_end = "/user/domain/" + str(domain_id) + "/record/" + str(subdomain_id) + data = json.dumps({"id":subdomain_id, "content":self.current_ip}) + headers = { 'Content-Type': 'application/json'} + r = requests.put(self.url_base + url_end, auth = self.auth, data = data, headers=headers) + return + +if __name__ == "__main__": + script_path = os.path.dirname(os.path.abspath(__file__)) + script_name = os.path.basename(__file__) + logger = start_logging(script_path + '/DomainUpdater.log') + domainupdater = DomainUpdater(script_path) + domainupdater.check_subdomains() + if len(domainupdater.updated_subdomain_list) > 0: + domainupdater.send_email_new_ip() + + + + + diff --git a/python/DomainUpdater/DomainUpdater.conf b/python/DomainUpdater/DomainUpdater.conf new file mode 100644 index 0000000..a18b7e5 --- /dev/null +++ b/python/DomainUpdater/DomainUpdater.conf @@ -0,0 +1,9 @@ +{ + "email_from": "domainupdater@databasepro.eu", + "email_to": "vplesnila@gmail.com", + "get_current_ip_api_url": "https://api.ipify.org?format=json", + "dnsmanager_api_url_base":"https://app.dnsmanager.io/api/v1", + "dnsmanager_id":"9422ac9d-2c62-4967-ae12-c1d15bbbe200", + "dnsmanager_key":"I9HV2Jqp1gFqMuic3zPRYW5guSQEvoyy", + "subdomain_list":"ssh.databasepro.fr,code.databasepro.fr,sabnzbd.databasepro.eu,sabnzbd.databasepro.fr,public.databasepro.fr,support.databasepro.fr" +} diff --git a/python/DomainUpdater/DomainUpdater.conf.2020-12-23 b/python/DomainUpdater/DomainUpdater.conf.2020-12-23 new file mode 100644 index 0000000..59e24d5 --- /dev/null +++ b/python/DomainUpdater/DomainUpdater.conf.2020-12-23 @@ -0,0 +1,8 @@ +{ + "email_from": "domainupdater@databasepro.fr", + "email_to": "vplesnila@gmail.com", + "get_current_ip_api_url": "https://api.ipify.org?format=json", + "dnsmanager_api_url_base":"https://app.dnsmanager.io/api/v1", + "dnsmanager_id":"9422ac9d-2c62-4967-ae12-c1d15bbbe200", + "dnsmanager_key":"I9HV2Jqp1gFqMuic3zPRYW5guSQEvoyy" +} diff --git a/python/DomainUpdater/DomainUpdater.conf.2021-01-15 b/python/DomainUpdater/DomainUpdater.conf.2021-01-15 new file mode 100644 index 0000000..bb80191 --- /dev/null +++ b/python/DomainUpdater/DomainUpdater.conf.2021-01-15 @@ -0,0 +1,9 @@ +{ + "email_from": "domainupdater@databasepro.fr", + "email_to": "vplesnila@gmail.com", + "get_current_ip_api_url": "https://api.ipify.org?format=json", + "dnsmanager_api_url_base":"https://app.dnsmanager.io/api/v1", + "dnsmanager_id":"9422ac9d-2c62-4967-ae12-c1d15bbbe200", + "dnsmanager_key":"I9HV2Jqp1gFqMuic3zPRYW5guSQEvoyy", + "subdomain_list":"None.databasepro.fr,ssh.databasepro.fr" +} diff --git a/python/DomainUpdater/DomainUpdater.py b/python/DomainUpdater/DomainUpdater.py new file mode 100644 index 0000000..77d164f --- /dev/null +++ b/python/DomainUpdater/DomainUpdater.py @@ -0,0 +1,147 @@ +#!/usr/bin/python3 + +# vplesnila 2019-06-24: creation +# vplesnila 2019-06-25: build self.subdomains_list +# vplesnila 2019-07-01: finalize update subdomains procedure and email sending +# vplesnila 2020-12-24: add subdomain list in config file to allow updating only a subset of dnsmanager.io registered subdomains + +import os +import socket +import json +import requests +import logging +import smtplib +from email.message import EmailMessage +from email.mime.text import MIMEText + + +# LOGGING initialization function +def start_logging(logfile): + logger = logging.getLogger(__name__) + logger.setLevel(logging.INFO) + + # create a file handler + handler = logging.FileHandler(logfile) + handler.setLevel(logging.INFO) + + # create a logging format + formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') + handler.setFormatter(formatter) + + # add the handlers to the logger + logger.addHandler(handler) + return logger + +class DomainUpdater: + def __init__(self, rootdir): + self.rootdir = rootdir + + # Load configuration + with open(self.rootdir + "/" + "DomainUpdater.conf", "r") as f: + self.config = json.load(f) + + # Get current IP + r = requests.get(self.config["get_current_ip_api_url"]) + self.current_ip = r.json()["ip"] + logger.info("Current public IP is " + self.current_ip) + + # Build subdomain list as a ist of (subdomain name, domain_id, subdomain_id) + self.subdomains_list = [] + + self.auth = (self.config["dnsmanager_id"], self.config["dnsmanager_key"]) + self.url_base = self.config["dnsmanager_api_url_base"] + + # Get domains dictionary + url_end = "/user/domains" + r = requests.get(self.url_base + url_end, auth = self.auth) + domain_dict = r.json()["results"] + + # Get fqdn list + self.fqdn_list = self.config["subdomain_list"].split(",") + logger.info("Subdomains list: " + ",".join(self.fqdn_list)) + + self.fqdn_to_update = [] + for domain in domain_dict: + domain_name = domain["domain"] + domain_id = domain["id"] + url_end = "/user/domain/" + str(domain["id"]) + "/records" + r = requests.get(self.url_base + url_end, auth = self.auth) + records_dict = r.json()["results"] + for record_dict in records_dict: + if record_dict["type"] == "A": + # Subdomain + subdomain_id = record_dict["id"] + subdomain_name = record_dict["name"] + subdomain_ip = record_dict["content"] + fqdn = "%s.%s" % (subdomain_name, domain_name) + record = (fqdn, domain_id, subdomain_id, subdomain_ip) + if (fqdn in self.fqdn_list): + self.fqdn_to_update.append(fqdn) + self.subdomains_list.append(record) + + logger.info("Updating subdomain(s): " + ",".join(self.fqdn_to_update)) + return + + + def send_email_new_ip(self): + SMTPserver = 'smtp.orange.fr' + sender = 'Domain-Updater@databasepro.fr' + destination = ['vplesnila@gmail.com'] + USERNAME = "plesnila.valeriu@orange.fr" + PASSWORD = "ch1tzch1tz" + + msg = EmailMessage() + msg["Subject"] = "Your public IP changed" + msg["From"] = sender + msg["To"] = destination + body = """ + Hello, + You have a new public IP: %s + Following subdomains has been updated: %s + -------------- + Domain-Updater + """ % (self.current_ip, ", ".join(self.updated_subdomain_list)) + msg.set_content(body) + s = smtplib.SMTP(host = SMTPserver, port= 587) + s.set_debuglevel(False) + s.login(USERNAME, PASSWORD) + s.send_message(msg) + s.quit() + logger.info("Email sent to " + msg["To"]) + return + + + def check_subdomains(self): + self.updated_subdomain_list=[] + for record in self.subdomains_list: + (fqdn, domain_id, subdomain_id, subdomain_ip) = record + if (subdomain_ip == self.current_ip): + logger.info(fqdn + " already set to " + subdomain_ip + ", nothing to do") + else: + logger.info("Updating " + fqdn + " with the new IP value " + self.current_ip) + self.update_subdomain(domain_id, subdomain_id) + self.updated_subdomain_list.append(fqdn) + return + + def update_subdomain(self, domain_id, subdomain_id): + url_end = "/user/domain/" + str(domain_id) + "/record/" + str(subdomain_id) + data = json.dumps({"id":subdomain_id, "content":self.current_ip}) + headers = { 'Content-Type': 'application/json'} + r = requests.put(self.url_base + url_end, auth = self.auth, data = data, headers=headers) + return + +if __name__ == "__main__": + script_path = os.path.dirname(os.path.abspath(__file__)) + script_name = os.path.basename(__file__) + logger = start_logging(script_path + '/DomainUpdater.log') + logger.info("__BEGIN_BATCH__") + domainupdater = DomainUpdater(script_path) + domainupdater.check_subdomains() + if len(domainupdater.updated_subdomain_list) > 0: + domainupdater.send_email_new_ip() + logger.info("__END_BATCH__") + + + + + diff --git a/python/DomainUpdater/DomainUpdater.py.2020-12-23 b/python/DomainUpdater/DomainUpdater.py.2020-12-23 new file mode 100644 index 0000000..bd0fdba --- /dev/null +++ b/python/DomainUpdater/DomainUpdater.py.2020-12-23 @@ -0,0 +1,126 @@ +#!/app/python/current_version/bin/python3 + +# vplesnila 2019-06-24: creation +# vplesnila 2019-06-25: build self.subdomains_list +# vplesnila 2019-07-01: finalize update subdomains procedure and email sending + +import os +import smtplib +from email.message import EmailMessage +from email.mime.text import MIMEText +import socket +import json +import requests +import logging + +# LOGGING initialization function +def start_logging(logfile): + logger = logging.getLogger(__name__) + logger.setLevel(logging.INFO) + + # create a file handler + handler = logging.FileHandler(logfile) + handler.setLevel(logging.INFO) + + # create a logging format + formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') + handler.setFormatter(formatter) + + # add the handlers to the logger + logger.addHandler(handler) + return logger + +class DomainUpdater: + def __init__(self, rootdir): + self.rootdir = rootdir + + # Load configuration + with open(self.rootdir + "/" + "DomainUpdater.conf", "r") as f: + self.config = json.load(f) + + # Get current IP + r = requests.get(self.config["get_current_ip_api_url"]) + self.current_ip = r.json()["ip"] + logger.info("Current IP is " + self.current_ip) + + # Build subdomain list as a ist of (subdomain name, domain_id, subdomain_id) + self.subdomains_list = [] + + self.auth = (self.config["dnsmanager_id"], self.config["dnsmanager_key"]) + self.url_base = self.config["dnsmanager_api_url_base"] + + # Get domains dictionary + url_end = "/user/domains" + r = requests.get(self.url_base + url_end, auth = self.auth) + domain_dict = r.json()["results"] + + for domain in domain_dict: + domain_name = domain["domain"] + domain_id = domain["id"] + url_end = "/user/domain/" + str(domain["id"]) + "/records" + r = requests.get(self.url_base + url_end, auth = self.auth) + records_dict = r.json()["results"] + for record_dict in records_dict: + if record_dict["type"] == "A": + # Subdomain + subdomain_id = record_dict["id"] + subdomain_name = record_dict["name"] + subdomain_ip = record_dict["content"] + fqdn = "%s.%s" % (subdomain_name, domain_name) + record = (fqdn, domain_id, subdomain_id, subdomain_ip) + self.subdomains_list.append(record) + return + + def send_email_new_ip(self): + msg = EmailMessage() + msg["Subject"] = "Your public IP changed" + msg["From"] = "domain-updater@databasepro.fr" + msg["To"] = "vplesnila@gmail.com" + body = """ + Hello, + You have a new public IP: %s + Following subdomains has been updated: %s + -------------- + Domain Updater + """ % (self.current_ip, ", ".join(self.updated_subdomain_list)) + msg.set_content(body) + s = smtplib.SMTP("localhost") + s.send_message(msg) + s.quit() + logger.info("Email sent to " + msg["To"]) + return + + def check_subdomains(self): + self.updated_subdomain_list=[] + for record in self.subdomains_list: + (fqdn, domain_id, subdomain_id, subdomain_ip) = record + if (subdomain_ip == self.current_ip): + logger.info(fqdn + " already set to " + subdomain_ip + ", nothing to do") + else: + logger.info("Updating " + fqdn + " with the new IP value " + self.current_ip) + self.update_subdomain(domain_id, subdomain_id) + self.updated_subdomain_list.append(fqdn) + return + + def update_subdomain(self, domain_id, subdomain_id): + url_end = "/user/domain/" + str(domain_id) + "/record/" + str(subdomain_id) + data = json.dumps({"id":subdomain_id, "content":self.current_ip}) + headers = { 'Content-Type': 'application/json'} + r = requests.put(self.url_base + url_end, auth = self.auth, data = data, headers=headers) + return + +if __name__ == "__main__": + script_path = os.path.dirname(os.path.abspath(__file__)) + script_name = os.path.basename(__file__) + logger = start_logging(script_path + '/DomainUpdater.log') + logger.info("__BEGIN_BATCH__") + domainupdater = DomainUpdater(script_path) + domainupdater.check_subdomains() + if len(domainupdater.updated_subdomain_list) > 0: + domainupdater.send_email_new_ip() + logger.info("__END_BATCH__") + + + + + diff --git a/python/DomainUpdater/DomainUpdater.py.2021-12-05 b/python/DomainUpdater/DomainUpdater.py.2021-12-05 new file mode 100644 index 0000000..b5d2271 --- /dev/null +++ b/python/DomainUpdater/DomainUpdater.py.2021-12-05 @@ -0,0 +1,136 @@ +#!/usr/bin/python3 + +# vplesnila 2019-06-24: creation +# vplesnila 2019-06-25: build self.subdomains_list +# vplesnila 2019-07-01: finalize update subdomains procedure and email sending +# vplesnila 2020-12-24: add subdomain list in config file to allow updating only a subset of dnsmanager.io registered subdomains + +import os +import smtplib +from email.message import EmailMessage +from email.mime.text import MIMEText +import socket +import json +import requests +import logging + +# LOGGING initialization function +def start_logging(logfile): + logger = logging.getLogger(__name__) + logger.setLevel(logging.INFO) + + # create a file handler + handler = logging.FileHandler(logfile) + handler.setLevel(logging.INFO) + + # create a logging format + formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') + handler.setFormatter(formatter) + + # add the handlers to the logger + logger.addHandler(handler) + return logger + +class DomainUpdater: + def __init__(self, rootdir): + self.rootdir = rootdir + + # Load configuration + with open(self.rootdir + "/" + "DomainUpdater.conf", "r") as f: + self.config = json.load(f) + + # Get current IP + r = requests.get(self.config["get_current_ip_api_url"]) + self.current_ip = r.json()["ip"] + logger.info("Current public IP is " + self.current_ip) + + # Build subdomain list as a ist of (subdomain name, domain_id, subdomain_id) + self.subdomains_list = [] + + self.auth = (self.config["dnsmanager_id"], self.config["dnsmanager_key"]) + self.url_base = self.config["dnsmanager_api_url_base"] + + # Get domains dictionary + url_end = "/user/domains" + r = requests.get(self.url_base + url_end, auth = self.auth) + domain_dict = r.json()["results"] + + # Get fqdn list + self.fqdn_list = self.config["subdomain_list"].split(",") + logger.info("Subdomains list: " + ",".join(self.fqdn_list)) + + self.fqdn_to_update = [] + for domain in domain_dict: + domain_name = domain["domain"] + domain_id = domain["id"] + url_end = "/user/domain/" + str(domain["id"]) + "/records" + r = requests.get(self.url_base + url_end, auth = self.auth) + records_dict = r.json()["results"] + for record_dict in records_dict: + if record_dict["type"] == "A": + # Subdomain + subdomain_id = record_dict["id"] + subdomain_name = record_dict["name"] + subdomain_ip = record_dict["content"] + fqdn = "%s.%s" % (subdomain_name, domain_name) + record = (fqdn, domain_id, subdomain_id, subdomain_ip) + if (fqdn in self.fqdn_list): + self.fqdn_to_update.append(fqdn) + self.subdomains_list.append(record) + + logger.info("Updating subdomain(s): " + ",".join(self.fqdn_to_update)) + return + + def send_email_new_ip(self): + msg = EmailMessage() + msg["Subject"] = "Your public IP changed" + msg["From"] = "domain-updater@databasepro.fr" + msg["To"] = "vplesnila@gmail.com" + body = """ + Hello, + You have a new public IP: %s + Following subdomains has been updated: %s + -------------- + Domain Updater + """ % (self.current_ip, ", ".join(self.updated_subdomain_list)) + msg.set_content(body) + s = smtplib.SMTP("localhost") + s.send_message(msg) + s.quit() + logger.info("Email sent to " + msg["To"]) + return + + def check_subdomains(self): + self.updated_subdomain_list=[] + for record in self.subdomains_list: + (fqdn, domain_id, subdomain_id, subdomain_ip) = record + if (subdomain_ip == self.current_ip): + logger.info(fqdn + " already set to " + subdomain_ip + ", nothing to do") + else: + logger.info("Updating " + fqdn + " with the new IP value " + self.current_ip) + self.update_subdomain(domain_id, subdomain_id) + self.updated_subdomain_list.append(fqdn) + return + + def update_subdomain(self, domain_id, subdomain_id): + url_end = "/user/domain/" + str(domain_id) + "/record/" + str(subdomain_id) + data = json.dumps({"id":subdomain_id, "content":self.current_ip}) + headers = { 'Content-Type': 'application/json'} + r = requests.put(self.url_base + url_end, auth = self.auth, data = data, headers=headers) + return + +if __name__ == "__main__": + script_path = os.path.dirname(os.path.abspath(__file__)) + script_name = os.path.basename(__file__) + logger = start_logging(script_path + '/DomainUpdater.log') + logger.info("__BEGIN_BATCH__") + domainupdater = DomainUpdater(script_path) + domainupdater.check_subdomains() + if len(domainupdater.updated_subdomain_list) > 0: + domainupdater.send_email_new_ip() + logger.info("__END_BATCH__") + + + + + diff --git a/python/DomainUpdater/__pycache__/DomainUpdater.cpython-36.pyc b/python/DomainUpdater/__pycache__/DomainUpdater.cpython-36.pyc new file mode 100644 index 0000000000000000000000000000000000000000..3c552e4a5b2ed1ccc92ff212bd70ee240132ad71 GIT binary patch literal 3795 zcma)9TXWmS6~+P}0bWJPHf6a@f?k}OsVz;Nv=5$4$MG%pOs%@LI!-X{pb&Q@f&vL@ zcj*fTd{SOB$q(os=zqvlr;mN;GalQg{slkvI}1vpoas!#!Pz|rXV31QJ3sDpn$d?} z{&}%sS^u_H9tZQgc-21vxW!p&h1JMH2HZ~Vi4!`EXin-*YGKXHSy~V4hTjW4Gy0)# z#zxrSF0XxMh0V_`UgzFd7WYo0+H;QrGmPap1y*Lui^1&@o@#(N*H+6B^ck@rK--y*vClfJH!L8u>jcI%~O~p%*uHcj9 zQPrSPdTDlem`o4D#-Y%^!Cc7Fk0RoZqR>|$((2HCvis<_Ve3(nipTMkr$UB}N12?& zT4UM<-#ONdIbSjj+>mxSz_PMVTY=ddoeDTO74TO}dQi*Tk9K61=^Zr^X}a?ugI=e9 znDH1}T*S6#Z_19+vDDG>{BS-?^#Cl^WNoK|;seaI4b@v55u!XjS`ZO*t2 zzjC<4U5xNDUdLGD9``ZUc>{WGmYoZS8j>h_XyXoEW8m*#_JS2wWNE-L++`Eaj@LP{ zzu8#W8pb8#fx~?P=l`Acd+Q5J*T!{lyWHI(7jOz^Y@b-Xwq=3O)Bd=@>AOeH%dA79 zHVwZ=99ZXXSqC<#ErT`8x;Aev+@<7p;cgOVi?_bE&*ZnatOcA7>pNQr9^N(Q>YDx5 zcz3*pZ=kL0+I#)?qV~Z0(|3z{QRh9Z_b{$w^!bKfujaIZU)r?(kKG%uXGH_@MvG?A zU%6k=gV}sPO@_gfXN^P!VTVuEB%UHW$SC1qcLhBX zZ^F$Ld?_v3kCn(fJ97ok=OzvmGK(9}^(geDQ1eu)u&d_#)yF7Jlzz)@=IhT-Nh%=P zouI5&ETx_BixPKoe@BX8Cb=qI{bnXg_F3stSNW!iLZpe{Y|9&J za3>gCDm{u=p2*V8W@1{pW0e7>SIl%X&P+Y51U5x=N%6 z@(Rgf2eM70M>6p>Y%R6NlcAPt_;f}wT4*dk!)EQJq9S4qTNP%IvVC@LW88Dh$XNY4 zD_uHkS+ACxlve@YTs4Z4X`-X(C&1J_0E^X~KI=O@)@41XZugPdTt;w%_3b(`osZvT zqF~;&3G*?petq!g{RgXAbo+FR3#Ez5lgV5&Otf`kEf_~(;`XP=Sr}c6HH>wP9-@hH ze~e5sMkz8;XrmmtRXL(u!yC)|-3ie#YOF zOug%m>qdegRYp(|lHDHGs6GH3)3}=N_2GE*^VtT=Ke*^@-&=p?brkkByvFNZV`A!= z^*SZ*LM_;*#^{gk0(ENPqCQcDveDq()edxJ_ty%i za8GPg2Q1WB(>5J5T{ba{0%H%43Mwg45pbLk>z0zp5+Z=KEm_O;8mhW zfgTCtH&31gFXMDBf`KP*;Ue;V0>*T7Nu%wuSK05}e3C+ZP&Y=9KPSGA2>gt|4FUrK z)Do@ahu&}`hDYZ@)FHkrYJA8X6!T4X)xL_c$MW|tn&RE1Lx+~(p*`rJ#uCpk;Y_1@ zG4&fd#2orU9d|TC%$um^&R;-Vpi|+sge_{?rM4BCbxeQZ6>fp%>1%g^CLS90cK=t| z*%{c9IwyGm-}*P)!*)RY7nm_DgRBg9)hyzWgys*aRqR zd_I|}O8M772%Xtn%Ma)~)e=~UoPI^i9}@aY0>2_a#o-;L%a1`*^fm!3b`@^!vuoee z@4E)x#b)H-WiyH<8K0-tj_ZeaG*0zn}_QMGsNCc>fDFkI*Xs literal 0 HcmV?d00001 diff --git a/python/Readme.md b/python/Readme.md new file mode 100644 index 0000000..d323271 --- /dev/null +++ b/python/Readme.md @@ -0,0 +1,2 @@ +Directory for Python scripts +---------------------------- diff --git a/python/scr_cod_dec/code.py b/python/scr_cod_dec/code.py new file mode 100644 index 0000000..b9b149d --- /dev/null +++ b/python/scr_cod_dec/code.py @@ -0,0 +1,15 @@ +#!/home/oracle/p3/bin/python + +import os + +k_scriptdir = "/mnt/yavin4/tmp/_oracle_/gitlab2/oracle/star" +scriptlist = sorted(os.listdir(k_scriptdir)) +for script in scriptlist: + if script.endswith(".sql"): + scriptlen = len(script) + script_underline = "".join("~" for i in range(scriptlen +4)) + print(f"{script_underline}\n~ {script} ~\n{script_underline}") + with open(k_scriptdir + "/" + script) as f: + file_contents = f.read().splitlines() + for script_line in file_contents: + print(f"\t{script_line}") diff --git a/python/scr_cod_dec/decode.py b/python/scr_cod_dec/decode.py new file mode 100644 index 0000000..7a8d3e6 --- /dev/null +++ b/python/scr_cod_dec/decode.py @@ -0,0 +1,34 @@ +#!/home/oracle/p3/bin/python + +import re +import fileinput + +ifile = "1-3.txt" +odir = "./unpack/" + +fc_cnt = sum(1 for line in fileinput.input(ifile)) +with open(ifile) as f: + fc = f.read().splitlines() + +i = 0 +while i