#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2004
    Posts
    43
    Rep Power
    14

    BASH Script, read a line from a file


    Hi, I'm trying to write a BASH script that uses a file containing a list of user names:
    cg776
    jcq448
    dfs
    etc...
    I want to read each line into a string, then run:
    Code:
                   finger | grep FRIEND
    or something to that affect, then I need to determine if the user supports real time chat (the '*' somewhere in the line of output from finger for that user I think...)

    If anyone could lend a hand it would be appreciated...
  2. #2
  3. Introspective
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Nov 2001
    Location
    London, UK
    Posts
    3,317
    Rep Power
    114
    I have a file called names, which looks like:

    chris
    cristi
    spira
    erik

    I have a script called namelooper.sh which looks like:
    Code:
    #!/bin/bash
    
    NAMES=`cat names`
    for i in $NAMES
    do
            RESULT=`finger $i`
            echo $RESULT
    done
    when I chmod 777 namelooper.sh and then run it, I get the following output - tidy it up as you like:

    bash-2.05b# ./namelooper.sh
    Login: chris Name: chris lacy-hulbert Directory: /home/chris Shell: /bin/bash Office: On since Tue May 18 09:51 (BST) on pts/0 from office.enovi.com On since Tue May 18 09:53 (BST) on pts/2 from office.enovi.com 2 minutes 27 seconds idle No mail. No Plan.
    finger: christi: no such user.

    Login: erik Name: (null) Directory: /dev/null Shell: /bin/false Never logged in. No mail. No Plan.
    Login: spira Name: spiration cvs user Directory: /home/spira Shell: /bin/bash Last login Mon May 5 10:21 2003 (BST) on pts/2 from 10.0.0.15 No mail. No Plan.
    Login: angus Name: Fred Lacy-Hulbert Directory: /home/fred Shell: /bin/bash Never logged in. No mail. No Plan.
    Login: root Name: (null) Directory: /root Shell: /bin/bash Last login Thu Apr 29 19:40 (BST) on pts/2 from 192.168.1.10 Mail last read Wed Sep 24 18:53 2003 (BST) No Plan.
    hth
    christo
    Last edited by christo; October 30th, 2006 at 09:25 AM.
    This is me: http://chris.uk.com
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2004
    Posts
    3
    Rep Power
    0

    Question


    how do i get to see the lines i read and search them for a particular char - I need to read and ignore a file till i find a certain string and then write out the rest of the file in to another file using sh ... can some one help ? thanks

    i tried using cat and a for loop but that breaks up the lines into words ... and the echo -n option does not work with my sh ... so it puts the words in seperate lines .

IMN logo majestic logo threadwatch logo seochat tools logo