2

I am trying to read some information from Raspberry. This script can be read for all types of Raspberry. I will define them via Raspberry Profile.
A Raspberry Profile can be thought of as a template or as a type or classification of Raspberry. General characteristics of the type of Raspberry such as:
1 - name
2 - description
3 - IP address
4 - Location
5 - Type of data (some parameters that Raspberry has like supporting BLE, Wifi, several sensors, protocol...)

Are there any ways to read the profile of Raspberry or how could I do that?

Thank you


UPDATE:
The profile information of Raspberry will send to a server to manage. The server will then read these profiles and accept them into the server's network.

Mohi Rostami
  • 4,434
  • 1
  • 20
  • 39
JERLee
  • 21
  • 2

2 Answers2

2

There is no way to get a "profile" with exactly the information you want. But you can use different available commands to gather the information into a file. There are many commands and possibilities. Here are only some examples:

rpi ~$ cat /etc/os-release > profile
rpi ~$ ip address >> profile
rpi ~$ iw dev wlan0 info >> profile
rpi ~$ uname --all >> profile
rpi ~$ lsblk >> profile
rpi ~$ df -h >> profile
rpi ~$ sudo parted /dev/mmcblk0 print free >> profile
rpi ~$ cat /proc/cpuinfo >> profile
rpi ~$ cat /proc/meminfo >> profile

... and much much more. It depends what you want to know. This is a very simple and raw example. You will find the information from the commands in the file profile. You can modify the output of the commands with its options or with the filter grep.

Here is a short bash example script how you can make your profile. Create a file profile.sh with this contents:

#!/bin/bash

echo profile of $(tr -d "\0" < /sys/firmware/devicetree/base/model)
echo -----------------------------------------------------------
echo Serial number: $(tr -d "\0" < /sys/firmware/devicetree/base/serial-number)
echo Name: $(hostname)
echo Full name: $(hostname --all-fqdns)
echo Interfaces:; ip -br addr

Make it executable with chmod +x profile.sh and execute it:

rpi ~$ ./profile.sh
profile of Raspberry Pi 4 Model B Rev 1.1
-----------------------------------------------------------
Serial number: 10000000cd0297b1
Name: raspberrypi
Full name:
Interfaces:
lo               UNKNOWN        127.0.0.1/8 ::1/128
eth0             UP             192.168.50.137/24 fe80::77c0:a4bd:e655:5427/64
wlan0            DOWN

If you need other information just ask for it. I'm sure you will get immediately an answer.

Ingo
  • 42,961
  • 20
  • 87
  • 207
1

You can save all the information about Raspberry Pis on a server with SNMP. At first, let take a look and this network protocol.

What is SNMP?

Simple Network Management Protocol (SNMP) is an Internet Standard protocol for collecting and organizing information about managed devices on IP networks and for modifying that information to change device behavior. Devices that typically support SNMP include cable modems, routers, switches, servers, workstations, printers, and more.

So, now you know that you should install some packages to make your Raspberry Pis as an SNMP agent. After that, they can answer SNMP requests of the SNMP server which is another host (a Windows or a Linux box). On the other words, the host can get the status of all your raspberry pis.


Install packages:

sudo apt-get update
sudo apt-get install snmp snmp-mibs-downloader  
sudo apt-get install snmpd

SNMPd Configuration, The configuration file is located at /etc/snmp/snmpd.conf. Make sure you are editing the snmpd.conf file and not the snmp.conf file:

sudo nano /etc/snmp/snmp.conf

Change lines like it:

view   systemonly  included   .1.3.6.1.2.1.1
view   systemonly  included   .1.3.6.1.2.1.25.1

 rocommunity public  default    -V all

 rocommunity6 public  default   -V all

Open the daemon’s configuration file with sudo privileges:

sudo nano /etc/snmp/snmpd.conf

Change lines like it:

# Listen for connections from the local system only
# agentAddress udp:127.0.0.1:161
# Listen for connections on all interfaces (both IPv4 *and* IPv6)
agentAddress udp:161,udp6:[::1]:161  

Start the services:

sudo service snmpd start

Test the SNMP on the local raspberry pi as a test:

snmpwalk –v2c –c public 127.0.0.1 .1.3.6.1.2.1.25.1.1  

You would see the result like it:

SNMPv2-MIB::sysORUpTime.1 = Timeticks: (3) 0:00:00.03  

Which tells you the uptime of the device. Now you can install snmpd packages and run snmpwalk command to gather this configured raspberry pi uptime status from the host. Also you need to change 127.0.0.1 to that raspberry pi IP address or Domain name.

There is a lot of information that you can get from the SNMP server to SNMP agent like, System hostname, IP address, number of packets, storage capacity, UUID, serial number, mac address, etc. Just search about that and add the OID root to the snmp.conf then request that OID value.

In addition, you can install a featured SNMP server on your host to monitor your raspberry pis. OpenNMS is one of them but I suggest PRTG. You can even create your own snmp OIDs (can be the output of a command) to send for the SNMP server as you said (5 - Type of data ).

In conclusion, you can send raspberry pi pre-arranged information or self-arranged (ANY information you want) to a host which can be a Linux or Windows PC.

Mohi Rostami
  • 4,434
  • 1
  • 20
  • 39