Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hello, this is for my INTRO to Linux class. We are using BASH and Vi editor. Tha

ID: 3604189 • Letter: H

Question

Hello, this is for my INTRO to Linux class. We are using BASH and Vi editor. Thanks for the help in advance.

STAGE 3 | Log Rotate More Info: man logrotate

To prevent logs from getting too big and eventually taking up the entire disk space of a server we need to rotate the logs. Rotating will take old logs that meet set rules and compress them. It will then start a new fresh log. The old compressed logs will continue to be saved until another threshold is met where the oldest compressed log will be deleted. Usually a log is rotated daily and compressed logs are kept for 7 days.

Create a configuration file to handle log rotation. The configuration file should be named ‘logrotate.conf’ and should be located within your home directory. Use the following rules for your logrotate configuration:

• Up to a maximum of 6 log files should be rotated
• Logs are to be rotated daily
• The log files older than one complete cycle are compressed
• Empty files are subject to log rotation
• The postrotate command is used to recreate the original log file • You must rotate both Server_Info.log and Server_Hourly.log

You can test your configuration file via the following steps: 1. Create a state file called /tmp/$USER.$$ (i.e, touch it)

2. Run the command (3-4 times)

% logrotate --state /tmp/$USER.$$ -f logrotate.conf

3. By using the ls command, you should have output similar to:

$ ls -l *.log* # should get your filenames instead of test

-rw-r--r-- 1 steve users 0 Mar 17 14:49 test.log.1.gz -rw-r--r-- 1 steve users 37 Mar 17 14:48 test.log.2.gz -rw-r--r-- 1 steve users 30 Mar 17 14:40 test.log.3.gz

Explanation / Answer

Well, it seems few information is missing but lemme paste the scripts:

log_copy.bash

#!/bin/bash

LAST_HOUR=$(( $(date +%l) - 1 ))

SEARCH_STRING=$(date +"%b-%d-%Y-${LAST_HOUR}:")

grep "${SEARCH_STRING}" > "/home/users/vijay/log/Server_Hourly.log"

------------------------------------------------------------------------------------------

Now, create one file named scheduler with below mentioned content:

scheduler

#!/bin/bash
PATH=/bin;/usr/local/bin;/usr/bin;/usr/sbin;/sbin;
*/10 * * * * bash /home/users/vijay/your_username/script/IsTheServerUp.bash
0 * * * * bash /home/users/vijay/your_username/script/log_copy.bash

---------------------------------------------------------------------------------------------------------

Now, execute below menioned command to schedule the jobs. It will directly schedule the job without any need for an editor:

sudo crontab /path-to-scheduler/scheduler