[COSMOS] 파티션 정리 & 커미션 분배 & 셀프 델리게이션 자동화(crontab)

91Savage·2023년 1월 31일
0

Cosmos

목록 보기
2/2
  • 원하는 경로에 sh 파일 생성 ex) vim /usr/backup.sh
    chmod +x /usr/backup.sh (실행 권한 추가)

[파티션 정리 & 백업]

  • backup.sh
#!/bin/bash

bu_path=~/.panacea/backup/
config=~/.panacea/config/config.toml

cp -a ~/.panacea/data/priv_validator_state.json $bu_path
reset=$(panacead tendermint unsafe-reset-all)



# Get the value of height and hash from the API
block_height=$(curl -s 13.124.96.254:26657/block | jq -r '.result.block.header.height')
block_hash=$(curl -s 13.124.96.254:26657/block | jq -r '.result.block_id.hash')

# Replace the trust_height and trush_hash value in config.toml
sed -i "s/trust_height = .*/trust_height = ${block_height}/g" $config
sed -i "s/trust_hash = .*/trust_hash = \"${block_hash}\"/g" $config



systemctl stop panacead

if echo "$reset" | grep -q "Reset private validator file to genesis state"; then

        # Start Panacead
        echo "$reset"
        systemctl start panacead

else
        # Print the output
        echo "$reset"
fi

[커미션 분배]

chmod +x /usr/distribution.sh (실행 권한 추가)

  • vim distribution.sh
#!/bin/bash
echo ""
echo "분배 받을 커미션"
check=$(panacead query distribution commission "validator 주소')
echo "$check"
echo ""
sleep 1

// 보유한 Commission 전액 분배
panacead tx distribution withdraw-rewards 'validator 주소' --from mblock --commission --chain-id=panacea-3 --gas-prices 5umed  --gas 200000 <<END
y
END

[셀프 델리게이션]

chmod +x /usr/delegation.sh (실행 권한 추가)

  • vim delegation.sh
#!/bin/bash

output=$(panacead query bank balances '주소')
amount=$(echo $output | grep -o -P '(?<=amount: ").*(?=" )')
s_amount=$((amount-10000000)) // 10 MED 정도는 available에 남겨두기 (tx 에 쓰기 위해)
echo""
echo " 위임 할 물량 : $s_amount "
echo ""
echo y | panacead tx staking delegate 'validator 주소' \
 "$s_amount"umed \
 --from 'moniker' \
 --chain-id panacea-3 \
 --gas-prices 5umed \
 --gas 200000

[자동화를 시키기 위해 크론탭에 적용]

  • crontab -e
// /root/go/bin 을 경로를 추가해줘야 함 (panacead 실행 데몬이 있는 경로)
# PATH
PATH=/bin:/usr/bin:/usr/local/bin:/root/go/bin 

# m h  dom mon dow   command

# 세달에 한 번 첫째 주 월요일 10시30분 에 실행
#30 1 1-7 */3 mon /usr//backup.sh >> /usr/backup.log 2>&1

# Every Monday 10:00 start
00 1 * * 1 /usr/distribution.sh >> /usr/distribution.log 2>&1

# Every Monday 10:05 start
05 1 * * 1 /usr/delegation.sh >> /usr/selfdelegation.log 2>&1

// 실행 경과를 확인하기 위해 shell이 실행 이후 로그파일을 만들어 로그를 남긴다.

0개의 댓글