Thanks to visit codestin.com
Credit goes to www.scribd.com

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

CSC308 Final Lab1 Operating Systems

The document outlines a lab assignment for CSC308 Operating Systems, detailing steps for basic command line operations and configuring an external SMTP server using Gmail for automated email notifications. It includes instructions for setting up a cron job to run a log collection script at regular intervals. Additionally, it emphasizes the importance of deactivating the cron job after completion to prevent continuous log emails.

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 views18 pages

CSC308 Final Lab1 Operating Systems

The document outlines a lab assignment for CSC308 Operating Systems, detailing steps for basic command line operations and configuring an external SMTP server using Gmail for automated email notifications. It includes instructions for setting up a cron job to run a log collection script at regular intervals. Additionally, it emphasizes the importance of deactivating the cron job after completion to prevent continuous log emails.

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/ 18

CSC308 Operating Systems

Spring 2024-2025
Lab 1
Instructor: Dr. Osama AlOmari

Name ID

Shahed Muhammad Ghazal 1088497


Lab Part 1
Step 1) PS1=”\d \@ [Your_Student-ID]”

Step 2) use the ls: lists files.

and ls -a : list all contents of your current working directory, including hidden files.

Step 3) make directory using mkdir

Step 4) change the directory using cd

Step 5) to go up a level use cd ..


Step 6) copy the file using cp

Step 7) make a copy of file1 and name it file2 using cp ../

Step 8) if you want to move file use mv

Step 9) if you want to delete file use rm

Step 10) if you want to remove directory use rmdir (I created a folder then removed it)

Step 11) to clear the terminal use clear


Step 12) to view use less
Step 13) to read documentation use man

Step 14) search for any file using apropos


Step 15) to run in administrative user use sudo

Step 16) you can download the files using wget


Step 17) edit the text file using gedit
Step 18) you can count the n.o of words or lines or characters using wc

What do the first three numbers in the output of the wc utility mean?
1---- means there is only one line in the file.

18—means there are 18 words in the file.


103- means there are 103 bytes, in other words characters.

Step 19) you can redirect using <>

Step 20) you can change the output from standard to file using >
Then, to change append >> to the end
Lab Part 2

Step 1) bash and script setup

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


SMTP (Simple Mail Transfer Protocol) is used to send emails from one server to another. In this lab,
we will configure your system to send log summaries via email using Gmail's SMTP server. By using
SMTP, you can automate the process of sending emails without needing to set up a local mail server.
This is ideal for sending automated notifications, like system log summaries, directly to your inbox.
Gmail's SMTP server will handle the email delivery securely, using encryption (TLS/SSL) to protect the
data.
In the lab, you’ll configure your system to send emails through Gmail using ssmtp (a lightweight SMTP
client), making it easy to integrate email notifications into your scripts.

1. 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:
sudo apt install ssmtp mailutils -y
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:
sudo nano /etc/ssmtp/ssmtp.conf

 Add the following lines to the configuration file, replacing the placeholders with your actual
Gmail credentials:
[email protected]
mailhub=smtp.gmail.com:587
[email protected]
AuthPass=your_app_password
FromLineOverride=YES
UseSTARTTLS=YES
o root: Your Gmail email address that will be used to send the email.
o mailhub: Gmail's SMTP server address and port ( smtp.gmail.com:587 for TLS).
o AuthUser: Your Gmail email address again.
o AuthPass: Your App Password (more on this below).
o FromLineOverride: Allows setting a custom "From" address in outgoing emails.
o UseSTARTTLS: Uses STARTTLS for email transmission security.

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).
To generate an App Password:
 Go to Google Account Settings.
 Under Security, find App Passwords.
 Select Mail as the app and Other for the device, then generate the password.
 Name the app password as LogCollectorXYZ, where X, Y, and Z are the first, third, and fifth
digits of your student ID.
 Copy the generated App Password and replace your_app_password in the ssmtp.conf
configuration with it.

For more details about how to generate an App Password, watch this video:
https://www.youtube.com/watch?v=N_J3HCATA1c

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:
echo "Hello Sir" | ssmtp [email protected]
If the email is received successfully, the setup is correct.

 Run the Bash script (logcollector.sh) to test the full log collection and email functionality. Use
the following command:

sh logcollector.sh
Step 3) Set Up a Cron Job

In this lab, we use a cron job to automate the execution of the log collection script (logcollector.sh) at
regular intervals, ensuring that the process runs without requiring manual intervention.

Cron is a time-based job scheduler in Unix-like operating systems, such as Ubuntu, and is ideal for
automating tasks like:

 Running scripts periodically (e.g., every hour, day, etc.).


 Reducing the need for manual monitoring or intervention.
 Ensuring that system logs are regularly collected and sent via email without forgetting or
skipping any important tasks.

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.

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

6. Demonstrate that the script is working as expected by showing two emails received within a
two-hour period, as shown below.
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.

This action will stop the cron job from sending log summaries every hour. It is crucial to do this to
avoid receiving continuous logs. If needed, you can reactivate it later by simply removing the # and
saving the file again.
References:

https://help.ubuntu.com/community/UsingTheTerminal

https://www.tutorialspoint.com/unix/bash-scripting-introduction.htm

https://opensource.com/article/17/11/how-use-cron-linux

https://ubuntu.com/tutorials

You might also like