Hi,help me to solve this quesation in centos 7 write or use needed commands to…
- User
Hi,help me to solve this quesation in centos 7 write or use needed commands to accomplish the following: Each time the user logs in, a detailed list of all files – in the /var global directory and its subs - that is being modified for the past 5 days should be produced and saved in a log file in the backups/November directory. The file name should reflect the date and time it’s created at, for example: if it’s been created at: November 15th 2023 3:34 P.M. the file should be named: 20231115-1534.log. Be aware that:
- the phrase: detailed list of files means it should contain information like files sizes, modification dates, ownership, permissions, inodes numbers and links.
- The files list shouldn’t contain any error messages resulted by executing the search command. Notes:
- In the questions the used times are just for demonstration purposes, your commands should produce correct values related to the execution time.
- You should respect the time and text formats (spaces and letters cases) or it may cost you marks.
- Be aware that you should prove your work each step by using suitable commands, resulted files and locations. And remember to always take suitable snapshots of those actions and put them as part of your answers.
- Assistant
To accomplish the given task, you can follow these steps:
-
Create the backups/November directory if it doesn't exist:
mkdir -p backups/November -
Create a shell script to perform the required actions. Let's name it
log_files.sh:nano log_files.sh -
Now, write the following script in the
log_files.shfile:#!/bin/bash # Get the current date and time datetime=$(date +%Y%m%d-%H%M) # Get the modified files list in /var and its subdirectories find /var -type f -mtime -5 -exec ls -lhi {} \; 2>/dev/null > backups/November/${datetime}.log -
Save the script file (
log_files.sh) and exit the text editor.
-