GUNBOT: The automatic profit generator > Technical Support & Development

Simple bash script to start/stop a single pair in a Screen [LINUX]

(1/2) > >>

gionni:
I made up a little something for those who like to manage the bot manually.
Do take a look at this post by user shacky here if you want to start all your pairs at once instead:
https://gunthy.org/index.php?topic=129.0

Note that I'm using exactly the same command here to launch the bot and I respected the same screen naming. I haven't tested but I believe this script is compatible with shacky's script and you can use gunctl script to stop a single pair also launched with shacky's script.

- configure the botfolder in the script
- make the script executable: chmod u+x gunctl.sh

USAGE:
Start:
--- Code: --- ./gunctl.sh start [strategy] [pair] [exchange or leave blank for poloniex]
--- End code ---

Stop:
--- Code: ---./gunctl.sh stop [pair]
--- End code ---

List (running pairs, strategy and exchange):
--- Code: ---./gunctl.sh list [pair]
--- End code ---

View the running bot:
--- Code: ---screen -r PAIR_NAME
--- End code ---


--- Code: ---#!/bin/bash
########### EDIT PLEASE ###############
# exact folder where gunbot and config files are
botfolder="/your/path/to/gunbot/"
########## NO MORE EDIT ###############


############## DONT EDIT ##############

red=`tput setaf 1`
green=`tput setaf 2`
blue=`tput setaf 4`
reset=`tput sgr0`
cmd=$1
strat=$2
pair=$3
exchange=$4


echo "*********** GUNCTL - v0.0.2 - $( date ) ***************"

if [[ -n "$cmd" ]]; then
  if [[ "$cmd" == "list" ]]; then
  lookup='ps aux'
  printf "%-10s %-10s %-10s\n" "Strategy" "Pair" "Exchange"
  printf "%-10s %-10s %-10s\n" "----------" "----------" "----------"
  $lookup | grep -v grep | grep -v gunctl | grep "node [stepgain|BB|1000trades]" |  awk '{printf "%-10s %-10s %-10s\n",$12,$13,$14}' | sort -nk2
  exit 0
  fi 
  if [[ "$cmd" == "stop" ]]; then
    pair=$2
    if [[ -n "$pair" ]]; then
      if ! screen -list | grep -q "$2"; then
        echo "${red}Pair not running or not started with gunctl... ${reset}"
        exit 0
      else
        echo "${green}Stopping Pair $2${reset}"
        screen -S $2 -X quit
        echo "${blue}Pair $2 stopped.${reset}"
        sleep 0.2
        exit 0
      fi
    else
      echo "Pair is missing"
      exit 0
    fi

  fi
else
  echo "Command missing"
  echo "Usage: gunctl [start [strat] [pair] [exchange],stop [pair],list]"
  exit 0
fi
if [[ -n "$strat" ]]; then
  echo "Strategy: $2"
else
  echo "Strategy is missing"
  exit 0
fi
if [[ -n "$pair" ]]; then
  echo "Pair: $3"
else
  echo "Pair is missing"
  exit 0
fi
if [[ -n "$exchange" ]]; then
  echo "Exchange: $4"
else
  exchange="poloniex"
  echo "Exchange: Poloniex"
fi
cd $botfolder
echo ""
if ! ls | grep -qw "$3"; then
  echo "Config missing for $3"
  exit 0
fi
echo "Checking if pair $3 is running..."
if ! ps aux | grep -v grep | grep -v gunctl | grep "$3"; then
  echo "${red}Pair not running...${reset}"
  echo "${green}Starting $3 pair. ${reset}"

  screen -dmS $3
  screen -S $3 -p 0 -X exec node $2 $3 $4
else
  echo "${green}Pair $3 is already running${reset}"
  sleep 0.2
fi

--- End code ---

Clannad:
Nice work, thanks gionni for sharing this !

I'm especially interested with this part (you'll understand why if you read my latest post)


--- Quote from: gionni on May 06, 2017, 12:20:25 AM ---Stop:
--- Code: ---screen -S $2 -X quit
--- End code ---

--- End quote ---

Do you know in deep how screen stops a process associated with the window you quit ?

gionni:
I believe that it kills all the processes running from the window and then quit the screen session

Clannad:

--- Quote from: gionni on May 07, 2017, 12:49:30 AM ---I believe that it kills all the processes running from the window and then quit the screen session

--- End quote ---
Thanks for your answer :)
Well not exactly the kind of "smart" exit I am looking for ... but I guess there is no other way...

gionni:

--- Quote from: Clannad on May 09, 2017, 08:10:11 AM ---
--- Quote from: gionni on May 07, 2017, 12:49:30 AM ---I believe that it kills all the processes running from the window and then quit the screen session

--- End quote ---
Thanks for your answer :)
Well not exactly the kind of "smart" exit I am looking for ... but I guess there is no other way...

--- End quote ---

What were you looking for?

Navigation

[0] Message Index

[#] Next page

Go to full version