###### tags: `Sys.management` # cours NOTE Manu # Sy.Man 08.12.2021 ### connecter au rapsi: ping + "nom du raspi" exemple: ping grpipi ### 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 ### 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) ### 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: 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 ### 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 ./scripte (il execute le fichier) ### exercice 2 shell linux 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 ./hello (il execute le fichier)[] ### program example ![](https://i.imgur.com/FTGO2ba.png) ![](https://i.imgur.com/edAx80D.png) ### comment #simple line comment : ' long comment long comment long comment long comment long comment ' ### 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>