Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision

Target

Select target project
  • flg_courses/systems_programming/sysprog_spring25
  • benjamin.marchesi/sysprog_spring25
  • louis.saulnier/sysprog_spring25
3 results
Select Git revision
Show changes
Commits on Source (18)
Showing
with 361 additions and 0 deletions
No preview for this file type
#!/bin/bash
function copy {
echo "Copie de $1"
cp $1 $2
if [ $? -ne 0 ]; then
echo "Failed copying $1 to $2" >&2
exit 5
fi
name=$(basename $1)
f=$2/$name
chmod 440 $f
if [ $? -ne 0 ]; then
echo "Failed chaning $f permissions" >&2
exit 6
fi
}
if [ $# -ne 2 ]; then
name=$(basename $0)
echo "Usage: $name src dest" >&2
echo "src source directory containing txt and dat files" >&2
echo "dst destination directory" >&2
exit 1
fi
if [ ! -d $1 ]; then
echo "source directory not found or not a directory!" >&2
exit 2
fi
DATA=$1
BACKUP=$2
# Si repertoire existe
if [ -d $BACKUP ]; then
# Efface les anciens backups
rm -f $BACKUP/*
if [ $? -ne 0 ]; then
echo "Failed removing files" >&2
exit 3
fi
else
# Cree repertoire
mkdir -p $BACKUP
if [ $? -ne 0 ]; then
echo "Failed creating $BACKUP directory" >&2
exit 4
fi
fi
# Backup les fichiers .txt et .dat
for f in $DATA/*.txt $DATA/*.dat; do
copy $f $BACKUP # appel à la fonction
done
exit 0
#/bin/bash
THUMB_SIZE=64x64
THUMB_EXT=png
if [ $# -ne 2 ]; then
name=$(basename $0)
echo "Usage: $name <input dir> <output dir>" >&2
exit 1
fi
function filetype {
file --mime-type "$1" | cut -d':' -f2 | cut -d'/' -f1 | tr -d ' '
# alternative plus simple:
#file --mime-type "$1" | cut -d' ' -f2 | cut -d'/' -f1
}
for f in "$1"/*; do
if [ $(filetype "$f") == "image" ]; then
basefile=$(basename "$f")
convert -thumbnail $THUMB_SIZE "$f" "$2/$basefile.$THUMB_EXT"
fi
done
#!/bin/bash
if [ "$#" -ne 2 ]; then
name=$(basename $0)
echo "Usage: $name <utilisateur> <signal>" >&2
else
# tail +2 = affiche à partir de la 2ème ligne de l'entrée
kill -$2 $(ps -o pid -u "$1" | tail -n +2)
# Alternative:
#kill -$2 $(ps -o pid= -u "$1")
fi
#!/usr/bin/env bash
# Notes:
# - en utilisant la récursivité
# - introduce stat command
# - do not compute size of folders
# - maange empty directories
# - hidden files should be ignored
# Get the size of a link given as parameter
function getsize {
stat "$1" | grep Size | cut -c9- | cut -d' ' -f1
}
# a folder is given as the unique parameter
# finds the biggest file in this folder
function findbig {
BIGSIZE=0
# If folder is empty skip it
CONTENT=$(ls "$1")
if [ -d "$1" -a -n "$CONTENT" ]; then
# For each file in the folder
for f in "$1"/*; do
# If directory find the biggest file of this directory
if [ -d "$f" ]; then
NEWSIZE=0
NEWFILE=$(findbig "$f")
if [ -n "$NEWFILE" ]; then
NEWSIZE=$(getsize "$NEWFILE")
fi
# If file find the size of this file
else
NEWSIZE=$(getsize "$f")
NEWFILE="$f"
fi
# Update biggest size and file
if [ $NEWSIZE -gt $BIGSIZE ]; then
BIGFILE="$NEWFILE"
BIGSIZE=$NEWSIZE
fi
done
echo "$BIGFILE" # return the name of the biggest file
fi
}
# Print usage if number / type of argument is incorrect
if [ $# -ne 1 -o ! -d $1 ];then
echo "Number of argument is incorrect or parameter is not a folder" >&2
echo "Usage:" >&2
echo -e "\t$(basename $0) folder" >&2
exit 1
fi
# Find the biggest file and recomptue its size for display
BIGFILE=$(findbig "$1")
if [ -n "$BIGFILE" ]; then
BIGSIZE=$(getsize $BIGFILE)
echo -e "$BIGFILE: $BIGSIZE"
fi
\ No newline at end of file
#!/usr/bin/env bash
# A few comments:
# - carefull that users can have the same group name than user name
# - what happens if program is used without an argument
# - what happens if program is used with a non existing username
# Returns the GID of the username given in the first parameter
function getusergid {
grep "^$1:" /etc/passwd | cut -d':' -f4
}
# Returns the groupname of the corresponding GID given in first parameter
function getgroupbygid {
grep "^.*:x:$1" /etc/group | cut -d':' -f1
}
# Retuns the main group of a username given in parameter
function getusergroup {
GID=$(getusergid $1)
if [ -n "$GID" ]; then
getgroupbygid $GID
fi
}
# Return all additional group names for the username given in the first parameter
function getusergroups {
grep -E "(:|,)$1(,|\$|\s)" /etc/group | cut -d':' -f1
}
USER=$1
if [ -z "$USER" ]; then
echo "Usage:" >&2
echo -e "\t$(basename $0) username" >&2
exit 1
fi
MGROUP=$(getusergroup $USER)
AGROUP=$(getusergroups $USER)
if [ -n "$MGROUP" -o -n "$AGROUP" ]; then
for G in $MGROUP $AGROUP; do
echo -n "$G "
done
echo ""
fi
\ No newline at end of file
File added
root:x:0:brltty,root
bin:x:1:root,bin,daemon
daemon:x:2:root,bin,daemon
sys:x:3:root,bin
adm:x:4:root,daemon
tty:x:5:brltty
disk:x:6:root
lp:x:7:cups,daemon,chanel
mem:x:8:
kmem:x:9:
wheel:x:10:root,chanel
ftp:x:11:
mail:x:12:
uucp:x:14:brltty,chanel
log:x:19:root
utmp:x:20:
locate:x:21:
rfkill:x:24:
smmsp:x:25:
proc:x:26:polkitd
http:x:33:
games:x:50:
lock:x:54:
uuidd:x:68:
dbus:x:81:
network:x:90:
video:x:91:
audio:x:92:brltty
optical:x:93:
floppy:x:94:
storage:x:95:
scanner:x:96:
input:x:97:brltty
power:x:98:
nobody:x:99:
users:x:100:
systemd-journal:x:190:
systemd-journal-gateway:x:191:
systemd-timesync:x:192:
systemd-network:x:193:
systemd-bus-proxy:x:194:
systemd-resolve:x:195:
systemd-journal-upload:x:999:
systemd-coredump:x:997:
systemd-journal-remote:x:998:
polkitd:x:102:
chanel:x:1000:
git:x:996:
avahi:x:84:
rtkit:x:133:
colord:x:124:
gdm:x:120:
usbmux:x:140:
brlapi:x:995:brltty
vboxusers:x:108:chanel,root
rpc:x:32:
mysql:x:89:
kvm:x:994:
mmi:x:1010:chanel,chanel-unige
render:x:993:
cups:x:209:
chanel-unige:x:1154:
docker:x:992:chanel
geoclue:x:991:
flatpak:x:990:
adbusers:x:989:
lxdm:x:988:
exim:x:79:
postdrop:x:75:
nvidia-persistenced:x:143:
dhcpcd:x:987:
named:x:40:
tor:x:43:
mailpile:x:986:mailpile
rainloop:x:985:
gitlab-runner:x:107:
tox-bootstrapd:x:199:
brltty:x:984:
x2gouser:x:111:
x2goprint:x:112:
sgx:x:983:
systemd-oom:x:982:chanel
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/usr/bin/nologin
daemon:x:2:2:daemon:/:/usr/bin/nologin
mail:x:8:12:mail:/var/spool/mail:/usr/bin/nologin
ftp:x:14:11:ftp:/srv/ftp:/usr/bin/nologin
http:x:33:33:http:/srv/http:/usr/bin/nologin
uuidd:x:68:68:uuidd:/:/usr/bin/nologin
dbus:x:81:81:dbus:/:/usr/bin/nologin
nobody:x:99:99:nobody:/:/usr/bin/nologin
systemd-journal-gateway:x:191:191:systemd-journal-gateway:/:/usr/bin/nologin
systemd-timesync:x:192:192:systemd-timesync:/:/usr/bin/nologin
systemd-network:x:193:193:systemd-network:/:/usr/bin/nologin
systemd-bus-proxy:x:194:194:systemd-bus-proxy:/:/usr/bin/nologin
systemd-resolve:x:195:195:systemd-resolve:/:/usr/bin/nologin
systemd-journal-upload:x:999:999:systemd Journal Upload:/:/sbin/nologin
systemd-coredump:x:997:997:systemd Core Dumper:/:/sbin/nologin
systemd-journal-remote:x:998:998:systemd Journal Remote:/:/sbin/nologin
polkitd:x:102:102:Policy Kit Daemon:/:/usr/bin/nologin
chanel:x:1000:1000::/home/chanel:/usr/bin/fish
git:x:996:996:git daemon user:/:/bin/bash
avahi:x:84:84:avahi:/:/bin/nologin
rtkit:x:133:133:RealtimeKit:/proc:/bin/false
colord:x:124:124::/var/lib/colord:/bin/false
gdm:x:120:120:Gnome Display Manager:/var/lib/gdm:/sbin/nologin
usbmux:x:140:140:usbmux user:/:/sbin/nologin
rpc:x:32:32:Rpcbind Daemon:/dev/null:/bin/false
mysql:x:89:89:MariaDB:/var/lib/mysql:/sbin/nologin
cups:x:209:209:cups helper user:/:/sbin/nologin
chanel-unige:x:1154:1154::/tmp:/usr/bin/fish
geoclue:x:991:991:Geoinformation service:/var/lib/geoclue:/sbin/nologin
flatpak:x:990:990:Flatpak system helper:/:/sbin/nologin
lxdm:x:988:988:Lightweight X11 Display Manager:/var/lib/lxdm:/usr/bin/nologin
exim:x:79:79:Exim MTA:/var/spool/exim:/usr/bin/nologin
nvidia-persistenced:x:143:143:NVIDIA Persistence Daemon:/:/usr/bin/nologin
dhcpcd:x:987:987:dhcpcd privilege separation:/var/lib/dhcpcd:/usr/bin/nologin
named:x:40:40:BIND DNS Server:/:/usr/bin/nologin
tor:x:43:43::/var/lib/tor:/usr/bin/nologin
mailpile:x:986:986:mailpile daemon user:/var/lib/mailpile:/bin/bash
rainloop:x:985:985:RainLoop User:/var/lib/rainloop:/usr/bin/nologin
gitlab-runner:x:107:107:GitLab Runner:/var/lib/gitlab-runner:/usr/bin/nologin
tox-bootstrapd:x:199:199:Tox bootstrapd:/:/usr/bin/nologin
brltty:x:984:984:Braille Device Daemon:/var/lib/brltty:/usr/bin/nologin
x2gouser:x:111:111:x2gouser:/var/lib/x2go:/usr/bin/nologin
x2goprint:x:112:112:x2goprint:/var/spool/x2go:/usr/bin/nologin
systemd-oom:x:982:982:systemd Userspace OOM Killer:/:/usr/bin/nologin
Woaw this is clearly the biggest file with all its content which is sooooo big. Incredible, how big it is....
Woaw this is clearly the biggest file with all its content which is sooooo big. Incredible, how big it is....
Woaw this is clearly the biggest file with all its content which is sooooo big. Incredible, how big it is....
Woaw this is clearly the biggest file with all its content which is sooooo big. Incredible, how big it is....
Woaw this is clearly the biggest file with all its content which is sooooo big. Incredible, how big it is....
Woaw this is clearly the biggest file with all its content which is sooooo big. Incredible, how big it is....
Woaw this is clearly the biggest file with all its content which is sooooo big. Incredible, how big it is....
Woaw this is clearly the biggest file with all its content which is sooooo big. Incredible, how big it is....
v
v
Woaw this is clearly the biggest file with all its content which is sooooo big. Incredible, how big it is....
v Woaw this is clearly the biggest file with all its content which is sooooo big. Incredible, how big it is....
Woaw this is clearly the biggest file with all its content which is sooooo big. Incredible, how big it is....
v
Woaw this is clearly the biggest file with all its content which is sooooo big. Incredible, how big it is....
Woaw this is clearly the biggest file with all its content which is sooooo big. Incredible, how big it is....
Woaw this is clearly the biggest file with all its content which is sooooo big. Incredible, how big it is....
Woaw this is clearly the biggest file with all its content which is sooooo big. Incredible, how big it is....
Woaw this is clearly the biggest file with all its content which is sooooo big. Incredible, how big it is....
v
Woaw this is clearly the biggest file with all its content which is sooooo big. Incredible, how big it is....
Woaw this is clearly the biggest file with all its content which is sooooo big. Incredible, how big it is....
Woaw this is clearly the biggest file with all its content which is sooooo big. Incredible, how big it is....
Woaw this is clearly the biggest file with all its content which is sooooo big. Incredible, how big it is....
Woaw this is clearly the biggest file with all its content which is sooooo big. Incredible, how big it is....
Woaw this is clearly the biggest file with all its content which is sooooo big. Incredible, how big it is.... Woaw this is clearly the biggest file with all its content which is sooooo big. Incredible, how big it is....
Woaw this is clearly the biggest file with all its content which is sooooo big. Incredible, how big it is....
Woaw this is clearly the biggest file with all its content which is sooooo big. Incredible, how big it is....
hop hophop hophop hophop hophop hophop hophop hophop hophop hophop hophop hophop hophop hophop hophop hophop hophop hophop hophop hophop hophop hophop hophop hophop hophop hophop hophop hophop hophop hophop hophop hophop hophop hophop hophop hophop hophop hophop hophop hophop hophop hophop hophop hophop hophop hophop hophop hophop hophop hophop hophop hophop hophop hophop hophop hophop hophop hophop hophop hophop hophop hophop hophop hophop hophop hophop hophop hophop hophop hophop hophop hophop hophop hophop hophop hophop hophop hophop hophop hophop hophop hophop hophop hophop hophop hophop hophop hophop hophop hophop hophop hophop hophop hophop hophop hophop hophop hophop hophop hophop hophop hophop hophop hophop hophop hophop hophop hophop hophop hop
hphphphphphphphphphphphphphphphphphphphphphphphphphphphphphphphphphphphphphphphphphphphphphphphphphphphphphphphphphphphphphphphphphphphphphphphphphphphphphphphphphphphphphphphphphphphphphphphphphphphphphphphphphphphphphphphphphphphphphphphphphphphphphphphphphphphphphphphphphphphphphphphphphphphphphphphphp
This is a file
This is a fileThis is a fileThis is a fileThis is a fileThis is a fileThis is a fileThis is a fileThis is a fileThis is a fileThis is a fileThis is a fileThis is a file
top top top top top top top top top top top top top top top top top top top top top top top top top top top top top top top top top top top top
File added
No preview for this file type