CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

| Download
Project: automation.sh
Views: 28
Image: ubuntu2204
1
#!/bin/bash
2
3
# Log file
4
log_file="Automation.log"
5
6
# Function to log messages with timestamp
7
log_message() {
8
local message="$1"
9
local timestamp=$(date "+%Y-%m-%d %H:%M:%S")
10
echo "[$timestamp] $message" >> "$log_file"
11
}
12
13
# Log currently logged in users
14
log_message "Currently logged in users:"
15
who >> "$log_file"
16
echo -e "\n" >> "$log_file"
17
18
# Log current processes
19
log_message "Current processes with details:"
20
ps aux >> "$log_file"
21
echo -e "\n" >> "$log_file"
22
23
# Log top 4 CPU utilizing processes
24
log_message "Top 4 CPU utilizing processes:"
25
ps aux --sort=-%cpu | head -n 5 >> "$log_file"
26
echo -e "\n" >> "$log_file"
27
28
# Log devices plugged in (e.g., USB)
29
log_message "Devices plugged in (USB):"
30
lsusb >> "$log_file"
31
echo -e "\n" >> "$log_file"
32
33
# Log disk usage
34
log_message "Disk usage:"
35
df -h >> "$log_file"
36
echo -e "\n" >> "$log_file"
37
38
# Log network interfaces and their states
39
log_message "Network interfaces and their states:"
40
ifconfig >> "$log_file"
41
echo -e "\n" >> "$log_file"
42
43
# End of the script
44