###### 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

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

### 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


### comment
#simple line comment
: '
long comment
long comment
long comment
long comment
long comment
'
### show on the sehll from a script

### conditionel way to write
<li> three way to do the same AND</li>



<li> three way to do the same OR</li>
-o
||
### case

### loops







-<li><Strong>break</Strong> will end the loop</li>

-<li><Strong>continu</Strong> will skip 3 and 7 in this example</li>
### input script
<Strong>STIN</Strong> standart input

#### with arrays



-<li><Strong>$#</Strong> will give the lenght of the array</li>
#### read a file

-<li><Strong>if we don't select any file</Strong> it will use the terminal</li>


-<li>read the file and print it in the terminal</li>
### script output
<Strong>STDOUT / STDERR </Strong> standart output and error

-<li>this is the standard output</li>

-<li>this is the standard error</li>

-<li>1 is the standard output and 2 is the standard error</li>



-<li>it assumes it is a standard output </li>


-<li>same file for the two standard</li>