CSC308 Lab1 VF
CSC308 Lab1 VF
Spring 2024-2025
Lab #1
Instructor: Dr. Osama Al Omari
Name StudentID
Saad Own 1085218
>>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:
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
3|Page
View a (text) file on screen: less
4|Page
Search document for a matching command: apropos
Note that this is the same as using the "-k" option with man:
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
What do the first three numbers in the output of the wc utility mean?
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
8|Page
Step 2: Use and configure an External SMTP Server (e.g., Gmail)
• 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:
• 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:
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.
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 *: Every month.
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:
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