Helpful Aliases (Commands) to help you manage your node

Hi all looked around for helpful aliases and did not see this, and I usually set this up for myself to make my life easier. I will share here and hope you find this helpful.

In .bashrc:

export NODE_HOME=/home/ubuntu/cardano-node

In .bash_aliases having these makes remembering or copying a breeze:

## Node Home
alias cdnode='cd $NODE_HOME'
## Node Logs
alias nodelogs='journalctl --unit=cardano-node --follow'
## Node start
alias nodestart='sudo systemctl start cardano-node'
## Node Stop
alias nodestop='sudo systemctl stop cardano-node'
## Node Restart
alias noderestart='sudo systemctl restart cardano-node'
## Node Status
alias nodestatus='sudo systemctl status cardano-node'
## Node Enable
alias nodeenable='sudo systemctl enable cardano-node'
## Node Disable
alias nodedisable='sudo systemctl disable cardano-node'
## Node Graph
alias nodegraph='cd $NODE_HOME && ./gLiveView.sh'
## Pool Rewards
alias noderewards='cardano-cli query stake-address-info  --address $(cat $NODE_HOME/stake.addr) --allegra-era --mainnet'

Christian - [COINZ/COINX]

1 Like

some other ideas, omitting duplicates of the ones above:

alias cstat='systemctl --no-pager status cardano'
alias cstarts="nice grep 'Byron; Shelley' ~/node.log"
alias cquery='cardano-cli query utxo --mainnet --address'
alias csubmit='cardano-cli transaction submit --mainnet --tx-file'
alias ctail='tail -fn40 ~/node.log'
alias cpk='pkill tail'   # sometimes the "tail" process runs away if terminal shell dies
alias cless='less +F -R ~/node.log'
alias clogr='cp -p ~/node.log ~/node.log.`date "+%F-%H%M"`; \cp /dev/null ~/node.log'
alias ckes="curl -s 127.0.0.1:12798/metrics | grep cardano_node_metrics_remainingKESPeriods_int"

ctip() { cardano-cli query tip --mainnet | grep slotNo | awk '{print $NF}' ; }
# ... and allowing some reasonable amounts of time for transaction signing...
ctip5m() { cardano-cli query tip --mainnet | grep slotNo | awk '{print $NF + 300}' ; }
ctip10m() { cardano-cli query tip --mainnet | grep slotNo | awk '{print $NF + 600}' ; }
ctip15m() { cardano-cli query tip --mainnet | grep slotNo | awk '{print $NF + 900}' ; }

cokv() {
        local DB_LIVE=~/db
        local DB_SNAP=~/db.old
        ls -ld --time-style=long-iso $DB_LIVE/{ledger,immutable}
        ls -ld --time-style=long-iso $DB_SNAP/{ledger,immutable}
}

This last function checks that we have a current node DB backup, which we run by hand in our daily server health check with the following script (cok, confirming tip is advancing in tandem between BP & relays, and that transactions are showing on the BP, so therefore everything is “OK”):

DB_LIVE=~/db
DB_SNAP=~/db.old

nice rm -rf $DB_SNAP
mkdir $DB_SNAP
nice cp -pr $DB_LIVE/immutable $DB_SNAP/immutable
nice cp -pr $DB_LIVE/ledger $DB_SNAP/ledger
nice rsync -a $DB_LIVE/immutable/ $DB_SNAP/immutable
cp -p $DB_LIVE/protocolMagicId $DB_SNAP/protocolMagicId

# These confirm snapshot isn't loading system too much,
# and that all required components exist in the snapshot:
uptime | grep --color=auto 'load average'
ls -ld --time-style=long-iso $DB_LIVE/{ledger,immutable}
ls -ld --time-style=long-iso $DB_SNAP/{ledger,immutable}

Why we back up the blockchain & ledger daily this way (in case something goes wrong with the node that day):

Very cool, appreciate you sharing this.

1 Like

@COSDpool what is the point of this one?

alias cstarts="nice grep 'Byron; Shelley' ~/node.log"

I know it shows matching lines, but why is this important. Like I see this:

Feb 19 21:59:29 ip-172-31-21-181 bash[1023]: [ip-172-3:cardano.node.basicInfo.protocol:Notice:5] [2021-02-19 21:59:29.32 UTC] Byron; Shelley

Thanks in advance.

The node (from recent versions up through 1.25.1) prints Byron; Shelley in the log file when it starts. So this alias prints a list of the dates & times when the node (re)started. Our example, from SimpleView (basic text logging):

1:core$ cstarts
[core:cardano.node.basicInfo.protocol:Notice:5] [2021-01-29 18:30:13.90 UTC] Byron; Shelley
[core:cardano.node.basicInfo.protocol:Notice:5] [2021-02-15 10:19:26.18 UTC] Byron; Shelley
1 Like