sword
October 9, 2020, 8:44am
1
Copy&paste following context.
Name it as you wish. (e.g. cccommand.sh)
Place it under CreditcoinDocs-Mainnet-master directory
chmod 755 cccommand.sh
./cccommand.sh
##################################################################################
#!/bin/bash
creditcoin command selection
until [ “$opt” = “0” ]
do
echo “==================================================”
echo “1. 서버 및 클라이언트 실행”
echo “2. docker container 상태 확인”
echo “3. 내 서버원장의 블록높이 확인”
echo “4. 내가 캔 블록확인 (종료시 Ctrl+C)”
echo “5. validator 디버그 메시지 확인 (종료시 Ctrl+C)”
echo “6. peer 확인 (종료시 Ctrl+C)”
echo “7. sawtooth 설정확인”
echo “8. 서버 및 클라이언트 종료”
echo “0. 스크립트 종료”
echo “--------------------------------------------------”
printf "원하는 기능의 번호를 선택 후 엔터를 입력하세요 : "
read opt
echo "=================================================="
case $opt in
1)
echo "서버 및 클라이언트 도커 컨테이너를 실행합니다..."
docker-compose -f ./Server/creditcoin-with-gateway.yaml up -d
sleep 1
docker-compose -f ./Client/creditcoin-client.yaml up -d
sleep 1
;;
2)
echo "docker container 상태는 아래와 같습니다..."
docker container ls
;;
3)
echo "현재 서버 원장의 블록높이는 아래와 같습니다..."
docker exec -it creditcoin-client ./ccclient tip
;;
4)
echo "현재까지 채굴한 블록번호와 공개키는 아래와 같습니다..."
pub=$(docker exec -it sawtooth-validator-default sh -c "cat /etc/sawtooth/keys/validator.pub")
docker exec -it sawtooth-validator-default bash -c "sawtooth block list --url http://rest-api:8008 -F csv" | grep $pub | awk -F, 'BEGIN{printf("BLKNUM SIGNER\n")} {printf("%s\t%s\n", $1, $5)}'
;;
5)
docker exec sawtooth-validator-default tail -f /var/log/sawtooth/validator-debug.log
;;
6)
while true
do
timestamp() {
ts=`date +"%Y-%m-%d %H:%M:%S"`
echo -n $ts
}
REST_API_ENDPOINT=localhost:8008
peers=`curl http://$REST_API_ENDPOINT/peers 2>/dev/null | grep tcp:// | cut -d \" -f2 | sed 's/^.*\///'`
# For dynamic peering, need to log nc probe results to view history of connected peers over time.
for p in $peers; do
ipv4_address=`echo $p | cut -d: -f1`
port=`echo $p | cut -d: -f2`
timestamp
preamble=" Peer $ipv4_address:$port is"
if nc -z $ipv4_address $port
then
echo "$preamble open"
else
echo "$preamble closed"
fi
done
sleep 60
done | tee -a peercheck.result
;;
7)
echo "sawtooth 설정은 아래와 같습니다..."
docker exec -it sawtooth-validator-default sawtooth settings list --url http://rest-api:8008
;;
8)
echo "서버 및 클라이언트 도커 컨테이너를 종료합니다..."
docker-compose -f ./Client/creditcoin-client.yaml down
sleep 1
docker-compose -f ./Server/creditcoin-with-gateway.yaml down
sleep 1
;;
0)
break
;;
*)
echo "실행할 수 없는 옵션입니다"
;;
esac
echo ""
done
##################################################################################
3 Likes
Welcome to the community @sword ! It’s very encouraging to see the community has a desire to contribute to our ecosystem.
2 Likes
sword
October 12, 2020, 2:45am
3
#!/bin/bash
# creditcoin command selection
until [ "$opt" = "0" ]
do
CurBlkNum=0
PreBlkNum=0
echo "=================================================="
echo "1. 서버 및 클라이언트 실행"
echo "2. docker container 상태 확인"
echo "3. 내 서버원장의 블록높이 확인"
echo "4. 블록높이 감시 (1시간 동일 시 재기동)"
echo "5. 내가 캔 블록확인 (종료시 Ctrl+C)"
echo "6. validator 디버그 메시지 확인 (종료시 Ctrl+C)"
echo "7. peer 확인 (종료시 Ctrl+C)"
echo "8. 서버 및 클라이언트 종료"
echo "0. 스크립트 종료"
echo "--------------------------------------------------"
printf "원하는 기능의 번호를 선택 후 엔터를 입력하세요 : "
read opt
echo "=================================================="
case $opt in
1)
echo "서버 및 클라이언트 도커 컨테이너를 실행합니다..."
docker-compose -f ./Server/creditcoin-with-gateway.yaml up -d
sleep 1
docker-compose -f ./Client/creditcoin-client.yaml up -d
sleep 1
;;
2)
echo "docker container 상태는 아래와 같습니다..."
docker container ls
;;
3)
echo "현재 서버 원장의 블록높이는 아래와 같습니다..."
docker exec -it creditcoin-client ./ccclient tip
;;
4)
while true
do
CurBlkNum=$(docker exec -it creditcoin-client ./ccclient tip | awk '/^[0-9]/{print int($0)}')
if [ "$PreBlkNum" -eq 0 ]
then
echo "$(date "+%Y-%m-%d %H:%M:%S") | 현재 블록높이는 $CurBlkNum입니다."
elif [ "$PreBlkNum" -eq "$CurBlkNum" ]
then
echo "$(date "+%Y-%m-%d %H:%M:%S") | 현재 블록높이가 1시간 전과 같아 서버를 재기동합니다..."
docker-compose -f ./Client/creditcoin-client.yaml down
sleep 1
docker-compose -f ./Server/creditcoin-with-gateway.yaml down
sleep 1
docker-compose -f ./Server/creditcoin-with-gateway.yaml up -d
sleep 1
docker-compose -f ./Client/creditcoin-client.yaml up -d
sleep 1
else
echo "$(date "+%Y-%m-%d %H:%M:%S") | 1시간 전 블록높이는 $PreBlkNum이고 현재 블록높이는 $CurBlkNum입니다."
fi
PreBlkNum=$CurBlkNum
sleep 3600
done
;;
5)
echo "현재까지 채굴한 블록번호와 공개키는 아래와 같습니다..."
pub=$(docker exec -it sawtooth-validator-default sh -c "cat /etc/sawtooth/keys/validator.pub")
docker exec -it sawtooth-validator-default bash -c "sawtooth block list --url http://rest-api:8008 -F csv" | grep $pub | awk -F, 'BEGIN{printf("BLKNUM SIGNER\n")} {printf("%s\t%s\n", $1, $5)}'
;;
6)
docker exec sawtooth-validator-default tail -f /var/log/sawtooth/validator-debug.log
;;
7)
while true
do
timestamp() {
ts=`date +"%Y-%m-%d %H:%M:%S"`
echo -n $ts
}
REST_API_ENDPOINT=localhost:8008
peers=`curl http://$REST_API_ENDPOINT/peers 2>/dev/null | grep tcp:// | cut -d \" -f2 | sed 's/^.*\///'`
# For dynamic peering, need to log nc probe results to view history of connected peers over time.
for p in $peers; do
ipv4_address=`echo $p | cut -d: -f1`
port=`echo $p | cut -d: -f2`
timestamp
preamble=" Peer $ipv4_address:$port is"
if nc -z $ipv4_address $port
then
echo "$preamble open"
else
echo "$preamble closed"
fi
done
sleep 60
done | tee -a ctcpeer.result
;;
8)
echo "서버 및 클라이언트 도커 컨테이너를 종료합니다..."
docker-compose -f ./Client/creditcoin-client.yaml down
sleep 1
docker-compose -f ./Server/creditcoin-with-gateway.yaml down
sleep 1
;;
0)
break
;;
*)
echo "실행할 수 없는 옵션입니다"
;;
esac
echo ""
done
wind
October 12, 2020, 5:13am
4
So much thankful for all your support, sword!
2 Likes
@sword Is there any way you could add English comments to these scripts and maybe put them onto Github (Or give me permission to do so on your behalf )
1 Like
sword
July 16, 2021, 3:49am
6
Yes. My pleasure and honour.
I made some updates of script,and translated Korean to English.
So please review and debug it.
#!/bin/bash
# creditcoin command selection
until [ "$opt" = "0" ]
do
CurBlkNum=0
PreBlkNum=0
CurPeerNum=0
CurSrvBlkNum=0
echo "========================================================================="
echo "1. Start Sever&Client containers"
echo "2. Check docker containers' status"
echo "3. Monitor block height every 10 minute (press Ctrl+C to quit)"
echo "4. Monitor the block height (Restart if same height with an hour ago)"
echo "5. Check mining history on my server's perspective (press Ctrl+C to quit)"
echo "6. Print validator's debug messages (press Ctrl+C to quit)"
echo "7. Monitor my server's peer status (press Ctrl+C to quit)"
echo "8. Terminate Server&Client container"
echo "9. Print Private Key/Public Key/Sighash"
echo "0. Quit this script"
echo "-------------------------------------------------------------------------"
printf "Enter the number and press Enter : "
read opt
echo "========================================================================="
case $opt in
1)
echo "Starting Server&Client docker containers..."
docker-compose -f ./Server/creditcoin-with-gateway.yaml up -d
sleep 1
docker-compose -f ./Client/creditcoin-client.yaml up -d
sleep 1
;;
2)
echo "docker container's status are as following..."
docker container ls
;;
3)
echo "Monitoring Block height every 10 minute..."
while true
do
CurBlkNum=$(docker exec -it creditcoin-client ./ccclient tip | awk '/^[0-9]/{print int($0)}')
CurPeerNum=$(curl http://localhost:8008/peers 2>/dev/null | grep tcp | wc -l)
CurSrvBlkNum=$(curl https://api.creditcoinexplorer.com/api/blockchain 2>/dev/null | grep 'blockHeight' | awk -F[:,] '{gsub("\"", ""); print $2}')
echo "$(date "+%Y-%m-%d %H:%M:%S") | [Server] $CurBlkNum [Network] $CurSrvBlkNum [Peer] $CurPeerNum"
sleep 600
done
;;
4)
while true
do
CurBlkNum=$(docker exec -it creditcoin-client ./ccclient tip | awk '/^[0-9]/{print int($0)}')
if [ "$PreBlkNum" -eq 0 ]
then
echo "$(date "+%Y-%m-%d %H:%M:%S") | The Block height is $CurBlkNum."
elif [ "$PreBlkNum" -eq "$CurBlkNum" ]
then
echo "$(date "+%Y-%m-%d %H:%M:%S") | Restarting Server&Client containers as current block height is same with that of one hour ago..."
docker-compose -f ./Client/creditcoin-client.yaml down
sleep 1
docker-compose -f ./Server/creditcoin-with-gateway.yaml down
sleep 1
docker-compose -f ./Server/creditcoin-with-gateway.yaml up -d
sleep 1
docker-compose -f ./Client/creditcoin-client.yaml up -d
sleep 1
else
echo "$(date "+%Y-%m-%d %H:%M:%S") | The block height of one hour ago is $PreBlkNum, now is $CurBlkNum."
fi
PreBlkNum=$CurBlkNum
sleep 3600
done
;;
5)
echo "Mining history of this server's perspective is as following..."
echo "Please note that mining history of ledger's perspective would be different with this."
pub=$(docker exec -it sawtooth-validator-default sh -c "cat /etc/sawtooth/keys/validator.pub")
docker exec -it sawtooth-validator-default bash -c "sawtooth block list --url http://rest-api:8008 -F csv" | grep $pub | awk -F, 'BEGIN{printf("BLKNUM SIGNER\n")} {printf("%s\t%s\n", $1, $5)}'
;;
6)
echo "If no debug message printed, please check 'sawtooth-validator -vv' in 'Server/docker-compose.yaml', instead of 'sawtooth-validator'."
valog=$(docker inspect --format='{{.LogPath}}' sawtooth-validator-default)
sudo tail -f ${valog}
;;
7)
echo "Checking peers list&status every 1 minute..."
while true
do
timestamp() {
ts=`date +"%Y-%m-%d %H:%M:%S"`
echo -n $ts
}
REST_API_ENDPOINT=localhost:8008
peers=`curl http://$REST_API_ENDPOINT/peers 2>/dev/null | grep tcp:// | cut -d \" -f2 | sed 's/^.*\///'`
# For dynamic peering, need to log nc probe results to view history of connected peers over time.
for p in $peers; do
ipv4_address=`echo $p | cut -d: -f1`
port=`echo $p | cut -d: -f2`
timestamp
preamble=" Peer $ipv4_address:$port is"
if nc -z $ipv4_address $port
then
echo "$preamble open"
else
echo "$preamble closed"
fi
done
sleep 60
done | tee -a ctcpeer.result
;;
8)
echo "Terminating Server&Client docker containers..."
docker-compose -f ./Client/creditcoin-client.yaml down
sleep 1
docker-compose -f ./Server/creditcoin-with-gateway.yaml down
sleep 1
;;
9)
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!WARNING!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
echo "!YOU NEED TO TAKE EXTREME CAUTION TO SHARE THESE KEY WITH OTHERS, !"
echo "!BECAUSE YOUR ASSETS WILL BE STOLEN, ONCE YOUR PRIVATE KEY LEAKED.!"
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!WARNING!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
echo "### Private Key ###"
docker exec sawtooth-validator-default cat /etc/sawtooth/keys/validator.priv | grep "[0-9]"
echo "### Public Key ###"
docker exec sawtooth-validator-default cat /etc/sawtooth/keys/validator.pub | grep "[0-9]"
echo "### SigHash ###"
docker exec creditcoin-client ./ccclient sighash | grep "[0-9]"
;;
0)
break
;;
*)
echo "Not Available option."
;;
esac
echo ""
done
sword:
Place it under CreditcoinDocs-Mainnet-master directory
chmod 755 cccommand.sh
./cccommand.sh
Thanks @sword !
I made a few tweaks and committed it to my Creditcoin-Tools
repo here:
https://github.com/MrAusnadian/Creditcoin-Tools/tree/main/ccCommand
1 Like
uncle
July 18, 2021, 2:19am
8
I really appreciate your help!!! @sword
Leave a comment for beginners like me.
If you can’t run it, go to git-scm.com and install the program.
Open a folder explorer and the directory where you want to run the bash shell
Right-click on (folder with cccommand.sh file)
Click “Git Bash Here”.
Then type chmod +x ccCommand.sh and press Enter
Then, type sudo ./ccCommand.sh or ccCommand.sh to run it.
I don’t know if it will help others. Anyway thanks!!
1 Like
how can I extract this file?
Please help me.
I am using ‘Docker’ and ‘Winodws Powershell’.
Thank you very much for your help!!!
정말 감사합니다.
덕분에 한시름 덜었습니다.ㅎㅎ