2022年12月7日星期三

shell different between return and exit

1. return used in function, 
    shell will continue after return from function 

2. exit used in everywhere of shell, stop and exit shell immediately.

example:
#========================
function testreturn(){
   echo "It will return 1"
   return 1
}

function testexit(){
   echo "It will exit 1"
   exit 1 
}

echo "start..."
testreturn
echo " after return "
testexit
echo " after exit"
#========================
#run result:
start...
It will return 1
after return 
It will exit 1
==========================

2022年11月17日星期四

check file changed or not by md5 hash code

windows powershell command:

PS C:\Users\test> certutil -hashfile destfile.zip md5

MD5 hash (対象 destfile.zip):

f6cb78afe66b417cd3f79df8d1c86444 

CertUtil: -hashfile コマンドは正常に完了しました。

linux command:

md5sum destfile.zip

 f6cb78afe66b417cd3f79df8d1c86444 destfile.zip


2022年11月11日星期五

git clone -b branchname url

git clone -b branchname https://domainname/group/project.git 


git clone -b branchname https://userid:token@domainname/group/project.git 


2022年11月8日星期二

Linux refresh .bashrc immediately source ~/.bashrc

 source ~/.bashrc 

linux shell setfacl /getfacl

$ setfacl --help

setfacl 2.2.51 -- set file access control lists Usage: setfacl [-bkndRLP] { -m|-M|-x|-X ... } file ... -m, --modify=acl modify the current ACL(s) of file(s) -M, --modify-file=file read ACL entries to modify from file -x, --remove=acl remove entries from the ACL(s) of file(s) -X, --remove-file=file read ACL entries to remove from file -b, --remove-all remove all extended ACL entries -k, --remove-default remove the default ACL --set=acl set the ACL of file(s), replacing the current ACL --set-file=file read ACL entries to set from file --mask do recalculate the effective rights mask -n, --no-mask don't recalculate the effective rights mask -d, --default operations apply to the default ACL -R, --recursive recurse into subdirectories -L, --logical logical walk, follow symbolic links -P, --physical physical walk, do not follow symbolic links --restore=file restore ACLs (inverse of `getfacl -R') --test test mode (ACLs are not modified) -v, --version print version and exit -h, --help this help text

#ex: $ setfacl -m u:testuser :rw test1.log
setfacl: Option -m incomplete
$ setfacl -m u:testuser:rw test1.log
$ getfacl test1.log
# file: test1.log # owner: ec2-user # group: ec2-user user::rw- user:ec2-user:rwx group::rw- mask::rwx other::r--

2022年11月1日星期二

shell if and or

 

  • && (AND) : if [ condition1 ] && [ condition2 ]; then 
       if [ -f $src/* ] && [ -d $dest ]; then 

          echo "there are files under $src"
          cp -rf $src/* $dest/
       else
          echo " directory $
dest is not found, or no files under $src" 
       fi


  • || (OR) : if [ condition1 ] || [ condition2 ]; then 
       

2022年10月27日星期四

2022年10月19日星期三

linux uname distribution check

# uname -a

Linux 6cfa069b60a5 4.14.291-218.527.amzn2.x86_64 #1 SMP Fri Aug 26 09:54:31 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

 

# cat /etc/os-release

NAME="Ubuntu"

VERSION="20.04.2 LTS (Focal Fossa)"

ID=ubuntu

ID_LIKE=debian

PRETTY_NAME="Ubuntu 20.04.2 LTS"

VERSION_ID="20.04"

HOME_URL="https://www.ubuntu.com/"

SUPPORT_URL="https://help.ubuntu.com/"

BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"

PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"

VERSION_CODENAME=focal

UBUNTU_CODENAME=focal

2022年10月14日星期五

shell sed insert. append replace

追加: i (insert), a(append) 注意:'中の処理は一つの処理とする'

sed -e '/pattern/ a内容'  #pattern行の後ろに、aで内容をappend

sed -e '/pattern/ i内容'  #pattern行の先頭に、iで内容をinsert


範囲限定の削除

sed -e '/fromPattern/,/toPattern/ d'  #fromPattern行(含む)~toPattern行(含む)まで、dで削除する

範囲限定の置換

sed -e '/fromPattern/,/toPattern/ s/pattern/replacement/'  #fromPattern行(含む)~toPattern行(含む)まで、sでpatternにmatchする文字列をreplacementで置換する。


2022年10月4日星期二

python3 regex .* vs .*? : match more or less, match, search, findall, sub

1.  .* vs  .*? :

import re

input='helloworld, 123abc,test'
pattern1='.*(\d+)'
pattern2='.*?(\d+)'

result1=re.match(pattern1, input)
result2=re.match(pattern2, input)

print(result1.group(1)) 
=> 3    # .* match more, \d+ match 3 only

print(result2.group(1)) 
=> 123 # .*? match less, \d+ match 123.  Generally used.

2. match, search, findall
pattern='test'
input2=' a test, b test '
m=re.match(pattern, input2)
print(m)
=>None
m=re.search(pattern, input2)
print(m)
=><_sre.SRE_Match object; span=(2, 6), match='test'>
print(m.group())
=>test
m=re.findall(pattern, input2)
print(m)
=>['test', 'test']

3. replace by sub() 
html = '''    <ul id="list" class="list-group">
        <li data-view="5"><a href="null">test1</a></li>
        <li data-view="6"><a href="null">test2</a></li>
    </ul>
    '''

html = re.sub('<a.*?>|</a>', '', html)
print(html)
=>    <ul id="list" class="list-group">
        <li data-view="5">test1</li>
        <li data-view="6">test2</li>
 </ul>

pattern = '<li.*?>(.*?)</li>'
results = re.findall(pattern, html, re.S)  # re.S改行
print(results)=> ["test1","test2"]
pattern = '<li.*>(.*)</li>'
results = re.findall(pattern, html, re.S)  # re.S改行
print(results)=> ["test2"]

4. get match group by name 
pattern = '<li.*?>(?P<text>.*?)</li>'
results = re.seach(pattern, html, re.S)  # re.S改行
print(results.group(1))=>test1
print(results.group("text"))=>test1

5. match lookahead assertion. (?=, ?! )
input1='hello world!'
input2='hello goodbye!'

pattern1='hello (?=world)'       #?=world: lookahead match
pattern2='hello (?!word)'  #?!world: lookahead not match 

r1=re.pattern(pattern1, input1)
print(r1.group())=>hello

r2=re.pattern(pattern2, input1)
print(r2.group())=>None
r3=re.pattern(pattern2, input2)
print(r3.group())=>hello

6. match lookbehind assertion. (?<=,?<! )
>>> m = re.search('(?<=abc)def', 'abcdef')  #?<=lookbehind match
>>> m.group(0)
'def'

m = re.search(r'(?<=-)\w+', 'spam-egg')     # must has - before \w+  
>>> m.group(0)
'egg'



2022年9月28日星期三

Oracle Alter user account lock/unlock

 - LOCK TEST_USER1
ALTER USER TEST_USER1 ACCOUNT LOCK;


- UNLOCK TEST_USER1
ALTER USER TEST_USER1 ACCOUNT UNLOCK;


2022年9月21日星期三

kali linux mount shared folder to windows folder

1. windows
    mkdir c:\my-shared
    echo "test" > test.txt

2. add shared folder in virtual Manager like 

     shared foldername: shared
     windows path: c:\my-shared
     access auth: full

3. goto linux vm 
    $ mkdir ~/wk-shared
    $ sudo mount -t vboxsf shared ~/wk-shared
    $ ll ~/wk-shared
      total 1
      -rwxrwxrwx 1 root root 63 Sep 21 14:24 test.txt

     

  
     

  


     

kali linux mysql init login

service mysql start 
sudo mysql -u root 

MariaDB [(none)]>  show databases

+--------------------+

| Database           |

+--------------------+

| information_schema |

| mysql              |

| performance_schema |

| sys                |

+--------------------+

4 rows in set (0.001 sec)


MariaDB [(none)]> select Host, User, Password  from mysql.user;

+-----------+-------------+----------+

| Host      | User        | Password |

+-----------+-------------+----------+

| localhost | mariadb.sys |          |

| localhost | root        | invalid  |

| localhost | mysql       | invalid  |

+-----------+-------------+----------+

3 rows in set (0.001 sec)

MariaDB [(none)]> use mysql 
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
MariaDB [mysql]> ALTER USER 'root'@'localhost' IDENTIFIED BY 'PASSWORD';
Query OK, 0 rows affected (0.012 sec)

MariaDB [mysql]> exit 
Bye
$ mysql -u root -p 
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 32
Server version: 10.6.8-MariaDB-1 Debian buildd-unstable

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> 

When forgot password. to next for reset 

$ service mysql stop  
$ sudo mysqld_safe --skip-grant-tables 
220921 10:31:13 mysqld_safe Logging to syslog.
220921 10:31:13 mysqld_safe Starting mariadbd daemon with databases from /var/lib/mysql

Open a new Terminal
mysql -u root mysql
FLUSH PRIVILEGES;
ALTER USER 'root'@'localhost' IDENTIFIED BY 'NEW_PASSWORD';
FLUSH PRIVILEGES;
quit
sudo kill `sudo cat /var/run/mysqld/mysqld.pid`

2022年9月16日星期五

postgresql db info

login to gitlab-Postgre-db:

gitlab-rails dbconsole
gitlab-psql -d gitlabhq_production

postgres=# \c dvdrental

You are now connected to database "dvdrental" as user "postgres".

\l = SELECT datname FROM pg_database;


gitlabhq_production=>  \d 

#list all objects of the db. include table,  sequence, and so on.

\d = select * from 


gitlabhq_production=>  \dt 
(\dt + :#show size)
(\dt  tablename :#show table columns)

#list all tables of the db

SELECT * FROM pg_catalog.pg_tables WHERE schemaname != 'pg_catalog' AND schemaname !=
schemaname != 'information_schema';
--'テーブル名'に存在する列一覧を取得
select * from information_schema.columns
where table_name='テーブル名' order by ordinal_position;

Linux reset gitlab root init_password

# ls -l /etc/gitlab/initial_root_password


gitlab-rake "gitlab:password:reset[root]"


Linux gitlab info

$ gitlab-ctl status 
# status of services

/# gitlab-rake gitlab:env:info

System information

System:

Proxy:          no

Current User:   git

Using RVM:      no

Ruby Version:   2.7.5p203

Gem Version:    3.1.6

Bundler Version:2.3.15

Rake Version:   13.0.6

Redis Version:  6.2.7

Sidekiq Version:6.4.0

Go Version:     unknown


GitLab information

Version:        15.3.3-ee

Revision:       1615d086ad8

Directory:      /opt/gitlab/embedded/service/gitlab-rails

DB Adapter:     PostgreSQL

DB Version:     13.6

URL:            http://gitlab.wangxg.com

HTTP Clone URL: http://gitlab.wangxg.com/some-group/some-project.git

SSH Clone URL:  git@gitlab.wangxg.com:some-group/some-project.git

Elasticsearch:  no

Geo:            no

Using LDAP:     no

Using Omniauth: yes

Omniauth Providers: 


GitLab Shell

Version:        14.10.0

Repository storage paths:

- default:      /var/opt/gitlab/git-data/repositories

GitLab Shell path:              /opt/gitlab/embedded/service/gitlab-shell

root@gitlab:/# 


Linux swap check create and using.

1. check current swap size 

$ free -m                                 

               total        used        free      shared  buff/cache   available

Mem:            4931         699        3260           7         971        3992

Swap:           1023           0        1023


2. create swap

$ sudo swapoff -a               
[sudo] password for kali: 

$ sudo dd if=/dev/zero of=/var/swapfile bs=1M count=4096
4096+0 records in
4096+0 records out
4294967296 bytes (4.3 GB, 4.0 GiB) copied, 7.89168 s, 544 MB/s
 
$ sudo mkswap /var/swapfile                             
mkswap: /var/swapfile: insecure permissions 0644, fix with: chmod 0600 /var/swapfile
Setting up swapspace version 1, size = 4 GiB (4294963200 bytes)
no label, UUID=0f0aef74-2c66-4c0c-b1d2-e7dd4bea06bc

$ sudo swapon /var/swapfile 
swapon: /var/swapfile: insecure permissions 0644, 0600 suggested.

$ chmod 600 /var/swapfile                                  
chmod: changing permissions of '/var/swapfile': Operation not permitted

$ free -m 
               total        used        free      shared  buff/cache   available
Mem:            4931        3807         174          23         950         839
Swap:           4095           0        4095
     

3. auto mount swap on os start

$ sudo echo "/var/swapfile swap swap defaults 0 0 " >> /etc/fstab 
$ cat  /etc/fstab
UUID=12deea7d-2c80-45a6-beb2-e91f0a02ca37       /       ext4    defaults,errors=remount-ro      0       1
/swapfile none swap defaults 0 0
/var/swapfile swap swap defaults 0 0 

2022年9月12日星期一

linux grep output group capture

grep can't output all group captures after one grep action.

so. each grep a time. 

ex.

input_string= "Caused by: java.io.FileNotFoundException: /tmp/storage/imart/public/storage/default/im_workflow/data/default/transaction/202107/21/16/ma_8g2mm9ovekgierj/result/ep_8g2mo7z76kgrmrj/flow.xml (No such file or directory)"

#I want to get
#[1]=/tmp/storage/imart/public/storage/default/im_workflow/data/default/transaction
#[2]=202107/21/16/
#[3]=ma_8g2mm9ovekgierj
#[4]=ep_8g2mo7z76kgrmrj

#cmd:
a1=$(echo $input_string | grep -ioE  "/tmp/.+/transaction")
echo $a1
:/tmp/storage/imart/public/storage/default/im_workflow/data/default/transaction

a2=$(echo $input_string | grep -ioE "[0-9]{6}/[0-9]{2}/[0-9]{2}")
echo $a2
=> 202107/21/16

a3=$(echo $input_string | grep -ioE "[0-9]{6}/[0-9]{2}/[0-9]{2}/\w+" | grep -ioE "\w+$")
echo $a3
:ma_8g2mm9ovekgierj

a4=$(echo $input_string | grep -ioE "\w+/flow" | grep -ioE "^\w+")
echo $a4
:ep_8g2mo7z76kgrmrj

$ echo $input_string | grep -ioE  "/tmp/.+/transaction"


log=webapps/imart/WEB-INF/log/platform/
found=$(find $log -type f -name "*.log"  | xargs grep -ionE "Caused by: java.io.FileNotFoundException:.+" )
for input_string in $(find $log -type f -name "*.log" | xargs grep -ionE "Caused by: java.io.FileNotFoundException:.+" )
do
  a1=$(echo $input_string | grep -ioE  "/tmp/.+/transaction")
  a2=$(echo $input_string | grep -ioE "[0-9]{6}/[0-9]{2}/[0-9]{2}")
  a3=$(echo $input_string | grep -ioE "[0-9]{6}/[0-9]{2}/[0-9]{2}/\w+" | grep -ioE "\w+$")
  a4=$(echo $input_string | grep -ioE "\w+/flow" | grep -ioE "^\w+")
  echo a1=$a1,a2=$a2,a3=$a3,a4=$a4
done 


2022年9月9日星期五

Linux ifconfig

#change network info 

#first reset a IP
ifconfig eth0 192.168.1.123 
#second reset netmask and broadcast for IP. 
ifconfig eth0 192.168.1.123 netmask 255.255.0.0 broadcast 192.168.1.255

#before change MAC, stop the network-adapter ethX.  
ifconfig eth0 down 

#third reset ether MAC for eth0
ifconfig eth0 hw ether 00:11:22:33:44:55
ifconfig eth0 up    #restart eth0

#request DHCP server for new IP
dhclient eth0 

#linux dns conf
more /etc/resolv.conf

 



linux cmd sed example

 1. sed s/mysql/MySQL/g test.conf >test2.conf 
     # replace all mysql to MySQL

 2. sed s/mysql/MySQL/ test.conf >test2.conf 
     # replace first mysql to MySQL

 3. sed s/mysql/MySQL/2 test.conf >test2.conf 
     # replace the second found mysql only to MySQL.



kali linux japanese keyboard layout setting

1. open setting/setting manager/keyboard.

2. tab to layout

3. add japanese and delete english

4. confirm keyboard layout = Generic 105-key PC (intl.)  

5. close window. setting completed.

2022年9月7日星期三

AI の初級考え方1:お菓子を買う

背景:

  こどもが300円までのお菓子を買うこと

条件:

  好きなお菓子の種類:
   1番はチョコレート   価格¥120 満足度:5
   2番はラムネ            価格¥80   満足度:4 
   3番はじゃがりこ      価格¥90     満足度:3

質問:

      300円まで、最善のお菓子組み合わせは何でしょう。

計算式:

      チョコレート:x 個
  ラムネ   :y 個
      ジャカリコ   : z 個

     前提条件式:       120x + 80y + 90z <=300
     求める式:          max(5x+4y+3z)
    

 

      


2022年8月31日星期三

intra-mart manul links

intra-mart Accel Platform IM-Workflow 仕様書 https://document.intra-mart.jp/library/iap/public/im_workflow/im_workflow_specification/index.html
intra-mart Accel Platform IM-Workflow 管理者操作ガイド https://document.intra-mart.jp/library/iap/public/im_workflow/im_workflow_administrator_guide/index.html
intra-mart Accel Platform IM-LogicDesigner ユーザ操作ガイド https://document.intra-mart.jp/library/iap/public/im_logic/im_logic_user_guide/index.html
intra-mart Accel Platform IM-LogicDesigner仕様書 https://document.intra-mart.jp/library/iap/public/im_logic/im_logic_specification/index.html
IM-BloomMaker チュートリアルガイド https://document.intra-mart.jp/library/bloommaker/public/im_bloommaker_tutorial_guide/index.html
IM-BloomMaker ユーザ操作ガイド https://document.intra-mart.jp/library/bloommaker/public/im_bloommaker_user_guide/index.html
IM-Repository ユーザ操作ガイド https://document.intra-mart.jp/library/iap/public/im_repository/im_repository_user_guide/index.html
IM-BloomMaker ユーザ操作ガイドCookBook https://document.intra-mart.jp/library/bloommaker/public/im_bloommaker_user_guide/texts/appendix/cookbook/index.html
IM-LogicDesigner仕様書 テンプレート https://document.intra-mart.jp/library/iap/public/im_logic/im_logic_specification/texts/function_specification/user_definition/template.html#id6
IM-LogicDesigner仕様書---タスク一覧 https://document.intra-mart.jp/library/iap/public/im_logic/im_logic_specification/texts/appendix/task_list.html
プログラミングガイド 入力チェックプログラム https://document.intra-mart.jp/library/forma/public/forma_programming_guide/texts/input_validation/index.html#common-programming-model-logicflow
IM-LogicDesigner仕様書  JavaScript https://document.intra-mart.jp/library/iap/public/im_logic/im_logic_specification/texts/function_specification/user_definition/javascript.html
IM-BIS 仕様書  暗黙的に連携するリクエストパラメータの仕様 https://document.intra-mart.jp/library/bis/public/bis_specification/texts/spec/external_linkage/external_linkage_request_spec.html
アクション処理¶ (logicdesigner 入出パラメータ) https://document.intra-mart.jp/library/iap/public/im_workflow/im_workflow_administrator_guide/texts/basic_guide/logic_flow/action_process.html
処理対象者プラグインに属するリソース全般 (logicdesigner 入出パラメータ) https://document.intra-mart.jp/library/iap/public/im_workflow/im_workflow_administrator_guide/texts/basic_guide/logic_flow/authority_plugin.html
intra-mart Accel Series ドキュメントライブラリ https://document.intra-mart.jp/library/index.html
Cookbook https://dev.intra-mart.jp/category/cookbook/
IM-Workflow CodeList https://api.intra-mart.jp/iap/javadoc/com/imwCodeList.html
申請処理Logic 前処理 https://document.intra-mart.jp/library/iap/public/im_workflow/im_workflow_specification/texts/appendix/bloommaker/permission.html

2022年8月22日星期一

git log --name-status

git log --name-status -n3
commit 482c51ab15
Author: wangxg
Date:   Mon Aug 22 13:15:09 2022 +0900
A       setting/database/ddl/BD0159.sql
A       setting/database/ddl/BD0160.sql
A       setting/database/ddl/BD0161.sql
A       setting/database/ddl/BD0162.sql
(END)

2022年7月20日星期三

docker images save and load , export and import

# docker save image to tar file      
docker save image:version -o imagename.tar 

# docker load image from tar file      
docker load < imagename.tar    #create image:latest

# docker export container to tar file       
docker export sample-container > sample-container.tar

# docker import  from tar file to image   
docker import sample-container.tar > sample-image:latest

2022年7月15日星期五

javascript match and exec

 3Q4:  https://step-learn.com/article/javascript/124-diff-match-exec.html

JavaScript では、正規表現にマッチした文字列を取得するメソッドとして、 match() メソッドと exec() メソッドがあります。

オブジェクト、書式の違い

まず、「どのオブジェクトのメソッドか」という違いがあります。 match() メソッドは String オブジェクトのメソッドで、 exec() メソッドは RedExp オブジェクトのメソッドです。

ですから、書式はそれぞれ次のようになります。


// match()
文字列.match(正規表現)

// exec()
正規表現.exec(文字列)

match() メソッド

// 文字列
var str = "cat map cut bat cute cap";

// 正規表現
var ex = /c.t/g;

var arr = str.match(ex);

for (var i = 0, len = arr.length; i < len; i++){
    console.log(arr[i]);
}

// 実行結果
cat
cut
cut


exec() メソッド

// 文字列
var str = "〒 135-0064\n〒 105-7444";

// 正規表現
var ex = /(\d{3})-(\d{4})/g;

var arr = [];

while((arr = ex.exec(str)) != null){
    console.log(arr);
    console.log('マッチ文字列:', arr[0]);
    console.log('lastIndex:', ex.lastIndex);
}

// 実行結果

Array [ "135-0064", "135", "0064" ]
マッチ文字列: 135-0064
lastIndex: 10

Array [ "105-7444", "105", "7444" ]
マッチ文字列: 105-7444
lastIndex: 21




chmod -R 760 destfolder

 ex. chmod -R 776 /var/local/resin/imart

2022年7月12日星期二

windows bat find key from string

set str=abcdefg

set key=abc

echo "%str%" | find "%key%" >NUL
if not ERRORLEVEL 1 goto OK_FOUND
:NOT_FOUND echo "NOT FOUND %key% in %str%. " pause exit /b :OK_FOUND


echo "GOOD! FOUND %key% in %str%. "
pause

2022年7月11日星期一

powershell PSSecurityException, FullyQualifiedErrorId : UnauthorizedAccess

REF:https://qiita.com/Targityen/items/3d2e0b5b0b7b04963750

現象:

c:\tmp.\test.ps1
... + .\test.ps1
+ ~~~~~~~~~~
+ CategoryInfo : セキュリティ エラー: (: ) []、PSSecurityException 
+ FullyQualifiedErrorId : UnauthorizedAccess 

原因:
PS C:\tmp\> get-executionPolicy
Restricted

実行ポリシー署名あり署名なし/ローカル署名なし/非ローカル説明
Restrictedxxxすべてのスクリプトの実行を制限 (初期設定)
AllSignedoxx署名のあるスクリプトのみ実行可能
RemoteSignedooxローカル上のスクリプトと非ローカル上の署名のあるスクリプトのみ実行可能
Unrestrictedooすべてのスクリプトが実行可能だが非ローカル上のスクリプトは実行時に許可が必要
Bypassoooすべてのスクリプトが実行可能

対策:
1. ps1ファイルに個別指定
c:\tmp>PowerShell -ExecutionPolicy RemoteSigned .\test.ps1


2. ps1ファイルに共通指定
c:\tmp>PowerShell Set-ExecutionPolicy RemoteSigned