Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.debian.user > #247268

Re: disable IPv6 debian

From Greg Wooledge <greg@wooledge.org>
Newsgroups linux.debian.user
Subject Re: disable IPv6 debian
Date 2022-04-16 02:50 +0200
Message-ID <EcENr-915z-3@gated-at.bofh.it> (permalink)
References (3 earlier) <EcvAt-8VxH-7@gated-at.bofh.it> <EcvAt-8VxH-5@gated-at.bofh.it> <EcEaJ-90SX-3@gated-at.bofh.it> <EcEkp-90W9-7@gated-at.bofh.it> <EcEu5-90Zc-1@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On Sat, Apr 16, 2022 at 08:20:40AM +0800, wilson wrote:
> Can you help check if my this script has any issue?

> #!/bin/bash
> 
> PORT=$1
> if [ -z $PORT ];then

"$PORT" should be quoted here.
 
>   echo "$0 port"

As a usage message, this is rather minimal.  At least put "usage: " in
front of it.  Ideally it should also be written to stderr, not stdout.

echo "usage: $0 port" >&2

>   exit

And you should exit with a nonzero status here, to indicate that an error
occurred.

exit 1

> fi
> 
> PS=`lsof -i :$PORT |grep LISTEN |awk '{print $2}'`

Backticks are deprecated.  $( ) is preferred for command substitution.

"$PORT" should be quoted here as well.

grep LISTEN | awk '{print $2}' can be combined into a single command:

awk '/LISTEN/ {print $2}'

> 
> if [ -z $PS ];then

"$PS" should be quoted.

>   echo "no this port, or I don't have privilege to list the port"

Use >&2 to send the error message to stderr.

>   exit

exit 1

> fi
> 
> ps -efw |grep $PS |grep -v grep

"$PS" should be quoted.

You're also going to exit your script with the exit status from that
last grep command.  That's probably not what you want.  If it's not,
then an explicit "exit 0" at the end might be a good idea.

Or, as another choice, you might want to exit with the exit status of
the *first* grep.  In that case, switching them around would be better:

ps -efw | grep -v grep | grep "$PS"

But it depends on whether you actually want that behavior.

> 
> Thanks

As a final note, using ALL-CAPS VARIABLE NAMES is a bad practice.  All-caps
variable names are reserved for environment variables, or special shell
internal variables like PATH, BASH_VERSION, RANDOM and so on.  Your
ordinary variables should contain at least one lower-case letter, to avoid
a name collision.

I don't think PORT or PS are used by anything... yet... but eventually
you're going to shoot yourself in the foot by accidentally picking
something like USER or PATH which *is* in use.  So, it's best to break
the bad habits now.

Back to linux.debian.user | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

disable IPv6 debian wilson <info@bigcount.xyz> - 2022-04-15 13:50 +0200
  Re: disable IPv6 debian 황병희 <soyeomul@doraji.xyz> - 2022-04-15 14:00 +0200
    Re: disable IPv6 debian wilson <info@bigcount.xyz> - 2022-04-15 14:30 +0200
      Re: disable IPv6 debian Greg Wooledge <greg@wooledge.org> - 2022-04-15 17:00 +0200
        Re: disable IPv6 debian Greg Wooledge <greg@wooledge.org> - 2022-04-15 18:00 +0200
          Re: disable IPv6 debian Tim Woodall <debianuser@woodall.me.uk> - 2022-04-15 18:10 +0200
        Re: disable IPv6 debian wilson <info@bigcount.xyz> - 2022-04-16 02:10 +0200
          Re: disable IPv6 debian Greg Wooledge <greg@wooledge.org> - 2022-04-16 02:20 +0200
            Re: disable IPv6 debian wilson <info@bigcount.xyz> - 2022-04-16 02:30 +0200
              Re: disable IPv6 debian Charles Curley <charlescurley@charlescurley.com> - 2022-04-16 02:40 +0200
              Re: disable IPv6 debian Greg Wooledge <greg@wooledge.org> - 2022-04-16 02:50 +0200
                Re: disable IPv6 debian wilson <info@bigcount.xyz> - 2022-04-16 03:10 +0200
                Re: disable IPv6 debian The Wanderer <wanderer@fastmail.fm> - 2022-04-16 03:50 +0200
                Re: disable IPv6 debian wilson <info@bigcount.xyz> - 2022-04-16 04:10 +0200
                Re: disable IPv6 debian Greg Wooledge <greg@wooledge.org> - 2022-04-16 05:00 +0200
                Re: disable IPv6 debian The Wanderer <wanderer@fastmail.fm> - 2022-04-16 14:10 +0200
                Re: disable IPv6 debian Greg Wooledge <greg@wooledge.org> - 2022-04-16 15:10 +0200
                Re: disable IPv6 debian David Wright <deblis@lionunicorn.co.uk> - 2022-04-16 18:10 +0200
                Re: disable IPv6 debian <tomas@tuxteam.de> - 2022-04-16 08:20 +0200
                Re: disable IPv6 debian Tim Woodall <debianuser@woodall.me.uk> - 2022-04-16 08:40 +0200
                Re: disable IPv6 debian wilson <info@bigcount.xyz> - 2022-04-16 10:30 +0200
                Re: disable IPv6 debian David <bouncingcats@gmail.com> - 2022-04-16 10:50 +0200
                Re: disable IPv6 debian Greg Wooledge <greg@wooledge.org> - 2022-04-16 15:00 +0200
            Re: disable IPv6 debian Michael Stone <mstone@debian.org> - 2022-04-16 20:00 +0200
          Re: disable IPv6 debian <tomas@tuxteam.de> - 2022-04-16 08:20 +0200
      Re: disable IPv6 debian Chuck Zmudzinski <brchuckz@netscape.net> - 2022-04-15 19:40 +0200
      Re: disable IPv6 debian Andy Smith <andy@strugglers.net> - 2022-04-16 01:00 +0200
        Re: disable IPv6 debian didar <nosferatu@purlo.in> - 2022-04-16 07:10 +0200
          Re: disable IPv6 debian Andy Smith <andy@strugglers.net> - 2022-04-16 11:50 +0200
  Re: disable IPv6 debian Reco <recoverym4n@enotuniq.net> - 2022-04-15 14:30 +0200
    Re: disable IPv6 debian wilson <info@bigcount.xyz> - 2022-04-15 14:40 +0200
      Re: disable IPv6 debian Erwan David <erwan@rail.eu.org> - 2022-04-15 16:00 +0200
        Re: disable IPv6 debian Jeremy Ardley <jeremy@ardley.org> - 2022-04-15 16:20 +0200
      Re: disable IPv6 debian Reco <recoverym4n@enotuniq.net> - 2022-04-15 16:20 +0200
  Re: disable IPv6 debian wilson <info@bigcount.xyz> - 2022-04-16 02:20 +0200
  Re: disable IPv6 debian Ash Joubert <ash@transient.nz> - 2022-04-16 02:20 +0200

csiph-web