(Solved) : Scripting Examples Example 1 Write Shell Script Prints Name Waits User Press Enter Key Scr Q42677258 . . .

More scripting examples

Example 1

Write a shell script that prints out your name and waits for theuser 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 filewith 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:

Write a script that upon invocation shows the time and date andlists all logged-in users. The script then saves this informationto a logfile.

#!/bin/bash

DATE_TIME = $(date)

echo $DATE_TIME

USERS = $(who)

echo $USERS

echo $DATE_TIME $USERS > log

exit

#!/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 3

# And we are done…

echo

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

Example 3

  1. Write a script which when executed will perform the following:
    1. Will Create a directory by today’s date in dd-mm-yyyy format(eg. 20-04-2019)
    2. Will Ask for a file name
    3. Test if a file by same name exists in your home directory.
    4. If the file is present Copy the file to the newly createddirectory
    5. If the file is not present, the script will create the file bythe same name in the newly created directory.
    6. Finally, display the contents of the newly createddirectory.

Expert Answer


Answer to More scripting examples Example 1 Write a shell script that prints out your name and waits for the user to press the [E…

Leave a Comment

About

We are the best freelance writing portal. Looking for online writing, editing or proofreading jobs? We have plenty of writing assignments to handle.

Quick Links

Browse Solutions

Place Order

About Us