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)