I wrote the following bash script:

```
#!/bin/bash

TIMEOUT="5"
SESSIONS="8"

function usage {
    echo "Usage: $(basename $0) -l servers.list -c COMMAND"
    echo ""
    echo "Options:"
    echo "   -l               :     Provide list containing hostnames/ips"
    echo "   -c               :     Command to run"
    echo "   -u [optional]    :     Run commands remotely as supplied user"
    echo "   -r [optional]    :     Connect to remote machine as root, run commands as supplied user"
    echo ""
    echo " **** \"-u\" is mandatory if \"-r\" is used ****"
    echo ""
}

while getopts ":l:c:u:r:" opt; do
    case $opt in
        l)
            LIST=$OPTARG
        ;;
        c)
            COMMANDS="$OPTARG"
        ;;
        u)
            USER=$OPTARG
            USERSWITCH="-l $USER"
        ;;
        r)
            RUSER=$OPTARG
            RUSERSWITCH="-l root"
            RUSERCMD="su - $USER -c '$COMMANDS'"
        ;;
        *)
            usage
            exit 1
        ;;
    esac
done

if [[ -z $LIST ]] || [[ -z $COMMANDS ]]; then
    echo "Error - not enough arguments have been supplied"
fi

if [[ -z $USER ]]; then
    /usr/bin/pssh -i -p $SESSIONS -t 100000000 -x "-oStrictHostKeyChecking=no" -O ConnectTimeout=$TIMEOUT -h $LIST "$COMMANDS"
    echo "user not supplied"
elif [[ ! -z $USER ]] && [[ ! -z $RUSER ]]; then
    echo "connecting as root running as user"
    /usr/bin/pssh $RUSERSWITCH -i -p $SESSIONS -t 100000000 -x "-oStrictHostKeyChecking=no" -O ConnectTimeout=$TIMEOUT -h $LIST "$RUSERCMD"
elif [[ ! -z $USER ]] && [[ -z $RUSER ]]; then
    echo "Connecting as supplied user"
    /usr/bin/pssh $USERSWITCH -i -p $SESSIONS -t 100000000 -x "-oStrictHostKeyChecking=no" -O ConnectTimeout=$TIMEOUT -h $LIST "$COMMANDS"
fi

```

It basically wraps the command "parallel-ssh" and allows some more functionality which is required at my workplace, such as supplying a list or running commands as a specific user.

The script works perfectly.

The only issue I have is with the command supplied after the "-c" switch - it must be put inside ("") or the spaces in the command will cause the variable to get only the first word in the command.

How shall I edit the script so it would be able to get whatever is after the -c even if not put in ("")?