-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrecorder.bash
More file actions
executable file
·41 lines (29 loc) · 1.21 KB
/
recorder.bash
File metadata and controls
executable file
·41 lines (29 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#! /bin/bash
SLEEPTIME=60s
#tutti i report creati vengono inseriti in una cartella apposita che viene creata se non esistente
mkdir -p reports
#il processo "entra" nella cartella reports in modo tale che non sia necessario spostare il file alla fine della creazione
cd reports
while true;
do
#creazione del nome del file, il quale deve contenere report_annomesegiorno_oraminutisecondi.csv
filename=report\_$(date +%Y%m%d_%H%M%S).csv
documento=""
#ciclo while per la sistemazione dello start > 24h e del command
while read line;
do
if [ $(echo $line | cut -d ';' -f3 | wc -c) != "4" ];
then
userPidCommand="$(echo $line | cut -d ';' -f1,2,5);"
startTime="$(echo $line | cut -d ';' -f3,4)"
documento="$documento$(echo "$userPidCommand$startTime\n")"
else
userPidCommand="$(echo $line | cut -d ';' -f1,2,6);"
start="$(echo $line | cut -d ';' -f3,4 | tr -s ';' ' ');"
ptime="$(echo $line | cut -d ';' -f5)"
documento="$documento$(echo "$userPidCommand$start$ptime\n")"
fi
done <<< "$(ps --no-headers -eo "user:32,pid,start,time,command" | tr -s ' ' ';' | cut -d ';' -f1-6)"
echo "$(echo -e "$documento" | tr -s '\n')" > "$filename"
sleep $SLEEPTIME
done