Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

AWK/BASH call awk script in bash script then run on command line with input file or ls command two files script.awk script.bash Use awk to

AWK/BASH

call awk script in bash script then run on command line with input file or ls command

two files script.awk script.bash

Use awk to create a program for summarizing and printing information based on the directory listing data of files and information.

You are not to use any other programs, utilities, or scripting languages.

Your program should take the output from the modified ls command line seen below, and process the data in order to output the aggregate information: ls -la --time - style = '+%Y -%m -%d %H:%M:%S'

The aggregated information processed from the directory listing data should consist of the following (see example later for proper output formatting):

Per-user grouping of file-related counts found in specified directories

Username of the entity owning these files

Total number of files found owned by this user, printing two values: all files versus hidden files

Total number of directories found that are owned by this user

Total number of other files found that are owned by this user (these items include, but are not limited to, symbolic links, FIFOs, character or block devices, etc. Basically, anything that is not a regular file nor a directory will fall under this category)

Total file storage (in bytes) occupied by the users regular files.

Itemization of the oldest and newest regular files found (if no regular files exist in the listing, simply report "None" for these items. If only one regular file exists, it is reasonable to report this file as both the oldest and newest.)

Also note, if multiple files share the same oldest or newest timestamps, you can break the tie however you wish; there are no guidelines you must adhere to while doing so.

Total file-related counts found in the specified directories

Total users owning files within these paths

Total number of files found, printing two values: all files versus hidden files

Total number of directories found

Total number of other files found (these items include, but are not limited to, symbolic links, FIFOs, character or block devices, etc. Basically, anything that is not a regular file nor a directory will fall under this category)

Total file storage (in bytes) occupied by all regular files listed.

Note 2: ensure to test the processing of ls listings for multiple directories, rather than just one. Such listings can be generated by passing more than one directory to ls and/or by the simple addition of the -r recursive option to the custom ls command shown previously.

Two examples of such command lines can be seen here:

ls -la --time - style = '+%Y -%m -%d %H:%M:%S' dir1 dir2 dir3

ls -lar --time - style = '+%Y -%m -%d %H:%M:%S' dir1

or if you have defined the aforementioned alias, equivalently:

lsa dir1 dir2 dir3 file1 dir4

lsa -r dir1 file1 dir2

Note that these commands can also include filenames alongside the directory names on the command line as well; this is perfectly permissible and should be accounted for, hence why it was shown in the example above.

Example The example below is an excerpt from the following command, executed upon my home directory: ls -la time-style='+%Y-%m-%d %H:%M:%S' ~

Your program should also work with arbitrary input from the ls -la time-style='+%Y-%m-%d %H:%M:%S' command.

This include both reading from one or more input files, as well as accepted piped input directly from standard input, as in these examples:

ls -la --time - style = '+%Y -%m -%d %H:%M:%S' ~ | ./ script .bash

or

./ script.bash listing . txt [ listing2 . txt [...]]

INPUT FILE (ls command ls -la --time - style = '+%Y -%m -%d %H:%M:%S' ~)

total 17160 drwxrwxrwt 98 root root 528384 2020 -04 -07 13:38:14 .

drwxr -xr -x 26 root root 4096 2018 -09 -04 10:50:29 ..

drwx ------ 2 pmp099 students 4096 2020 -03 -03 20:57:31 appInsights - nodeAIF -444 c3af9 -8 e69 -4462 - ab49 -4191 e6ad1916

-rw ------- 1 mce237 students 199 2020 -03 -01 18:41:59 . build1276786824731864129 . log

-rw ------- 1 mce237 students 199 2020 -03 -01 20:18:42 . build291177188595028335 . log

-rw ------- 1 mce237 students 199 2020 -03 -01 20:10:44 . build4195866878600813549 . log

-rw ------- 1 mce237 students 199 2020 -03 -01 20:08:55 . build4503681510908034369 . log

-rw ------- 1 mce237 students 199 2020 -03 -01 18:18:44 . build4964061885086964943 . log

-rw ------- 1 mce237 students 199 2020 -03 -01 20:17:13 . build5474334865226720725 . log

-rw ------- 1 mce237 students 199 2020 -03 -01 19:08:39 . build6322670020019345604 . log

-rw ------- 1 mce237 students 420 2020 -03 -01 20:08:08 . build8057453026527719771 . log

-rw ------- 1 mce237 students 199 2020 -03 -01 20:08:32 . build8316126450060215695 . log

-rw ------- 1 mce237 students 732 2020 -03 -01 20:13:35 . build8317708361921336382 . log

-rw ------- 1 mce237 students 420 2020 -03 -01 20:07:57 . build8983757940366444429 . log

drwxr -xr -x 3 bfn715 students 4096 2020 -03 -03 23:07:12 dlight_bfn715

drwx ------ 3 dad980 students 4096 2020 -03 -05 15:44:15 dlight_dad980

drwx ------ 3 hrb980 students 4096 2020 -04 -06 09:54:44 dlight_hrb980

drwx ------ 3 hrm102 students 4096 2020 -04 -06 18:43:17 dlight_hrm102

drwx ------ 3 kaq447 students 4096 2020 -02 -26 17:58:46 dlight_kaq447

drwx ------ 3 mce237 students 4096 2020 -03 -30 00:04:57 dlight_mce237

drwx ------ 3 mjy610 students 4096 2020 -02 -27 15:33:54 dlight_mjy610

drwx ------ 3 pdq039 students 4096 2020 -04 -06 18:43:48 dlight_pdq039

drwx ------ 3 xie192 students 4096 2020 -03 -23 17:47:37 dlight_xie192

drwx ------ 3 ynb963 students 4096 2020 -04 -07 13:26:46 dlight_ynb963

-rw ------- 1 hrb980 students 95 2020 -03 -09 16:25:53 exec1108000877022604592 . log

-rw ------- 1 hrb980 students 74 2020 -04 -03 13:39:09 exec1218509371493740144 . log

-rw ------- 1 hrb980 students 1470 2020 -03 -09 13:28:36 exec1334040267987479302 . log

-rw ------- 1 hrb980 students 1134 2020 -04 -06 10:16:23 exec1413924165655873346 . log

-rw ------- 1 mce237 students 1538 2020-03-01 18:17:50 exec1520228248140431728.log

...

...

OUTPUT FILE (EXAMPLE OF HOW IT SHOULD LOOK, ls -la --time - style = '+%Y -%m -%d %H:%M:%S' ~ | ./ script .bash)

user : mjy610

dirs : 3

user : hrb980

files :

all / hidden : ( 195 / 2 )

dirs : 3

file storage : 76235 B

user : pdq039

dirs : 3

user : zqu051

files :

all / hidden : ( 452 / 0 )

file storage : 652583 B

user : mce237

files :

all / hidden : ( 52 / 12 )

dirs : 4

file storage : 2729344 B

user : pmp099

dirs : 2

other : 10

user : root

files :

all / hidden : ( 1 / 1 )

dirs : 5

other : 1

file storage : 11 B

user : hrm102

dirs : 3

oldest file : -r--r--r-- 1 root root 11 2020 -02 -25 15:30:11 . X0 - lock

newest file : -rw ------- 1 ynb963 students 1308 2020 -04 -06 19:40:46 output1586220046526

total users : 13

total files

all / hidden : ( 708 / 16 )

total dirs : 38

total other : 11

file storage : 3472081 B

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Accounting questions

Question

8-6 Who poses the biggest security threat: insiders or outsiders?

Answered: 1 week ago