You are on page 1of 4

CSBP 315 – Operating Systems Fundamentals

Lab 7 Assignment
Name : Obaid Mubarak Alnuaimi – ID : 201503908
Objective:

More scripting examples

Example 1

Write a shell script that prints out your name and waits for the user to press the [Enter] key
before the script ends.

#!/bin/bash

echo "Ahmed"

read -p "Press [Enter] key to continue..."

Example 2

You need to use ${varName} to avoid any kind of ambiguity

Write a script to prompt for your name and then create a file with your ‘<name>_file’ as file
name.

#!/bin/bash

echo "What is your name?" read

USER_NAME # Input from user

echo "Hello $USER_NAME" touch $

{USER_NAME}_file

echo "I have created you a file called ${USER_NAME}_file"

Example 2:
This study source was downloaded by 100000876763978 from CourseHero.com on 11-30-2023 01:57:50 GMT -06:00

https://www.coursehero.com/file/40891514/OS-Lab7Assignment-Obaid-Alnuaimi-201503908docx/
Write a script that upon invocation shows the time and date and lists all logged-in users. The
script then saves this information to a logfile.

#!/bin/bash

DATE_TIME = $(date)

echo $DATE_TIME

USERS = $(who) echo

$USERS

echo $DATE_TIME $USERS > log exit

Example 3
#!/bin/bash

# Display welcome message, computer name and date

echo "*** Backup Shell Script ***" echo

echo "*** Run time: $(date) @ $(hostname)" echo

# Define variables

BACKUP="/CIT01"

NOW=$(date +"%d-%m-%Y")

# Let us start backup

echo "*** Dumping MySQL Database to $BACKUP/$NOW..."

# Just sleep for 3 secs sleep

# And we are done...

echo

echo "*** Backup wrote to $BACKUP/$NOW/latest.tar.gz"

This study source was downloaded by 100000876763978 from CourseHero.com on 11-30-2023 01:57:50 GMT -06:00

https://www.coursehero.com/file/40891514/OS-Lab7Assignment-Obaid-Alnuaimi-201503908docx/
Homework:

1. Write a script which when executed will perform the following:


a. Will Create a directory by today’s date in dd-mm-yyyy format (eg. 09-04-2018) b.
Will Ask for a file name
c. Test if a file by same name exists in your home directory.
d. If the file is present Copy the file to the newly created directory
e. If the file is not present, the script will create the file by the same name in the newly created
directory.
f. Finally, display the contents of the newly created directory.

After completion, upload the script as text file to Blackboard submission for grading.

This study source was downloaded by 100000876763978 from CourseHero.com on 11-30-2023 01:57:50 GMT -06:00

https://www.coursehero.com/file/40891514/OS-Lab7Assignment-Obaid-Alnuaimi-201503908docx/
This study source was downloaded by 100000876763978 from CourseHero.com on 11-30-2023 01:57:50 GMT -06:00

https://www.coursehero.com/file/40891514/OS-Lab7Assignment-Obaid-Alnuaimi-201503908docx/
Powered by TCPDF (www.tcpdf.org)

You might also like