Spent all day trying to figure this script out...


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Spent all day trying to figure this script out...
# 1  
Old 02-07-2011
Spent all day trying to figure this script out...

Before I begin with the question, I just want to point out that I just started learning unix in the middle of last week, so my code (and knowledge of how unix operates) is weak sauce. I took my best stab at this question but it's just not working.

Assignment:
Create a script named 'userprocesses' which will allow you to find all users currently logged on to the system and display the processes they are running. The heading for each user must be their real name not their log in name.
I.e. my login name is lee.ballancore but my real name is Lee Ballancore
The users must not be displayed more than once. DO NOT USE AWK OR SED.
The output should look similar to this.

Lee Ballancore
PID TTY TIME CMD
31799 pts/3 00:00:00 vim
31866 pts/3 00:00:00 vim
2495 pts/7 00:00:00 vim
8368 pts/0 00:00:00 vim
9544 pts/2 00:00:00 ps

Alistairr Rutherford
PID TTY TIME CMD
8368 pts/0 00:00:00 vim
9544 pts/2 00:00:00 ps

Write the output to a file.
-------------------------------------------------

So I spent all day messing around with it, and here's the code I wrote up:
Code:
#!/bin/bash

finger > fingers
a=wc -l fingers
b=0

username=$(finger | cut -d ' ' -f1)
fullname=$(grep $username /etc/passwd | cut -d : -f5) >name
ps -au $username > process


until [ $a -eq $b ]; do
   cat name | cat - process
   a=$a - 1
done

# 2  
Old 02-07-2011
This is not the forum thread for homework.
Take a look here and use the proper procedure.
https://www.unix.com/homework-coursew...ons-forum.html
This User Gave Thanks to Aia For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Oracle/SQLPlus help - ksh Script calling .sql file not 'pausing' at ACCEPT, can't figure out why

Hi, I am trying to write a script that calls an Oracle SQL file who in turns call another SQL file. This same SQL file has to be run against the same database but using different username and password at each loop. The first SQL file is basically a connection test and it is supposed to sort... (2 Replies)
Discussion started by: newbie_01
2 Replies

2. Shell Programming and Scripting

Help with change significant figure to normal figure command

Hi, Below is my input file: Long list of significant figure 1.757E-4 7.51E-3 5.634E-5 . . . Desired output file: 0.0001757 0.00751 0.00005634 . . . (10 Replies)
Discussion started by: perl_beginner
10 Replies

3. UNIX for Dummies Questions & Answers

[Solved] ksh script - can't figure out what's wrong

Hi! (I guess this could of gone into the scripting forum, but Unix for Dummies seemed more appropriate. Please note that I am not in school, so Homework doesn't seem appropriate either. You guys can let me know if you think otherwise.) I am following an exercise in a book on ksh scripting which... (2 Replies)
Discussion started by: sudon't
2 Replies

4. Shell Programming and Scripting

cant figure out the error in this script (adding numbers in a string) using ubantu shell

hii please help me this is the script num=$1 sum=0 while do x=`expr $num % 10` sum=`expr $sum + $x` num=`expr $num / 10` done echo "Summation is $sum" it is giving error pratyush@ubuntu:~$ sh shell.sh 123 shell.sh: 11: 123: not found Summation is 0 (3 Replies)
Discussion started by: Pratyush Sakhle
3 Replies

5. Shell Programming and Scripting

Anybody here can help me to figure thie perl script out?

Gey guys, I'm a new learner of perl. Now I encountered a problem when I tried to get the output below from the input file. Input: 5'h1f, 16'h8210 write, 5'h10, 16'h0000 write, 5'h11, 16'h0000 5'h1f, 16'hffd0 write, 5'h1e, 16'h0000 5'h1f, 16'h8310 read, 5'h10, rd_data 5'h1f,... (3 Replies)
Discussion started by: sunbaby
3 Replies

6. Shell Programming and Scripting

Script to check if last modified day is previous day

Hi, I would like to write a script that checks if a file ('counter') was modified the previous day, if so erase its contents and write 00000000 into it. For e.g. if the file 'counter' was last modified at 11.30pm on 24th May and the script runs at 12.15am of 25th May, it should erase it's... (1 Reply)
Discussion started by: hegdepras
1 Replies

7. Shell Programming and Scripting

Bash script - im missing something and cant's figure out what

I just put together a script for work that will essentially automate the migration of our Windows fileserver to my newly created Debian based SAMBA server. My script will create the necessary directories then copy the data over to my new server, after that it will set the ACL's by using... (3 Replies)
Discussion started by: binary-ninja
3 Replies

8. Shell Programming and Scripting

Script to find previous month last day minus one day timestamp

Hi All, I need to find the previous month last day minus one day, using shell script. Can you guys help me to do this. My Requirment is as below: Input for me will be 2000909(YYYYMM) I need the previous months last day minus 1 day timestamp. That is i need 2000908 months last day minus ... (3 Replies)
Discussion started by: girish.raos
3 Replies

9. Shell Programming and Scripting

Write a shell script to find whether the first day of the month is a working day

Hi , I am relatively new to unix... Can u pls help me out to find out if the first day of the month is a working day ie from (Monday to Friday)...using Date and If clause in Korn shell.. This is very urgent. Thanks for ur help... (7 Replies)
Discussion started by: phani
7 Replies
Login or Register to Ask a Question