How to specify more spaces for the delimiter using cut?

前端 未结 12 687
遥遥无期
遥遥无期 2020-12-04 05:51

Is there any way to specify a field delimiter for more spaces with the cut command? (like \" \"+) ? For example: In the following string, I like to reach value \'3744\', wha

12条回答
  •  执念已碎
    2020-12-04 06:29

    My approach is to store the PID to a file in /tmp, and to find the right process using the -S option for ssh. That might be a misuse but works for me.

    #!/bin/bash
    
    TARGET_REDIS=${1:-redis.someserver.com}
    PROXY="proxy.somewhere.com"
    
    LOCAL_PORT=${2:-6379}
    
    if [ "$1" == "stop" ] ; then
        kill `cat /tmp/sshTunel${LOCAL_PORT}-pid`
        exit
    fi
    
    set -x
    
    ssh -f -i ~/.ssh/aws.pem centos@$PROXY -L $LOCAL_PORT:$TARGET_REDIS:6379 -N -S /tmp/sshTunel$LOCAL_PORT  ## AWS DocService dev, DNS alias
    # SSH_PID=$! ## Only works with &
    SSH_PID=`ps aux | grep sshTunel${LOCAL_PORT} | grep -v grep | awk '{print $2}'`
    echo $SSH_PID > /tmp/sshTunel${LOCAL_PORT}-pid
    

    Better approach might be to query for the SSH_PID right before killing it, since the file might be stale and it would kill a wrong process.

提交回复
热议问题