P2Pool and scripting

I have a script for my P2Pool which I am not sure how to create or make. I am not really a *nix guy. I am using KDE so yes I know how to open KWrite and copy and paste the script into it, but I don’t know were to save it or if I need to make any changes using chmod to the file?

I appreciate your help!

Example script:

###sample script

#!/bin/bash

NICE=ps -eo pid,nice,command | grep '/home/btd/bitcoinroot/bin/bitcoind' | grep -v grep | awk '{ print $2 }'
PID=ps -eo pid,nice,command | grep '/home/btd/bitcoinroot/bin/bitcoind' | grep -v grep | awk '{ print $1 }'

P2P_NICE=ps -eo pid,nice,command | grep '/home/xo/p2pool/run_p2pool.py' | grep -v grep | awk '{ print $2 }'
P2P_PID=ps -eo pid,nice,command | grep '/home/xo/p2pool/run_p2pool.py' | grep -v grep | awk '{ print $1 }'

if $NICE -ne -20 ] ; then

echo “$PID is not nice!”
echo “Setting $PID to -20 nice value…”
renice -n -20 -p $PID
ionice -c1 -p $PID

else

echo “$PID is already set to nice value $NICE”
fi

if $P2P_NICE -ne -20 ] ; then

echo “p2pool is not running with nice”
echo “Setting $P2P_PID to -20 nice value…”
renice -n -20 -p $P2P_PID
ionice -c1 -p $P2P_PID

else
echo "p2pool is already running with $P2P_NICE "
fi

##script ends

##change txqueuelen of network interface
ifconfig ens32 txqueuelen 2000

For normal/single user you can put your script in

~/bin

aka

"$HOME/bin"

For system wide aka global script that everyone in your system can use it then it should be in

/usr/local/bin

The script needs to be executable too, either right click on the script using your mouse and make the permission executable or

chmod +x myscript

or

chmod +x ~/bin/myscript

myscript is arbitary in this case.

Once you have that script in your PATH ie either in ~/bin or /usr/local/bin then you can just awk for everything since you’re already using it. Here is my example

ps -eo pid,nice,command | awk '/virtualbox/'

085   0 /usr/lib/virtualbox/VBoxXPCOMIPCD
2099 0 /usr/lib/virtualbox/VBoxSVC --auto-shutdown
2193 0 /usr/lib/virtualbox/VBoxHeadless --comment Apache3 --startvm 847216e3-1d84-4327-9a6a-f1c4050bb792 --vrde config
9299 0 awk /virtualbox/

It prints the awk command as well that is why you needed then grep -v grep, using grep to avoid it

ps -eo pid,nice,command | grep '[v]irtualbox'
2085   0 /usr/lib/virtualbox/VBoxXPCOMIPCD
2099   0 /usr/lib/virtualbox/VBoxSVC --auto-shutdown
2193   0 /usr/lib/virtualbox/VBoxHeadless --comment Apache3 --startvm 847216e3-1d84-4327-9a6a-f1c4050bb792 --vrde config

However that needs an additional cut command or an awk command to print the second field. No worries since you can do that all in awk.

ps -eo pid,nice,command | awk '/[v]irtualbox/{print $1}'

ps -eo pid,nice,command | awk '/[v]irtualbox/{print $2}'

In your case that should be something like

nice=$(ps -eo pid,nice,command | awk  '/**itcoind/{print $2}')
pid=$(ps -eo pid,nice,command | awk  '/**itcoind/{print $1}')
p2p_nice=$(ps -eo pid,nice,command | awk '/[r]un_p2pool\.py/{ print $2 }')
p2p_pid=$(ps -eo pid,nice,command | awk '/[r]un_p2pool\.py/{ print $1 }')

The \ before the .py is to make the dot . literal since dot means any character in regrexp. That should be a start, the rest you can adjust as you learn more :).****