Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Unix shell script help  (Read 7553 times)

0 Members and 1 Guest are viewing this topic.

itfin

  • Guest
Unix shell script help
« on: October 22, 2007, 09:13:11 AM »
This is one of the tasks I need to achieve for my job so please help me if you can:

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 John.Smith but my real name is John Smith
The users must not be displayed more than once.
The output should look similar to this.


John Smith
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

Jane Doe
PID TTY TIME CMD
8368 pts/0 00:00:00 vim
9544 pts/2 00:00:00 ps


Any help will be appreciated
Thanks

Admin edit: Persons real name was used (without permission) in this post that didn't want to be shown.
« Last Edit: December 10, 2007, 10:03:14 AM by Computer Hope Admin »

itfin

  • Guest
Re: Unix shell script help
« Reply #1 on: October 22, 2007, 09:19:03 AM »
The script should not use SED or AWK. :-[

Thanks

TonyRichens

  • Guest
Re: Unix shell script help
« Reply #2 on: October 22, 2007, 10:06:08 AM »
Im reporting you to a Mod serious posting going on here..... turning into spam....

itfin

  • Guest
Re: Unix shell script help
« Reply #3 on: October 22, 2007, 10:13:32 AM »
Im reporting you to a Mod serious posting going on here..... turning into spam....

I didn't gt what you meant by that? Am I not allowed to ask unix doubts here?

WillyW



    Specialist
  • Thanked: 29
  • Experience: Experienced
  • OS: Windows XP
Re: Unix shell script help
« Reply #4 on: October 22, 2007, 10:17:33 AM »
Im reporting you to a Mod serious posting going on here..... turning into spam....

I didn't gt what you meant by that? Am I not allowed to ask unix doubts here?

You are allowed to ask questions here.
However, multiple threads on the same topic are frowned upon.   


Next,  I'll venture a guess here.....   :) .....    you might like to check out:
http://www.computerhope.com/forum/index.php/topic,33332.msg200565.html#msg200565
Be sure to note the third point up from the bottom.   It may apply to you.

.



ghostdog74



    Specialist

    Thanked: 27
    Re: Unix shell script help
    « Reply #5 on: October 25, 2007, 12:53:31 AM »
    The script should not use SED or AWK. :-[

    Thanks
    These 2 essential tools comes shipped together with the system. if you can't even use these for your job, what kind of environment are you in?.

    itfin

    • Guest
    Re: Unix shell script help
    « Reply #6 on: October 26, 2007, 12:28:17 PM »
    I am aware of that, that awk and sed comes along with the system.
    This is basically a script required to prove how powerful the Unix scripting is for reading and writing files without the use of sed and awk.

    I have managed to print the required output except the username.
    Using finger > file and cutting the field 1 by cut -d " " -f1 file I have managed to get the login ids and for each login id I have got the processes.
    But the only thing I am not able to get is the usernames. As mentioned in the sample output we are required to display the Username not the user id.

    Will appreciate any help.

    Thanks

    ghostdog74



      Specialist

      Thanked: 27
      Re: Unix shell script help
      « Reply #7 on: October 27, 2007, 09:23:04 PM »
      I am aware of that, that awk and sed comes along with the system.
      This is basically a script required to prove how powerful the Unix scripting is for reading and writing files without the use of sed and awk.
      I will give you the benefit of the doubt to this
      and this. Its a coincidence that some other people are doing the same job as you..

      Quote
      I have managed to print the required output except the username.
      Using finger > file and cutting the field 1 by cut -d " " -f1 file I have managed to get the login ids and for each login id I have got the processes.
      But the only thing I am not able to get is the usernames. As mentioned in the sample output we are required to display the Username not the user id.

      Will appreciate any help.

      Thanks

      you should read the bash manual, either through the man page or online. meantime, i will give you a small snippet. you go experiment with it.
      Code: [Select]
      finger | while read line; do
        set -- $line
        echo $2 
        done

      itfin

      • Guest
      Re: Unix shell script help
      « Reply #8 on: October 28, 2007, 03:30:49 AM »
      thanks for your help.

      I have managed to do the script using finger -lmps | grep "Login" > tempfile
      and then using the cut command to get the required field.

      Anyways, thanks for your support.

      ghostdog74



        Specialist

        Thanked: 27
        Re: Unix shell script help
        « Reply #9 on: October 28, 2007, 05:57:35 AM »
        thanks for your help.

        I have managed to do the script using finger -lmps | grep "Login" > tempfile
        and then using the cut command to get the required field.

        Anyways, thanks for your support.

        it is strange you can use grep and not awk.
        Code: [Select]
        finger -lmps |  awk '/Login/'
        anyway,glad you found your solution.