티스토리 뷰

공부

[sh] start.sh

승가비 2023. 8. 20. 14:07
728x90
#!/bin/bash

PORT=8000
FORCE=false

while [ $# -gt 0 ]; do
    opt="$1";
    shift;

    case "$opt" in
        --force|-f)
            FORCE=true
            ;;
        *)
            echo "Unknown argument: $1"
            ;;
    esac
done

RUNNING=false
if lsof -i :${PORT} >/dev/null 2>&1; then
    RUNNING=true
fi

t=$(date "+%Y-%m-%d %H:%M:%S")
if [ "${RUNNING}" = false ] || [ "${FORCE}" = true ]; then
    pid=$(lsof -ti:${PORT})
    kill -9 ${pid}

    mkdir -p ~/log

    . .venv/bin/activate
    source ./sh/env.sh
    PYTHONPATH=$PYTHONPATH:../ python3 app.py 2> ~/log/api.txt &

    echo "[${t}] [INFO] started."
else
    echo "[${t}] [INFO] already running."
fi
#!/bin/bash

PORT=80
FORCE=false
DEV=false
STG=false

while [ $# -gt 0 ]; do
    opt="$1";
    shift;

    case "$opt" in
        --force|-f)
            FORCE=true
            ;;
        --dev|-d)
            DEV=true
            ;;
        --stg|-s)
            STG=true
            ;;
        *)
            echo "Unknown argument: $1"
            ;;
    esac
done

RUNNING=false
if lsof -i :${PORT} >/dev/null 2>&1; then
    RUNNING=true
fi

t=$(date "+%Y-%m-%d %H:%M:%S")
if [ "${RUNNING}" = false ] || [ "${FORCE}" = true ]; then
    pid=$(lsof -ti:${PORT})
    kill -9 ${pid}

    if [ ${DEV} = true ]; then
        sudo npm start --yes &
        exit 0
    fi

    if [ ${STG} = true ]; then
        sudo npm run start:stg --yes &
        exit 0
    fi

    mkdir -p ~/log
    sudo npm run start:prd -- -p ${PORT} 2> ~/log/ui.txt &

    echo "[${t}] [INFO] started."
else
    echo "[${t}] [INFO] already running."
fi

https://stackoverflow.com/questions/14062895/bash-argument-case-for-args-in

 

bash argument case for args in $@

I have a script with a long list of OPTIONAL arguments. some have associated values. Such as: .script --first 2012-12-25 --last 2012-12-26 --copy --remove .script --first 2012-12-25 Thus the

stackoverflow.com

 

728x90
댓글