Linux Script Worksheet
POS/433 Version 2 / 2

University of Phoenix Material

Linux® Script Worksheet

To: Lori Nicholson

From: Evan Rosado

Date: 05/21/2017

Before beginning the Linux® Script Worksheet, update the PATH variable to add your folder from last week. You will find how to do this on p. 134 of Linux® Command Line and Shell Scripting Bible.

Linux® Script 1

Requirements

In the same folder as last week, create a new file titled week3prog1[name].scr.
Change the permissions on this new file to add the execute bit for user, group, and owner.
Edit your new file using Gedit or VI and change it so it performs the following actions:
·  Display the date
·  Display the words Hello World
·  Display information about users that are currently logged in
Note: Remember to include #!/bin/bash as the first line of your script.
Save the file and type your file name to execute.

Source Programs

vi week3prog1Evan.scr
#!/bin/bash
05/21/2017
echo “Hello World”
who
:wq
now on command prompt, I change permission
chmod ugo+x week3prog1Evan.scr
to execute:
./week3prog1Evan.src

Output Results


Linux® Script 2

Requirements

In the same folder as last week, create a new file called week3prog2[name].scr.
Change the permissions on this new file to add the execute bit for user, group, and owner.
Edit your new file using Gedit or VI and change it so it performs the following actions:
·  Using a line after #!/bin/bash, take the output of the ps –e command and pipe it to the sort command
·  After it has been piped to the sort command, redirect that output to a file called psfile
Note: Remember to include #!/bin/bash as the first line of your script.

Source Programs

vi week3prog2Evan.scr
#!/bin/bash
ps -e | sort > psfile
Press Esc
:wq
now on command prompt, I change the permission
chmod ugo+x week3prog2Evan.scr
Then execute:
./week3prog2Evan.src

Output Results

Linux® Script 3

Requirements

In the same folder as last week, create a new file called week3prog3[name].scr.
Change the permissions on this new file to add the execute bit for user, group, and owner.
Create two files.
·  File1 has one line with the value of 5.
·  File2 has one line with the value of 100.
Edit your new file using Gedit or VI and change it so it performs the following actions:
·  Read the values from the two files above (file1 and file2)
·  Divide the value from file2 by the value in file1
·  Output the result of this calculation to a new file called file3
Note: Remember to include #!/bin/bash as the first line of your script.

Source Programs

echo 5 > file1.txt
echo 100 > file2.txt
vi week3prog3Evan.scr
#!/bin/bash
val1=`cat file1.txt`
val2=`cat file2.txt`
val3=`expr $val2 / $val1`
echo $val3 > file3
:wq
now on command prompt, I change permission
chmod ugo+x week3prog3Evan.scr
to execute:
./week3prog3Evan.src

Output Results

<Insert the output here. Use a screenshot of the output with the input requirements specified in the assignment.>