spycatcher
Posts: 1
Joined: Sat Jun 12, 2021 8:41 am

sudo question

Sat Jun 12, 2021 8:49 am

Hi guys, i'm a complete newbie to sudo. My problem is when i run the command "sudo iwlist wlan0 scan" to list the wi fi hosts within range of my wireless raspberry pi. The list shoots up the screen before i can see them. In DOS i would use the more command to show one screen at a time. What is the equivalent command in sudo. Thanks

markkuk
Posts: 277
Joined: Thu Mar 22, 2018 1:02 pm
Location: Finland

Re: sudo question

Sat Jun 12, 2021 11:05 am

The "more" command was copied to DOS from Unix and it's also available in LInux. Using "more" to page command output has nothing to do with sudo.

User avatar
kerry_s
Posts: 2190
Joined: Thu Jan 30, 2020 7:14 pm

Re: sudo question

Sat Jun 12, 2021 2:43 pm

Code: Select all

sudo iwlist wlan0 scan | less

andrum99
Posts: 1449
Joined: Fri Jul 20, 2012 2:41 pm

Re: sudo question

Sat Jun 12, 2021 4:45 pm

markkuk wrote:
Sat Jun 12, 2021 11:05 am
The "more" command was copied to DOS from Unix and it's also available in LInux. Using "more" to page command output has nothing to do with sudo.
No it wasn't. DOS's CLI was a clone of CP/M, which was loosely modelled on Unix.

swampdog
Posts: 729
Joined: Fri Dec 04, 2015 11:22 am

Re: sudo question

Sat Jun 12, 2021 8:07 pm

'sudo' invokes a command as the root user so (like here with 'iwlist') only use it if you have to.

You can redirect the output to a file if you like:

Code: Select all

foo@pi21:~ $ sudo iwlist wlan0 scan > ~/z
..then fiddle with it later..

Code: Select all

foo@pi21:~ $ cat z | egrep "(Address|Frequency|Quality|ESSID)(:|=)"

          Cell 01 - Address: C8:3A:35:F4:97:40
                    Frequency:2.437 GHz (Channel 6)
                    Quality=70/70  Signal level=-26 dBm  
                    ESSID:"eek"
          Cell 02 - Address: 48:5A:B6:6A:DD:89
                    Frequency:2.437 GHz (Channel 6)
                    Quality=26/70  Signal level=-84 dBm  
                    ESSID:"HP-Print-89-LaserJet 200 color"
          Cell 03 - Address: 10:C6:1F:F5:0D:FC
                    Frequency:2.412 GHz (Channel 1)
                    Quality=34/70  Signal level=-76 dBm  
                    ESSID:"BTHub3-GGZ2"
          Cell 04 - Address: 42:C6:1F:F5:0D:FD
                    Frequency:2.412 GHz (Channel 1)
                    Quality=35/70  Signal level=-75 dBm  
                    ESSID:"BTWi-fi"
          Cell 05 - Address: E8:DE:27:E9:83:EA
                    Frequency:2.437 GHz (Channel 6)
                    Quality=46/70  Signal level=-64 dBm  
                    ESSID:"ook!"
          Cell 06 - Address: E4:57:40:44:88:5C
                    Frequency:2.462 GHz (Channel 11)
                    Quality=50/70  Signal level=-60 dBm  
                    ESSID:"VM7506420"
          Cell 07 - Address: FA:8F:CA:7D:E9:37
                    Frequency:2.437 GHz (Channel 6)
                    Quality=26/70  Signal level=-84 dBm  
                    ESSID:"Bedroom TV.b"
..and when you've got it working, do it all in one line..

Code: Select all

foo@pi21:~ $ sudo iwlist wlan0 scan | egrep "(Address|Frequency|Quality|ESSID)(:|=)"

          Cell 01 - Address: C8:3A:35:F4:97:40
                    Frequency:2.437 GHz (Channel 6)
                    Quality=70/70  Signal level=-24 dBm  
                    ESSID:"eek"
          Cell 02 - Address: 48:5A:B6:6A:DD:89
                    Frequency:2.437 GHz (Channel 6)
                    Quality=25/70  Signal level=-85 dBm  
                    ESSID:"HP-Print-89-LaserJet 200 color"
          Cell 03 - Address: 10:C6:1F:F5:0D:FC
                    Frequency:2.412 GHz (Channel 1)
                    Quality=36/70  Signal level=-74 dBm  
                    ESSID:"BTHub3-GGZ2"
          Cell 04 - Address: 42:C6:1F:F5:0D:FD
                    Frequency:2.412 GHz (Channel 1)
                    Quality=33/70  Signal level=-77 dBm  
                    ESSID:"BTWi-fi"
          Cell 05 - Address: E8:DE:27:E9:83:EA
                    Frequency:2.437 GHz (Channel 6)
                    Quality=46/70  Signal level=-64 dBm  
                    ESSID:"ook!"
          Cell 06 - Address: E4:57:40:44:88:5C
                    Frequency:2.462 GHz (Channel 11)
                    Quality=50/70  Signal level=-60 dBm  
                    ESSID:"VM7506420"
          Cell 07 - Address: 48:D2:4F:0A:2E:41
                    Frequency:2.412 GHz (Channel 1)
                    Quality=22/70  Signal level=-88 dBm  
                    ESSID:"TALKTALK0A2E44"
The ">" denotes file redirection whereas "|" denotes a pipe. The former redirects output into a file(*) whereas the latter sends it to the input of the next program. You'll note that the file "z" isn't owned by root (because 'sudo' only ran 'iwlist' as root).

(*) slightly more complex than that. There's two output streams, one for normal (stdout) and one for errors (stderr) but that's for another time.

This kind of thing often goes nicely in a custom script..

Code: Select all

foo@pi21:~ $ cd;mkdir -p bin && cd bin && touch z-scan && chmod u+x z-scan

foo@pi21:~/bin $ cat z-scan

#!/bin/bash
sudo iwlist wlan0 scan | egrep "(Address|Frequency|Quality|ESSID)(:|=)"
Now you can run it when you want and you've buried 'sudo' (it'll still prompt if it needs to).

Hmm. That went off at a tangent. ;-)

User avatar
kerry_s
Posts: 2190
Joined: Thu Jan 30, 2020 7:14 pm

Re: sudo question

Sat Jun 12, 2021 9:50 pm

swampdog wrote:
Sat Jun 12, 2021 8:07 pm
'sudo' invokes a command as the root user so (like here with 'iwlist') only use it if you have to.

You can redirect the output to a file if you like:

Code: Select all

foo@pi21:~ $ sudo iwlist wlan0 scan > ~/z
..then fiddle with it later..

Code: Select all

foo@pi21:~ $ cat z | egrep "(Address|Frequency|Quality|ESSID)(:|=)"

          Cell 01 - Address: C8:3A:35:F4:97:40
                    Frequency:2.437 GHz (Channel 6)
                    Quality=70/70  Signal level=-26 dBm  
                    ESSID:"eek"
          Cell 02 - Address: 48:5A:B6:6A:DD:89
                    Frequency:2.437 GHz (Channel 6)
                    Quality=26/70  Signal level=-84 dBm  
                    ESSID:"HP-Print-89-LaserJet 200 color"
          Cell 03 - Address: 10:C6:1F:F5:0D:FC
                    Frequency:2.412 GHz (Channel 1)
                    Quality=34/70  Signal level=-76 dBm  
                    ESSID:"BTHub3-GGZ2"
          Cell 04 - Address: 42:C6:1F:F5:0D:FD
                    Frequency:2.412 GHz (Channel 1)
                    Quality=35/70  Signal level=-75 dBm  
                    ESSID:"BTWi-fi"
          Cell 05 - Address: E8:DE:27:E9:83:EA
                    Frequency:2.437 GHz (Channel 6)
                    Quality=46/70  Signal level=-64 dBm  
                    ESSID:"ook!"
          Cell 06 - Address: E4:57:40:44:88:5C
                    Frequency:2.462 GHz (Channel 11)
                    Quality=50/70  Signal level=-60 dBm  
                    ESSID:"VM7506420"
          Cell 07 - Address: FA:8F:CA:7D:E9:37
                    Frequency:2.437 GHz (Channel 6)
                    Quality=26/70  Signal level=-84 dBm  
                    ESSID:"Bedroom TV.b"
..and when you've got it working, do it all in one line..

Code: Select all

foo@pi21:~ $ sudo iwlist wlan0 scan | egrep "(Address|Frequency|Quality|ESSID)(:|=)"

          Cell 01 - Address: C8:3A:35:F4:97:40
                    Frequency:2.437 GHz (Channel 6)
                    Quality=70/70  Signal level=-24 dBm  
                    ESSID:"eek"
          Cell 02 - Address: 48:5A:B6:6A:DD:89
                    Frequency:2.437 GHz (Channel 6)
                    Quality=25/70  Signal level=-85 dBm  
                    ESSID:"HP-Print-89-LaserJet 200 color"
          Cell 03 - Address: 10:C6:1F:F5:0D:FC
                    Frequency:2.412 GHz (Channel 1)
                    Quality=36/70  Signal level=-74 dBm  
                    ESSID:"BTHub3-GGZ2"
          Cell 04 - Address: 42:C6:1F:F5:0D:FD
                    Frequency:2.412 GHz (Channel 1)
                    Quality=33/70  Signal level=-77 dBm  
                    ESSID:"BTWi-fi"
          Cell 05 - Address: E8:DE:27:E9:83:EA
                    Frequency:2.437 GHz (Channel 6)
                    Quality=46/70  Signal level=-64 dBm  
                    ESSID:"ook!"
          Cell 06 - Address: E4:57:40:44:88:5C
                    Frequency:2.462 GHz (Channel 11)
                    Quality=50/70  Signal level=-60 dBm  
                    ESSID:"VM7506420"
          Cell 07 - Address: 48:D2:4F:0A:2E:41
                    Frequency:2.412 GHz (Channel 1)
                    Quality=22/70  Signal level=-88 dBm  
                    ESSID:"TALKTALK0A2E44"
The ">" denotes file redirection whereas "|" denotes a pipe. The former redirects output into a file(*) whereas the latter sends it to the input of the next program. You'll note that the file "z" isn't owned by root (because 'sudo' only ran 'iwlist' as root).

(*) slightly more complex than that. There's two output streams, one for normal (stdout) and one for errors (stderr) but that's for another time.

This kind of thing often goes nicely in a custom script..

Code: Select all

foo@pi21:~ $ cd;mkdir -p bin && cd bin && touch z-scan && chmod u+x z-scan

foo@pi21:~/bin $ cat z-scan

#!/bin/bash
sudo iwlist wlan0 scan | egrep "(Address|Frequency|Quality|ESSID)(:|=)"
Now you can run it when you want and you've buried 'sudo' (it'll still prompt if it needs to).

Hmm. That went off at a tangent. ;-)
:lol:
kinda overkill for the question

Return to “Raspberry Pi OS”