ML
    • Recent
    • Categories
    • Tags
    • Popular
    • Users
    • Groups
    • Register
    • Login

    Solved How do you disconnect an OpenVPN tunnel on CentOS 7?

    IT Discussion
    4
    13
    2.5k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • S
      sn @thwr
      last edited by sn

      @thwr That was the perfect answer I was looking for! Thank you.

      One more question,
      I tried to create an alias for that command but it gave me a "-bash: alias: print: not found" error.
      I tried to replace awk '{ print $1 }' with cut -d' ' -f1 but still got similar error.
      Adding the command to a bash script also did not work.

      Am I doing anything wrong here or is there a better way to shorten the command?

      StrongBadS thwrT 2 Replies Last reply Reply Quote 1
      • StrongBadS
        StrongBad @sn
        last edited by

        @sn said in How do you disconnect an OpenVPN tunnel on CentOS 7?:

        @thwr That was the perfect answer I was looking for! Thank you.

        One more question,
        I tried to create an alias for that command but it gave me a "-bash: alias: print: not found" error.
        I tried to replace awk '{ print $1 }' with cut -d' ' -f1 but still got similar error.
        Adding the command to a bash script also did not work.

        Am I doing anything wrong here or is there a better way to shorten the command?

        What was the alias command that you attempted?

        S 1 Reply Last reply Reply Quote 1
        • thwrT
          thwr @sn
          last edited by

          @sn said in How do you disconnect an OpenVPN tunnel on CentOS 7?:

          @thwr That was the perfect answer I was looking for! Thank you.

          One more question,
          I tried to create an alias for that command but it gave me a "-bash: alias: print: not found" error.
          I tried to replace awk '{ print $1 }' with cut -d' ' -f1 but still got similar error.
          Adding the command to a bash script also did not work.

          Am I doing anything wrong here or is there a better way to shorten the command?

          Sure, np. Stopping an OpenVPN tunnel is basically just stopping the process. Signal 9 may be a bit hard, try lower levels to let it gracefully stop.

          About the alias: see @StrongBad's answer

          1 Reply Last reply Reply Quote 1
          • S
            sn @StrongBad
            last edited by

            @StrongBad I attempted to add the following line to the .bashrc

            alias openvpn-disconnect='kill -9 $( ps -e | grep openvpn | grep -v grep | awk '{ print $1 }' )'

            When sourced the .bashrc file, I received the following errors.

            -bash: alias: print: not found
            -bash: alias: } 😞 not found

            StrongBadS 1 Reply Last reply Reply Quote 0
            • StrongBadS
              StrongBad @sn
              last edited by

              @sn said in How do you disconnect an OpenVPN tunnel on CentOS 7?:

              @StrongBad I attempted to add the following line to the .bashrc

              alias openvpn-disconnect='kill -9 $( ps -e | grep openvpn | grep -v grep | awk '{ print $1 }' )'

              When sourced the .bashrc file, I received the following errors.

              -bash: alias: print: not found
              -bash: alias: } 😞 not found

              That's because you messed up your quotes. Look at them, you have this:

              kill -9 $( ps -e | grep openvpn | grep -v grep | awk
              

              Then you have this:

              { print $1 }
              

              Fix your quotes and it will likely work fine. If it doesn't run in a normal command line, it won't work in an alias command.

              S 1 Reply Last reply Reply Quote 0
              • S
                sn @StrongBad
                last edited by

                @StrongBad said in How do you disconnect an OpenVPN tunnel on CentOS 7?:

                @sn said in How do you disconnect an OpenVPN tunnel on CentOS 7?:

                @StrongBad I attempted to add the following line to the .bashrc

                alias openvpn-disconnect='kill -9 $( ps -e | grep openvpn | grep -v grep | awk '{ print $1 }' )'

                When sourced the .bashrc file, I received the following errors.

                -bash: alias: print: not found
                -bash: alias: } 😞 not found

                That's because you messed up your quotes. Look at them, you have this:

                kill -9 $( ps -e | grep openvpn | grep -v grep | awk
                

                Then you have this:

                { print $1 }
                

                Fix your quotes and it will likely work fine. If it doesn't run in a normal command line, it won't work in an alias command.

                It does run in a normal command line without changing the quotes!

                StrongBadS 1 Reply Last reply Reply Quote 0
                • StrongBadS
                  StrongBad @sn
                  last edited by

                  @sn are you sure? The quotes are definitely wrong. How do you run it normally? You put quotes around the whole thing?

                  1 Reply Last reply Reply Quote 1
                  • StrongBadS
                    StrongBad
                    last edited by

                    So you are running it like this...

                    openvpn-disconnect='kill -9 $( ps -e | grep openvpn | grep -v grep | awk '{ print $1 }' )'
                    

                    ANd the value of the variable is what you want?

                    S 1 Reply Last reply Reply Quote 1
                    • S
                      sn @StrongBad
                      last edited by

                      @StrongBad Thank you!, I fixed the quote and my alias is now working!!

                      Now let me explain.

                      As you suggested, it was absolutely related to the messy quotes I was using. I changed the outer one to double quotes as below and the alias worked immediately.

                      alias openvpn-disconnect="kill -9 $( ps -e | grep openvpn | grep -v grep | awk '{ print $1 }' )"

                      When I said it was working in a normal command line, I was just entering the command without the outer quotes which means there was only one set of quote ( around { print $1} ) and hence it worked without any issues.

                      @thwr Thank you again for "killer" command!

                      StrongBadS 1 Reply Last reply Reply Quote 2
                      • StrongBadS
                        StrongBad @sn
                        last edited by

                        @sn NP.

                        1 Reply Last reply Reply Quote 0
                        • 1 / 1
                        • First post
                          Last post