0% found this document useful (0 votes)
10 views15 pages

CSC308 Lab1 VF

The document outlines instructions for a lab assignment in an Operating Systems course, focusing on basic Linux commands and Bash scripting for log collection and email reporting. It includes steps for setting up an email configuration using Gmail's SMTP server, creating a cron job for automated script execution, and managing the cron job. Additionally, it provides references for further reading on Linux commands and email setup.

Uploaded by

s647822
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views15 pages

CSC308 Lab1 VF

The document outlines instructions for a lab assignment in an Operating Systems course, focusing on basic Linux commands and Bash scripting for log collection and email reporting. It includes steps for setting up an email configuration using Gmail's SMTP server, creating a cron job for automated script execution, and managing the cron job. Additionally, it provides references for further reading on Linux commands and email setup.

Uploaded by

s647822
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

CSC308: Operating Systems

Spring 2024-2025
Lab #1
Instructor: Dr. Osama Al Omari

Name StudentID
Saad Own 1085218

Submission date: March 23, 2025


1|Page
Lab Part 1-Copy, Run, and Screenshot

From the terminal and run the following command

>>PS1=”\d \@ [Your_Student-ID]”.
Use your own student ID. The prompt will change, as shown below.

- List files: ls
- use the -a option with the ls command to list all contents of your current working directory,
including hidden files:

Make directory: mkdir

Change to a different directory: cd

To go up one level in the directory tree, use two dots: cd ..

2|Page
Copy file: cp

To make a copy of file1 and give it the name file2 (in the current working directory), use:

Move file: mv

Delete file: rm

Delete ("remove") directory: rmdir

Clear the terminal window: clear

3|Page
View a (text) file on screen: less

Read documentation on a command: man

4|Page
Search document for a matching command: apropos

Note that this is the same as using the "-k" option with man:

Run a command as the administrative ("root") user: sudo

Downloading Files Using wget

wget is a command-line tool used to download files from the web over HTTP, HTTPS, and FTP.

5|Page
Edit a text file: gedit

Count the number of characters, words, or lines in a file: wc

What do the first three numbers in the output of the wc utility mean?

1 → There is one line in the file.


11 → There are 11 words in the file.
59 → The file has 59 bytes, which are characters that include newlines and spaces.

Redirect input and output: < and >

Change the input to a program from standard input to a file: <

6|Page
Change the output of a program from standard output to a file: >

Change the output of a program from standard output to a file, appending to the end: >>

(You should have two copies of the docs in the file now!):

7|Page
Lab Part 2 - Automating Log Collection and Email
Reporting Using Bash Scripts

Step 1: Introduction to Bash and Script Setup

8|Page
Step 2: Use and configure an External SMTP Server (e.g., Gmail)

. Install ssmtp and mailutils:

• First, install the necessary packages for sending emails via an external SMTP server. Open a
terminal and run the following command to install ssmtp and mailutils:

2. Configure ssmtp for Gmail:

• Next, you'll need to edit the ssmtp.conf file to set up Gmail’s SMTP server. Open the
configuration file:

9|Page
3. Generate an App Password:

Important: Gmail now requires the use of an App Password instead of your normal Gmail password for
third-party applications (like sending emails through a script).

4. Once you’ve configured ssmtp, you can test the email setup by sending a simple test email or running
the script (logcollector.sh) to check the full functionality.

• Send a test email to verify that your email configuration is working. Run the following command,
replacing [email protected] with your Gmail address:

10 | P a g e
• Run the Bash script (logcollector.sh) to test the full log collection and email functionality. Use the
following command:

Step 3: Set Up a Cron Job

By scheduling the script to run at specific intervals (e.g., every hour or every day), the cron job ensures
that your system logs are consistently gathered, summarized, and emailed as part of regular system
maintenance, improving efficiency and reliability.

1. Edit the Cron Table:

crontab -e

2. Add a New Cron Job: Add the following line to run the script every 1 hour:

0 * * * * /path/to/logcollector.sh

Replace /path/to/logcollector.sh with the actual path where your script is located.

o 0: Run at minute 0.

o *: Run every hour.

o *: Every day of the month.

o *: Every month.

o *: Every day of the week.

11 | P a g e
3. Save and Exit the Cron Table:

In nano, save and exit the editor by pressing Ctrl + X, then Y and Enter.

4. To verify that the cron job was added successfully, you can list the current cron jobs by typing:

crontab -l

5. Now that the cron job is set up, the script will automatically run every hour. To monitor its
execution. You can check cron logs to confirm that the cron job is running correctly by looking at
the cron logs:

grep CRON /var/log/syslog

12 | P a g e
6. Demonstrate that the script is working as expected by showing two emails received within a two-
hour period, as shown below.

13 | P a g e
Important!

Once you have finalized the lab and no longer need the cron job running, it is important to
deactivate it to avoid receiving logs continuously. Follow these steps:
1. Edit the cron job configuration: Open the crontab file by running the following command:

crontab -e

2. Comment out the cron job: In the crontab file, add a # at the beginning of the line that
schedules the log collection script. It should look like this:

# 0 * * * * /path/to/logcollector.sh

By commenting out the line, you will prevent the cron job from running and stop the log summaries from
being sent.

3. Save and exit the crontab: Press CTRL+X, then Y to save and exit the file.

14 | P a g e
References:

https://www.geeksforgeeks.org/basic-linux-commands/

https://www.digitalocean.com/community/tutorials/send-email-linux-command-line

15 | P a g e

You might also like