Skip to content
Lowy Shin edited this page Dec 20, 2023 · 44 revisions
  • URL Encoding
str=`tail giipAgent.log`

echo "original string"
echo $str

encode=$(echo $str | jq -Rr '@uri')

echo "URL Encoded..."
echo $encode
strTxt=`cat ../gitrst.txt`
if [[ $strTxt == *"file changed"* ]]; then
  echo "File changed!!!"
fi
  • check file size
sFileName="<filename>"
if [ -s $sFileName ]; then
  echo "File size is not zero."
fi
  • file exists
sFileName="<filename>"
if [ -e $sFileName ]; then
  echo "File exist."
fi

Basic command

dtnow=`date +%Y%m%d`
dtprev=`date -d "1 day ago" +%Y%m%d`

echo "Today:${dtnow}, Yesterday:${dtprev}"
  • du

    • Show directory status
    • du -b /data | sort -n | grep -v test >du-data.txt
      • -b : show usage by byte
      • sort -n : sort by number(big size directory is below)
      • /data : target directory
  • ls -lt

    • show files sorting date
  • mv

    • for i in `find /orgpath -mtime +15 -type f`; do mv $i /targetpath; done
      • The files over 15 days from /orgpath to /targetpath
  • if you can not work cp and mv force on shell scripts, then use it

    • \cp -f origin.txt target.txt
    • \mv -f origin.txt target.txt
    • ignore alias command recent version of linux.
  • diff FileA FileB

    • compare with FileA and FileB.
  • fdisk

    • fdisk -l
      • list physical devices and format status
    • fdisk /dev/sdb
      • partitioning /dev/sdb
      • p : Check status selected partition
      • g : gpt mode change
      • n : Create new partition
      • w : Save changed
    • mkfs.ext4 /dev/sdb1
      • format partition of sdb1
    • mkdir -p /data2
    • mount /dev/sdb1 /data2
  • get current directory name

    • name only : basename ``pwd``
    • full path : pwd

Advanced scripting

execute by condition

  • git pull and changed target file, then execute it
git pull origin master >../${svrname}-gitsyncstat.txt
strTxt=`cat ../${svrname}-gitsyncstat.txt`

if [[ $strTxt == *"lwcmd.sh"* ]]; then
  # execute all fw rule
  sh sh/lwcmd.sh
  rm -rf lwcmd.sh
fi

String handling

It can be changed / to | when error on shell

#before
sed -e "s/PermitRootLogin yes/PermitRootLogin no/g" /etc/ssh/sshd_config>/etc/ssh/sshd_config_bak

#after
sed -e "s|PermitRootLogin yes|PermitRootLogin no"|g" /etc/ssh/sshd_config>/etc/ssh/sshd_config_bak
  • using one method without MID, SUBSTR, LEFT, RIGHT
lwStr="giipasp.azurewebsites.net"

echo ${lwStr:0:2}
# -> gi
echo ${lwStr:4}
# -> .net
echo ${lwStr:0:-4}
# -> giipasp.azurewebsites
echo ${lwStr%.*}
# -> giipasp.azurewebsites
echo ${lwStr%%.*}
# -> giipasp
echo ${lwStr#*.}
# -> azurewebsites.net
echo ${lwStr##*.}
# -> net

Server Configuration

disable root on ssh connection

  • Make sure create user by adduser and connect test before this process!!

sshblockroot.sh

cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bak

sed -e "s/PermitRootLogin yes/PermitRootLogin no/g" /etc/ssh/sshd_config>/etc/ssh/sshd_config_bak
sed -e "s/#PermitRootLogin/PermitRootLogin/g" /etc/ssh/sshd_config_bak>/etc/ssh/sshd_config
rm -f /etc/ssh/sshd_config_bak

service sshd restart

https://talklowykr.blogspot.com/2020/01/linux-root.html#more

  • add sudoer to user
usermod -aG wheel mylogin
  • check user group
cat /etc/group | grep mylogin
  • check sudoers file open wheel
cat /etc/sudoers | grep wheel

notice : delete comment when commented

mypid=`echo $$`
echo "$mypid"

jq(JSON Converter CLI)

datetime

  • Change Linux Time
### backup org localtime
cp /etc/localtime /etc/localtime.org

### Change to JST
ln -sf  /usr/share/zoneinfo/Asia/Tokyo /etc/localtime

vi editor

Change Terminal Color

by shell

cp /etc/DIR_COLORS ~/.dircolors
vi ~/.dircolors
``

Find and change color code `~/.dircolors`
```vim
DIR 01;36       # directory
LINK 36;01      # symbolic link 

httpd

httpd -t -D DUMP_CONFIG 2>/dev/null | grep '# In' | awk '{print $4}' # 設定ファイル一覧
httpd -t -D DUMP_CONFIG 2>/dev/null | grep -v '#'                    # 設定ファイル内容
httpd -V                 # コンパイル時の設定
httpd -S -D SSL          # 実行時の設定
httpd -l                 # 静的モジュール一覧
httpd -M                 # ロード済みモジュール一覧
rpm -qi httpd            # パッケージ情報
rpm -q --changelog httpd # パッケージ更新履歴

Links

Translate this page?

Data(DBMS, NoSQL)

Development

Tools

Management

OS

Hardware

Business

Hobby

Lifestyle

Giip(RPA Engine)

Clone this wiki locally