Written Assignment Unit 5 Social

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

Written Assignment Unit 5

University of the People

CS 3307 - Operating Systems 2

December 20th, 2023


2

Abstract

This document provides a comprehensive guide for beginners on automating the process of

downloading and organizing sales reports using bash scripting. It details a sample script for these

tasks and explains each step in the process, including dependencies and scheduling.

Introduction

The purpose of this document is to guide beginners through the process of automating the

download and organization of sales reports. This task is crucial for efficient data management.

Sample Bash Script

Variables

Explanation: According to Gite (2023), (#!/bin/bash) specifies that the script should be executed

in the bash shell, ensuring compatibility and predictability of the script's behavior. FILE_URL,

LOCAL_FILE, DESTINATION_FOLDER. These variables are used to define the remote file's

URL, the local file path, and the destination folder for organizing reports.
3

Download_tools function

Explanation: According to Gite (2023), the check_download_tools function determines whether

to use wget or curl for downloading files.

Download_report function:

Explanation: The download_report function uses the selected tool to download the report.

Organize_report function:
4

Explanation: The organize_report function checks if the destination folder exists and creates it if

it doesn't. Then, it moves the downloaded file to the destination folder (Pete & Pete, 2023).

Steps for Downloading and Scheduling the Report

1. Grant execute permission to the script (IBM documentation, n.d.).

2. Edit the crontab to add a scheduled job (IBM documentation, n.d.):

Setting Up the Script

1. Ensure wget or curl is installed on your system (Gite, 2023).

2. Place the script within the home directory of a user with the necessary permissions.

3. Use the crontab command as described above to schedule the script (IBM, n.d.).

4. Test the script manually before scheduling to ensure it functions as expected.

Conclusion

Automating the download and organization of sales reports ensures efficiency and accuracy

within the e-commerce environment. By following the steps outlined in this document, you can

set up the script to run as required.


5

Sample Bash File

#!/bin/bash

# URL of the sales report


FILE_URL="https://my.uopeople.edu/pluginfile.php/1808573/mod_wor
kshop/instructauthors/Sample-Spreadsheet-1000-rows.csv"

# local path for the report


LOCAL_FILE="/tmp/Sample-Spreadsheet-1000-rows.csv"

# destination path where the report will be organized


DESTINATION_FOLDER="/var/reports/sales/"

# check for the existence of wget or curl


check_download_tools() {
if command -v wget > /dev/null; then
DOWNLOAD_COMMAND="wget -O \"$LOCAL_FILE\" \"$FILE_URL\""
elif command curl > /dev then
DOWNLOAD_COMMAND="curl -o \"$LOCAL_FILE\" \"$FILE_URL\""
else
echo "Error: wget or curl is required"
exit 1
fi
}

# download the sales report


download_report() {
echo "Starting download of the sales report..."
if ! eval $DOWNLOAD_COMMAND; then
echo "Download failed."
exit 1

#organize the report


organize_report() {
if [ ! -d "$DESTINATION_FOLDER" ]; then
mkdir -p "$DESTINATION_FOLDER"
fi
mv "$LOCAL_FILE" "$DESTINATION_FOLDER"
echo "Report organized in folder: $DESTINATION_FOLDER"
}
6

References

Gite, V. (2023, October 3). How to download a file with curl on Linux/Unix command line.

https://www.cyberciti.biz/faq/download-a-file-with-curl-on-linux-unix-command-line/

Prakash, A. (2023, August 20). Bash scripting tutorial for Beginners. It’s FOSS.

https://itsfoss.com/bash-scripting-tutorial/

NinjaOne. (2023, December 7). How to Download Files from URLs with a Bash Script

|https://www.ninjaone.com/blog/how-to-download-files-from-urls-with-a-bash-script/

Pete, & Pete. (2023, November 24). File Manipulation and Automation with Bash scripting.

https://www.linuxmo.com/file-manipulation-and-automation-navigating-the-world-of-bas

h-scripting/

IBM documentation. (n.d.). Grant permission for shell scripting.

https://www.ibm.com/docs/en/fci/1.1.0?topic=installation-grant-permission-shell-scripts-

configuring-cron-job

You might also like