###### tags: `Sys.management` # Résumer cours ## cours du 11.11.2021 ### connection raspi au wifi mettre la carde sd dans boot créer un fichier en fichier txt sans le ".txt" avec le nom **ssh** sur le boot créer un fichier **wpa_supplicant.conf** ouvrir le fichier dans visual code et insérer ``` network={ ssid="solidus" // nom du wifi _2.4G si le raspberry n'as pas la technologie 5G psk="soliduscup15" //Mp du wifi } ``` ou bien mettre le code directement dans le fichier wpa_supplicant.conf --- ```` ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev update_config=1 country=CH network={ scan_ssid=1 ssid="<Name of your wireless LAN>" psk="<Password for your wireless LAN>" proto=RSN key_mgmt=WPA-PSK pairwise=CCMP auth_alg=OPEN } ```` raspi-config sudo raspi-config changer le nom de l'hote avec **grjpi** reboot --- ![](https://i.imgur.com/BvrDBTQ.jpg) htop ls ping google.ch hostname --- **---** --- ## cours 15.11.2021 raspberry sur la machine virtuelle ### dans la machine virtuelle **sudo apt install mosquitto-pub** **sudo apt install mosquitto-sub** **mosquitto** **man mosquittopub** **mosquittopub -h tcp://mqtt.eclipseprojects.io -t hftm -m test** **mqtt.nomdumqtt.io** **hostname -i : donne l'adresse IP** mosquitto_pub -h mqtt.nom.io -t hftm/roapo/ip -m message mosquitto_sub -h mqtt.nom.io -t hftm/roapi/ip souscription à la "chaine" mqtt --- ### quelques commandes ls -h ls -lisah ls -lisah .bashrc nano .bashrc hostname -i | mosquitto_pub -h mqtt.nom.io -t hftm/roapi/ip -s reboot boot/auto login console fichier bashrc qui se fait tout seul quand on ouvre la console.. --- --- --- --- --- -- -- - -- - -- --- ---- ----- ----- ------ --- ### crontab -e --- @reboot hostname -i | mosquitto_pub -h mqtt.nom.io -t hftm/roapi/ip -s - ------------------------------------------------- - - ---- ## use mosquitto / Cours du 24.11.2021 startfile bash.rc (console) /etc/rc.local sudo nano rc.local deuxième ligne avant exit: hostname -i | mosquitto_pub -h mqtt.eclipseprojects.io -t hftm/roa/pi -s sync sudo reboot sudo nano /etc/rc.local sudo apt install mosquitto-clients sudo apt install mc sudo reboot hostname hostname -i hostname -h ifconfig dans wlan0 : inet ...(chiffre) ifconfig | grep inet hostname -I ( pour fenêtre d'aide man hostname) sudo raspi-config --- ### Quelques commande à faire **mkdir** :création de dossier **touch** création de fichier **nano** nom de fichier: écrire dans le fichier **cat** ou **less** nom de fichier : lire/ ouvrir et voir le contenu du fichier **tree** : regarder la structure **mc** : ouvre jsp quoi mais apparement c'est utile sudo find -name "nom dossier/ fichier" grep: chercher par mot/ partie de mot dans les fichiers (pour trouver un fichier) sudo grep "mot à chercher" * -r --- ouvrir mqtt explorer: pour voir l'addresse IP --- windows links harddiskShell ![](https://i.imgur.com/nBRigS7.png) ## Sy.Man 08.12.2021 ### connecter au rapsi: ping + "nom du raspi" exemple: ping germpi ### Recherche/mot clés List your processes on the system ps ou top htop --- Pour créer des nouveaux mots pour travailler on peut utiliser alias --- Trouver la différence entre deux fichier diff exemple: diff train train2 --- ls -l -R | grep java ### look at all ls -all ### Redirecting Output exemple: ls -l date > train (remplace tout) somthing >>file.txt (ajoute something) la date sera inscrite dans le fichier train --- ### The output of one command can become the input of another faire plusieurs instructions avec | (pipe) ps -aux |grep apache2 |wc ps -aux |grep apache2 |wc -l ### install node-red sudo apt install node-red ### créer un nouvel utilisateur adduser sudo adduser hftuser ls -l ( pour voir les dossiers) pour se connecter à un utilisateur su visitor exit ### file types / location file: file timezone file get-pip.py file start.txt file mosquitto-pub type: pour trouver ou sont les fichier type mosquitto type ls --- commande apperçu détail fichier (owner,...) ls -l /etc chmod 755 file (changer les droit du fichier) ### mettre a jour sudo apt update sudo apt upgrade ### chmod chmod +x fileName chmod 744 filname ### modifier qqch dans mosquitto sudo nano /etc/mosquitto/mosquitto.conf ### regarder les application en cours htop ### chercher qqch example mosquitto: ps -aux | grep mosquitto ### lien ln ln -s (pour symbolic) ln testprog newlink ### regarder dans les fichiers ls ls -l ls -lisah ### pour ne pas bloquer la console avec une longue action tree / >> directory pour arreter = ctrl + c sshd d = demon web server ### créer un fichier exe nano scipte #!/bin/bash ... chmod 744 scripte (donné les droit pour executé) 7 = tous les droits +4= read +2= write +1=execute premier chiffre pour owner permission deuxième chiffre pour group permission troisième chiffre pour others permission ./scripte (il execute le fichier) ### comment #simple line comment : ' long comment long comment long comment long comment long comment ' ## créer un serveur mqtt perso #### install mosquitto sudo apt install mosquitto ps -aux | grep mosquitto ![](https://i.imgur.com/XwDTDKW.png) mettre le nom du raspi dans broker Adress - sudo systemctl start - sudo systemctl restart (après avoir modifier qqch) - sudo systemctl stop - sudo systemctl status - systemctl status mosquitto.service systemctl start mosquitto.service systemctl stop mosquitto.service sudo systemctl restart mosquitto.service #### example mqtt ![](https://i.imgur.com/7eo3r7H.png) ### démarrer une application tjrs au démmarage sudo systemctl enable name sudo systemctl disable name example: sudo systemctl enable mosquitto.service ## exercice: ### exercice 1 cd /home tree cd /home/pi mkdir sport cd sport mkdir volley ski athletics tennis volley cd volley touch volleyplan skiplan nano volleyplan nano skiplan mv ./skiplan ../ski/skiplan cp ./volley/volleyplan ./athletics/athleticsplan cp ./volley/volleyplan ./tennis/tennisplan tree df ps kill 941 ps sudo adduser visitor su visitor chmod 777 /home/pi ln -s /home/pi/sport/tennis/tennisplan linktennis rm tennisplan ### exercice 2 shell linux / fichier script ls /usr/bin | file *.ziprm sudo dnf install vlc cvlc v4l2:///dev/video0 nano hello #!/bin/bash read user if [ "$user" = "pi" ]; then echo "hi Mr. Gerber your last login was:" last pi | head -n2 | tail -n1 else echo "hello $USER" fi read a read b read sign if [ "$sign" = "+" ]; then echo $[$a+$b] fi if [ "$sign" = "-" ]; then echo $[$a-$b] fi if [ "$sign" = "*" ]; then echo $[$a*$b] fi if [ "$sign" = "/" ]; then echo $[$a/$b] fi #!/bin/bash for ((i=10; i>0;i--)) do echo "$i" done #!/bin/bash echo "nbr ?" read nbrStudent echo "Number of Student: $nbrStudent">>file.txt for ((i=1; i<nbrStudent+1;i++)) do echo "Name student $i:" read name echo "Student $i: $name">>file.txt done ### exécuter un fichier ./hello (il execute le fichier)[] ## Crone 14.12.2021 Si vous voulez éditer un fichier crontab de l’utilisateur actuel, tapez la commande suivante dans le terminal : crone -e Si vous souhaitez modifier le crontab d’un autre utilisateur, vous pouvez taper : (sudo) crontab -u [utilisateur] -e Si vous voulez supprimer le fichier crontab actuel de l’utilisateur actuel, tapez la commande suivante : crontab -r L’option suivante est la même que -r, mais elle invite l’utilisateur à choisir une option oui/non avant de supprimer le crontab : crontab -i ### utiliser node-red d'abord sur le raspi : node-red-start ensuite sur le computer: http://germpi.hftm.ch:1880 ## program example ![](https://i.imgur.com/FTGO2ba.png) ![](https://i.imgur.com/edAx80D.png) ### show on the sehll from a script ![](https://i.imgur.com/3TgSQBH.png) ### conditionel way to write <li> three way to do the same AND</li> ![](https://i.imgur.com/xcDM1xs.png) ![](https://i.imgur.com/9paPEve.png) ![](https://i.imgur.com/ouTHyQB.png) <li> three way to do the same OR</li> -o || ### case ![](https://i.imgur.com/dRuicml.png) ### loops ![](https://i.imgur.com/1uHYUWZ.png) ![](https://i.imgur.com/V7xQUB2.png) ![](https://i.imgur.com/y1jJ1wk.png) ![](https://i.imgur.com/8ok3WJi.png) ![](https://i.imgur.com/JsGQc2J.png) ![](https://i.imgur.com/zO1rXvS.png) ![](https://i.imgur.com/vLUEyBS.png) -<li><Strong>break</Strong> will end the loop</li> ![](https://i.imgur.com/R2uo8s3.png) -<li><Strong>continu</Strong> will skip 3 and 7 in this example</li> ### input script <Strong>STIN</Strong> standart input ![](https://i.imgur.com/TjtAIjb.png) #### with arrays ![](https://i.imgur.com/91NgUMB.png) ![](https://i.imgur.com/tHK1hwk.jpg) ![](https://i.imgur.com/w224bu1.png) -<li><Strong>$#</Strong> will give the lenght of the array</li> #### read a file ![](https://i.imgur.com/ndY0y6m.png) -<li><Strong>if we don't select any file</Strong> it will use the terminal</li> ![](https://i.imgur.com/hFwMeUT.png) ![](https://i.imgur.com/hrvBQY5.jpg) -<li>read the file and print it in the terminal</li> ### script output <Strong>STDOUT / STDERR </Strong> standart output and error ![](https://i.imgur.com/19A0bXi.png) -<li>this is the standard output</li> ![](https://i.imgur.com/74mJHg2.png) -<li>this is the standard error</li> ![](https://i.imgur.com/2mcW5d8.png) -<li>1 is the standard output and 2 is the standard error</li> ![](https://i.imgur.com/mfwJruf.png) ![](https://i.imgur.com/SuGOpaW.png) ![](https://i.imgur.com/5ymghpW.png) -<li>it assumes it is a standard output </li> ![](https://i.imgur.com/HvOXI3i.png) ![](https://i.imgur.com/JhSjo3f.png) -<li>same file for the two standard</li> ## résumé commande --- https://www.linux.org/threads/more-useful-commands.4131/ --- ### make a file looks like it was done the 07 mai at 09h15 Code: touch -t 05070915 my_report.txt touch [a file name] ### find Code: find -name *hawaii You may have created some file recently. For example, you may want to find some file that you were working on, let's say from now up to 10 minutes ago, you could type. Code: find -mmin +0 -mmin -10 ### pico Create a file with 'pico' or any Linux text editor, create a file called 'mary1.txt' Code: pico mary1.txt ### grep Let's explain this a little. 'grep' looks for the word "Mary" in any text file that is called "mary(something).txt". You've created three files that start with 'mary', so the asterisk makes sure that 'grep' will look for the word 'Mary' in all three. Code: grep Mary mary*.txt ### who 'who' is a command to find out who's working on your system. As you now know, Linux is a multi-user system. Even if you're using one computer at your home, you may be working as more than one person. For example, if you logged in as 'root' but are working as 'bob'. who ### tee tee' is used to write out what appears on your screen into a file. You will be using this with the after a pipe '|' . You might do this: Code: ls -l | tee directory_listing to get a file with the listing of a directory. If you've placed files in a directory to be backed up, you could use this command to create a listing of that directory. You could print out the file on a label and stick it to the disk, tape, zip cartridge or whatever you used to make the backups. If you're using the 'tee' command for the backups I described before, you may want to put a date on the file. You can use this command: #### date Code: date | tee -a directory_listing The command 'date' will enter the date and time in the file at the end. Remember to use the -a option if you're going to write to that file a second time. If you don't you will erase everything on the file in favor of whatever the second command was. ### The '>' command The "greater than" symbol '>' will do the same as 'tee'. You don't need the pipe command (|) with this one. Code: ls -l > directory_listing will give you the same result. If you want to add the date at the end, use the command: #### >> Code: date >> directory_listing with two "greater than" symbols (>>) The two symbols will add to the file without erasing its contents (appending). ### whatis To show you how to use the 'whatis' command 'whatis' is a command so you can find out what a program does. If you explore your Linux system, you will find a lot of programs and you may not know what they do. You would simply type: Code: whatis grep ### whereis whereis is a nice command for finding other commands or programs. If you decide to download any program from the internet, that program may need other programs in order to work. If you want to know whether or not you have it, you can type: whereis [program name] and find out. If you wanted to find out if you have the 'pico' editor and where it is, you would type: Code: whereis pico which To show you another tool for locating programs 'which' is similar to 'whereis'. It will give you the location of a program. At times, a program may not find another program it needs to make it run. It will need to know its location or "path". For example, a program may need Java to run it but thinks its in another place. You would simply type: Code: which java ### echo To show you some uses of the 'echo' command 'echo' is a little command that repeats anything you type. For example if you type Code: echo hello Linux will display the word 'hello' . There is a practical use for 'echo' in everyday life. I sometimes use it to write short notes. If we use 'echo' along with 'pipe' (|) and 'tee', you've got a poor-man's post-it-note. For example: Code: echo remember to tell Bill Gates he owes me 5 bucks | tee -a bill_gates.note Will make you a nice reminder note about dear 'ole Bill. Just remember to read your note. You could type: Code: echo remember to open Gates note | tee -a remember_gates.note to make yourself a reminder for the other reminder note. Use less bill_gates.note or less remember_gates.note to read your notes ### wc Actually, this command will give you the number of lines, words and letters (characters) in a file and in that order. Let's go back to the file about the people I owe money. If I type: Code: wc people_I_owe_money.note I will get this output: 439 6510 197120 wc people_I_owe.note As you can see, there are 439 lines, so that means if each line represents one person, then I owe 439 people money. There are 6510 words and a total of 197120 characters.