Linux Bash Create a logfile bash file that has the following data on each line o
ID: 3834095 • Letter: L
Question
Linux Bash
Create a logfile bash file that has the following data on each line of the file (fields separated by |):
user name | process name | process time (in minutes)
eg:
smiths|Login|2
olivert|Login|2
northj|Login|2
denniss|Login|2
smithd|Login|2
smiths|Time Reporting|210
olivert|Payroll|155
northj|Server Maintenance|70
northj|Logfile Reporting|45
denniss|Report Printing|80
smithd|Payroll Program Updates|150
smithd|Benefit Program Updates|180
smiths|Logout|2
olivert|Logout|2
northj|Logout|2
denniss|Logout|2
smithd|Logout|2
Explanation / Answer
The below command prints the output in required format:
ps --no-heading -e -o uname,comm,etime | tr -s ' ' | tr '-' ' ' | tr ':' ' ' | awk '{ total=0; m=1; } { for (i=0; i < NF-2; i++) {total += $(NF-i)*m; m *= i >= 2 ? 24 : 60 }} {print $1,$2,total/60}' | tr ' ' '|'
**NOTE: The whole command is a single line.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.