3

Is it possible to provide more than one variable to be executed in first prompt? at first prompt I would like to provide 1 or 2 up to 5 variables which are executing particular script within one session.

e.g.:

echo -n "Enter the script you want to launch and press [ENTER]
read script

Instead of $script, I would like to have some alternative like reading script1 or script2 ... up to script5, which allows me to execute with this single entry launch any number of script #i want, and at any combination (eg 1 and 2, 1 and 3 and 5, etc)

echo "Hello, "$USER".  This script will allow you to start $
echo "1. Claymore ZEC v12.6"
echo "2. Claymore ETH & SIA v10"
echo "3. Claymore ETH  v10"
echo "4. XMRIG ETN v2.4.4 //etn-pool.proxpool"
echo "5. XMRIG ETN v2.4.4 //pool.etn.spacepools.org"
echo "6. Quit"
echo -n "Enter the script you want to launch and press [ENT$
read script
case $script in
1) 
  echo "Starting to mine ZEC."
  cd ~/Downloads/claymore.s.Zcash.v12.6/;
  ./mine.sh;
  ;;
2)
  echo "Starting to mine ETH & SIA."
  cd ~/Downloads/claymore.dualminer.v10_ETHSIA/;
  ./mine.sh;
  ;;
3)
  echo "Starting to mine ETH."
  cd ~/Downloads/claymore.dualminer.v10_ETHSIA/;
  ./mineETH.sh;
  ;;
4)
  echo "Starting to mine ETN."
  cd ~/Downloads/Electroneum/XMRIG/build/;
  sudo sysctl -w vm.nr_hugepages=128;
  clear;
  cat /proc/meminfo | grep Huge;
  ./mine.sh;
  ;;
5)
  echo "Starting to mine ETN."
  cd ~/Downloads/Electroneum/XMRIG/build/;
  sudo sysctl -w vm.nr_hugepages=128;
  clear;
  cat /proc/meminfo | grep Huge;
  ./mine_space.sh;
  ;;
6) 
  echo "Quit"
  ;;
esac
Kevin Bowen
  • 20,055
  • 57
  • 82
  • 84

2 Answers2

1

You can use bash read command in order to get several parameters from the user.

The below example was taken from bash input tutorial

The below script read 3 input parameters in one read command and use those 3 unique parameters later in the script.

cars.sh script

#!/bin/bash
# Demonstrate how read actually works
echo What cars do you like?
read car1 car2 car3
echo Your first car was: $car1
echo Your second car was: $car2
echo Your third car was: $car3

Terminal execution:

./cars.sh
What cars do you like?
Jaguar Maserati Bentley
Your first car was: Jaguar
Your second car was: Maserati
Your third car was: Bentley
./cars.sh
What cars do you like?
Jaguar Maserati Bentley Lotus
Your first car was: Jaguar
Your second car was: Maserati
Your third car was: Bentley Lotus
Yaron
  • 13,453
1

I threw one together for you based on the comment left from @steeldriver. This is just a command line script allowing multiple input on the command line. It uses getopts for multiple options as well as adding in nohup command & for moving the scripts to the background so that the next case can run.

For further help, search the internet for bash getopts. There's so much to learn out there and you can make incredible scripts to do whatever you want.

The Script:

#!/bin/bash

#Set name
NAME=$(basename $0)

#Set option choices
OPTS="h12345"
PUSAGE=""

#This is how to use the script
usage="
Hello, "$USER".  This script will allow you to start the following. 
You can run as many as you like starting with a `-`.  Example below.

Usage:  ${NAME} [OPTIONS]

Options are:
  -h  Show this message.
  -1. Claymore ZEC v12.6
  -2. Claymore ETH & SIA v10
  -3. Claymore ETH  v10
  -4. XMRIG ETN v2.4.4 //etn-pool.proxpool
  -5. XMRIG ETN v2.4.4 //pool.etn.spacepools.org

Example:

${NAME} -135
"

#Run script
while getopts :${OPTS} i ; do
    case $i in
    1) 
      echo "Starting to mine ZEC."
      cd ~/Downloads/claymore.s.Zcash.v12.6/
      nohup ./mine.sh & 2>&1>/dev/null;;
    2)
      echo "Starting to mine ETH & SIA."
      cd ~/Downloads/claymore.dualminer.v10_ETHSIA/
      nohup ./mine.sh & 2>&1>/dev/null;;
    3)
      echo "Starting to mine ETH."
      cd ~/Downloads/claymore.dualminer.v10_ETHSIA/
      nohup ./mineETH.sh & 2>&1>/dev/null;;
    4)
      echo "Starting to mine ETN."
      cd ~/Downloads/Electroneum/XMRIG/build/
      sudo sysctl -w vm.nr_hugepages=128
      clear
      cat /proc/meminfo | grep Huge
      nohup ./mine.sh & 2>&1>/dev/null;;
    5)
      echo "Starting to mine ETN."
      cd ~/Downloads/Electroneum/XMRIG/build/
      sudo sysctl -w vm.nr_hugepages=128
      clear
      cat /proc/meminfo | grep Huge
      nohup ./mine_space.sh & 2>&1>/dev/null;;
    h | \?) PUSAGE=1;;
    esac
done

#Show help based on selection
if [ ${PUSAGE} ]; then
    echo "${usage}"
    exit 0
fi

#Check for input if none show help.
if [[ $1 == "" ]]; then
    echo "${usage}"
    exit 0
fi

Now, if you run the script with nothing after or a -h for help, the following appears. I named my script askhelp.bsh just as an example.

~$ ./askhelp.bsh

Hello, terrance.  This script will allow you to start the following. 
You can run as many as you like separated by spaces and dashes. Example below.

Usage:  askhelp.bsh [OPTIONS]

Options are:
  -h  Show this message.
  -1. Claymore ZEC v12.6
  -2. Claymore ETH & SIA v10
  -3. Claymore ETH  v10
  -4. XMRIG ETN v2.4.4 //etn-pool.proxpool
  -5. XMRIG ETN v2.4.4 //pool.etn.spacepools.org

Example:

askhelp.bsh -135

Then in my test script I made it so that it echoes the lines to show that they are running.

Examples:

~$ ./askhelp.bsh -135
Starting Option 1
Starting to mine ZEC.
cd ~/Downloads/claymore.s.Zcash.v12.6/
nohup ./mine.sh & 2>&1>/dev/null
Starting Option 3
Starting to mine ETH.
cd ~/Downloads/claymore.dualminer.v10_ETHSIA/
nohup ./mineETH.sh & 2>&1>/dev/null
Starting Option 5
Starting to mine ETN.
cd ~/Downloads/Electroneum/XMRIG/build/
sudo sysctl -w vm.nr_hugepages=128
clear
cat /proc/meminfo | grep Huge
nohup ./mine_space.sh & 2>&1>/dev/null

Another example:

~$ ./askhelp.bsh -24
Starting Option 2
Starting to mine ETH & SIA.
cd ~/Downloads/claymore.dualminer.v10_ETHSIA/
nohup ./mine.sh & 2>&1>/dev/null
Starting Option 4
Starting to mine ETN.
cd ~/Downloads/Electroneum/XMRIG/build/
sudo sysctl -w vm.nr_hugepages=128
clear
cat /proc/meminfo | grep Huge
nohup ./mine.sh & 2>&1>/dev/null

New script from request:

This script should open a new gnome-terminal for each choice made for tracking back. The commands are done for gnome-terminal. If you decide to use a different terminal, make sure you make the appropriate changes to the command in each case statement.

#!/bin/bash

#Set name
NAME=$(basename $0)

#Set option choices
OPTS="h12345"
PUSAGE=""

#This is how to use the script
usage="
Hello, "$USER".  This script will allow you to start the following. 
You can run as many as you like starting with a `-`.  Example below.

Usage:  ${NAME} [OPTIONS]

Options are:
  -h  Show this message.
  -1. Claymore ZEC v12.6
  -2. Claymore ETH & SIA v10
  -3. Claymore ETH  v10
  -4. XMRIG ETN v2.4.4 //etn-pool.proxpool
  -5. XMRIG ETN v2.4.4 //pool.etn.spacepools.org

Example:

${NAME} -135
"

#Run script
while getopts :${OPTS} i ; do
    case $i in
    1) 
      gnome-terminal -x bash -c 'echo "Starting to mine ZEC."; cd ~/Downloads/claymore.s.Zcash.v12.6/; ./mine.sh';;
    2)
      gnome-terminal -x bash -c 'echo "Starting to mine ETH & SIA."; cd ~/Downloads/claymore.dualminer.v10_ETHSIA/; ./mine.sh';;
    3)
      gnome-terminal -x bash -c 'echo "Starting to mine ETH."; cd ~/Downloads/claymore.dualminer.v10_ETHSIA/; ./mineETH.sh';;
    4)
      gnome-terminal -x bash -c 'echo "Starting to mine ETN."; cd ~/Downloads/Electroneum/XMRIG/build/; sudo sysctl -w vm.nr_hugepages=128; clear; cat /proc/meminfo | grep Huge; ./mine.sh';;
    5)
      gnome-terminal -x bash -c 'echo "Starting to mine ETN."; cd ~/Downloads/Electroneum/XMRIG/build/; sudo sysctl -w vm.nr_hugepages=128; clear; cat /proc/meminfo | grep Huge; ./mine_space.sh';;
    h | \?) PUSAGE=1;;
    esac
done

#Show help based on selection
if [ ${PUSAGE} ]; then
    echo "${usage}"
    exit 0
fi

#Check for input if none show help.
if [[ $1 == "" ]]; then
    echo "${usage}"
    exit 0
fi

Hope this helps!

Terrance
  • 43,712