Results 1 to 2 of 2

Thread: Write a bash script to produce the following screen

  1. #1
    Junior Member
    Join Date
    Jan 2011
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Default Write a bash script to produce the following screen

    Write a bash script to produce the following screen:


    The userís home directory;
    The userís working directory;
    List of processes owned by the user;
    List of first twelve System Processes;
    A count of the total number of processes running on Student UNIX;


    This is the problem i have been given to do and would like some help with the code mainly for showing the users home directory and working directory. This must show the home and working directory for any user that logs on using the server.

    Thanks

  2. #2
    Contributors jaysunn's Avatar
    Join Date
    Apr 2009
    Location
    NYC - USA
    Posts
    1,023
    Thanks
    164
    Thanked 153 Times in 132 Posts
    Rep Power
    24

    Default

    Hello,
    Bash contains builtin variables that you can view by typing the env command. You can get some valuable information from that command. Such as Present /current working directory. You can use these variables to get what you are after.

    Here is a snippet of the env output.
    Code:
    [jralph@jralph-linux ~]$ env
    USER=jralph
    HOME=/home/PFTCTRADING/jralph
    PWD=/home/PFTCTRADING/jralph/notes
    OLDPWD=/home/PFTCTRADING/jralph
    In your script you can get these variables by echoing them. E.G.


    Code:
    [jralph@jralph-linux notes]$ echo $HOME
    /home/PFTCTRADING/jralph
    [jralph@jralph-linux notes]$ echo $PWD
    /home/PFTCTRADING/jralph/notes
    Hope this get's you started. You can post what you have so far and we can assist you.


    EDIT:

    Also have a look at the PS manpage. As well as the HEAD and WC man page for other requirements.

    PS
    UNIX man pages : ps ()

    HEAD
    UNIX man pages : head ()

    WC
    UNIX man pages : wc ()



    EDIT:
    Some examples of the variable echoing.

    Code:
    [jralph@jralph-linux notes]$ cat scripter.sh 
    #!/bin/bash
    
    echo "Hello the users home directory is $HOME"
    echo "The users curent directory is $PWD"

    If you run it you get.

    Code:
    [jralph@jralph-linux notes]$ ./scripter.sh 
    Hello the users home directory is /home/PFTCTRADING/jralph
    The users curent directory is /home/PFTCTRADING/jralph/notes



    jaysunn
    Last edited by jaysunn; 5th January 2011 at 10:32 PM.

  3. The Following User Says Thank You to jaysunn For This Useful Post:

    dandaman13 (6th January 2011)

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 3
    Last Post: 1st November 2010, 03:43 PM
  2. How to write ls -l command in shell script?
    By Reid in forum Shell scripting
    Replies: 5
    Last Post: 22nd September 2010, 05:48 AM
  3. Linux Cheat Sheets (awk, ed, sed, bash, screen, perl, and more)
    By pkrumins in forum Getting started tutorials
    Replies: 3
    Last Post: 27th March 2009, 07:12 PM
  4. How do I Write a shell script
    By seaman77 in forum Shell scripting
    Replies: 1
    Last Post: 11th February 2009, 02:30 AM
  5. need help to write automated server monitering script
    By vishal Titre in forum Shell scripting
    Replies: 1
    Last Post: 15th July 2006, 01:35 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •