Category Archives: Linux

How to Find Your Raspberry Pi in Your Network Using Nmap

Bildschirmfoto 2016-09-09 um 09.01.26

sudo nmap -sn 192.168.1.0/24 | grep -B 2 Raspberry

First you have to find your current IP address and netmask. If you don’t know what a netmask is, chances are you have a 24-bit netmask (which you may have seen in this format: 255.255.255.0).

The -sn option in nmap disables port scanning. This allows for a much faster, host discovery-only scan. After nmap is done, we are piping its output into grep, so that we can filter out our Raspberry Pi devices. The -B option stands for “before”, which means that grep will include the upper two lines of the output too. Without them we would only see the MAC address.

If you put this command in our ~/.bash_profile file with an alias, we can simply type “findpi” into a terminal and are done (see screenshot above)!

alias findpi='sudo nmap -sn 192.168.1.0/24 | grep -B 2 Raspberry'

Autostart any Script using crontab

This guide is targeted at Raspian (Raspberry Pi) but it will work with most Linux distributions.

First, create your script using your editor of choice. Make sure you know the location of it!

nano superscript.sh

 

Make it executable:

chmod +x superscript.sh

 

Now edit your crontab file using this command:

crontab -e

 

Go to the bottom of the file and add the following line (lines starting with a # will be ignored):

@reboot sh /home/pi/superscript.sh > /home/pi/superscript-cronlog 2>&1
@reboot
Tells crontab to execute this command after a boot
sh
Uses sh to execute your script. Of course you can use any other shell too.
/home/pi/superscript.sh
Path to your script
>
Writes the output of your script into the file specified on the right-hand side (green part)
/home/pi/superscript-cronlog
Path to your log file
2>&1
Makes sure that error messages (stderr) are also written to the log file. More information.

 

Reboot your computer and it should work!