File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- new = ('new' )kB ]
2- Get :30 http :// in .archive .ubuntu .com / ubuntu noble - updates / multiverse amd64 Components [940 B ]
3- Get :31 http :// in .archive .ubuntu .com / ubuntu noble - backports / main amd64 Components [7 ,300 B ]
4- Get :32 http :// in .archive .ubuntu .com / ubuntu noble - backports / restricted amd64 Components [216 B ]
5- Get :33 http :// in .archive .ubuntu .com / ubuntu noble - backports / universe amd64 Components [10.5 kB ]
6- Get :34 http :// in .archive .ubuntu .com / ubuntu noble - backports / multiverse amd64 Components [212 B ]
7- Fetched 5 ,731 kB in 7 s (863 kB / s )
8- Reading package lists ... Done
9- Building dependency tree ... Done
10- Reading state information ... Done
11- 31 packages can be upgraded . Run 'apt list --upgradable' to see them .
12- # rajeev@rajeevmachphy:~$
1+ import os
2+ from datetime import datetime
3+
4+ LOG_FILE = "system_logs.txt"
5+ OUTPUT_FILE = "collected_logs.txt"
6+
7+ def collect_logs ():
8+ if not os .path .exists (LOG_FILE ):
9+ print ("Log file not found!" )
10+ return
11+
12+ with open (LOG_FILE , "r" ) as src , open (OUTPUT_FILE , "a" ) as dst :
13+ timestamp = datetime .now ().strftime ("%Y-%m-%d %H:%M:%S" )
14+ dst .write (f"\n --- Logs collected at { timestamp } ---\n " )
15+ for line in src :
16+ dst .write (line )
17+
18+ print ("Logs collected successfully!" )
19+
20+ if __name__ == "__main__" :
21+ collect_logs ()
You can’t perform that action at this time.
0 commit comments