1,105,271 Community Members

Shell Script Tasks

Member Avatar
Icostyle
Newbie Poster
2 posts since Jan 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Shell Script Tasks

This is a homework assignment to create the below described shell scripts.
I need the scripts so I can complete my university education.
If you would like to help me and can create these scripts, please send them in a zip or rar file to my email: technologicbg@yahoo.com

Thank you.

Task 1:
Compile a script named zad1.sh, which script receives as parameters a list of users (usernames). When executed, the script reads text from the standard input and sends it to those users in the list who have started a session and working in it.

Hint:
- You can use write for sending
- If we want to send a message to users, i.e. to the users unix, student1 and student2, the script can be started as below:

$ ./zad1.sh unix student1 student2
It reads from the standard input, checks which users have been logged in (i.e. unix and student2) and sends them what the script has read.


Task2:
Compile a script zad2.sh, which shows on the screen the files in the current directory, grouped in three columns.

Tasks3:
Compile a script zad3.sh, which would ask for a username and show this username on the screen and with it the HOME directory of this user. If the user does not exist, a proper message has to be generated.

Task4:
Running
$ ll 1> -
a file is being created: -
$ ll
-rw-rw-r-- 1 user1 users 35 Nov 30 15:41 -

How can we see the content of the created file "-"? Compile a script zad4.sh with the proper command.

Task5:
Below is the content of the file /var/log/messages

...
Nov 28 11:30:58 x-wing mon[2921]: no monitor found while trying to run [http.monitor]
Nov 28 11:36:10 x-wing mon[2921]: no monitor found while trying to run [ping.monitor]
Nov 28 11:36:18 x-wing mon[2921]: no monitor found while trying to run [telnet.monitor]
...
The multiple dots (…) are lines with unknown content, which follow the chronological order.

Compile a script zad5.sh, which shows the messages from the last minute (the messages received within the same minute in which the script is being executed).

Example: If the date at the moment when the script was run is November 28, 11:36 AM, we would have:
Nov 28 11:36:10 x-wing mon[2921]: no monitor found while trying to run [ping.monitor]
Nov 28 11:36:18 x-wing mon[2921]: no monitor found while trying to run [telnet.monitor]
...

PS: If the script is named zad5.sh, the answer can be tested by:
$ ./zad5_test.sh ; ./zad5.sh
where zad5_test.sh is:
$ cat zad5_test.sh
# Testing the task for generating the messages from the last minute
# The script adds to the file messages from the last minute
echo `date +%b" "%d" "%H":"%M:%S` Test message >> /var/log/messages

Task6:
- Compile a script with name zad6.sh, which shows its name (the name of the executed file).
Example:
Assume the script is called zad6.sh and is located in the home directory of user unix.
$ ./zad6.sh
Hi,I am a script!
My name is: zad6.sh

- If the script's name is changed, the new name has to be shown, i.e.:
mv zad6.sh zad6a.sh
$ ./zad6a.sh
Hi,I am a script!
My name is: zad6a.sh

- The script has to generate its own name, regardless of how the script is started - by relative or absolute name, regardless of the current directory, thus it has to remove the directory and the suffix from the filename.

Example:
$ /home/unix/zad6.sh
Hi,I am a script!
My name is: zad6.sh
$ cd /home/unix
$ ./zad6.sh
Hi,I am a script!
My name is: zad6.sh
$ cd /home
$ unix/zad6.sh
Hi,I am a script!
My name is: zad6.sh

Hint:
- Some commands that can be used: cut, wc, tr
- There is a command for removing a directory/suffix from a filename - basename, which can be used in case you cannot go without it.

Task7:
Script (zad7.sh) receives one argument as a parameter - string. If a subdirectory of the user's HOME directory does not exist (the user who launches the script), with a name that is the same as the given string, the script created it, copies into it all common files from the current directory, that are available to read and generates on the standard output the number of the rest.

Task8:
a) Compile a script zad8a.sh which shows on the screen in alphabetical order all users in the system and their user ID numbers (UID) in a format (sorting is by username):

adm 3
apache 48
avahi 70
beaglidx 58
bin 1
clamav 102
...

b) Change the script (zad8a.sh) in a way so that it sorts out by UID numbers:

root 0
bin 1
daemon 2
adm 3
lp 4
sync 5
shutdown 6
....

PS: Note that in the output there is no column sign ( : ) between the username and the respective UID.

Task9:
LDAP file is given with the below format:

dn: uid=rhiz,ou=accounts,dc=theo,dc=uni-sofia,dc=bg
uid: rhiz
cn: rhiz
objectClass: account
objectClass: posixAccount
objectClass: top
userPassword:: e2rhizXB0fSQxJHFVS1VaL3RzJHlwbkNtbm5KeG9kM2zE0RWZKaFd=
uidNumber: 565
gidNumber: 565
homeDirectory: /home/rhiz
dn: uid=hristo,ou=accounts,dc=theo,dc=uni-sofia,dc=bg
uid: hristo
cn: hristo
objectClass: account
objectClass: posixAccount
objectClass: top
userPassword:: e2hristoB0fSQxJExEMDBkaElxJEo5dzNScy5yNzhqMHZCLzdjYUdSTi4=
uidNumber: 568
gidNumber: 568
homeDirectory: /home/hristo
...and so on

Compile a script zad9.sh , which accepts as input parameter the filename and generates to the standard output the user and its password.
Note: A user is uid = value of the line starting with dn:
User's password is the value of userPassword::

Example:
$ ./zad9.sh test.ldap
rhiz e2rhizXB0fSQxJHFVS1VaL3RzJHlwbkNtbm5KeG9kM2zE0RWZKaFd=
hristo e2hristoB0fSQxJExEMDBkaElxJEo5dzNScy5yNzhqMHZCLzdjYUdSTi4=
... and so on.

Member Avatar
L7Sqr
Veteran Poster
1,006 posts since Feb 2011
Reputation Points: 179 [?]
Q&As Helped to Solve: 168 [?]
Skill Endorsements: 11 [?]
 
0
 

If you can give a valid reason why we should earn your degree for you then perhaps you will get a valid answer. Until then, dont hold your breath.

Member Avatar
zachmandude32
Newbie Poster
5 posts since Nov 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

I was looking for scripts to write just to practice and familiarize myself more with bash itself. Thanks for posting up these questions...

I am confused on this step from the first assignment...

"When executed, the script reads text from the standard input and sends it to those users in the list who have started a session and working in it."

What text/message are you supposed to send to the users?

Member Avatar
zachmandude32
Newbie Poster
5 posts since Nov 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Never mind...

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article