If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > grep -v -f

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-21-02, 04:02
dustin dustin is offline
Registered User
 
Join Date: Nov 2002
Location: Germany
Posts: 1
Unhappy grep -v -f

Hello all !
im from Germany and hope you can understand my bad english

now my problem:

first my script:

echo "folgender User hat sich soeben eingeloggt: "
date
#( until user1= who | egrep -v $uservar
until user1=`who | cut -b 1-8 | fgrep -v -f ./user`
do
sleep 3
date
echo $user1
echo $user1 >> user
cat user
done

ok,
some lines in the script are not important (like date etc.)
importent is line 4!

until user1=`who | cut -b 1-8 | fgrep -v -f ./user`

i want that this line search for users how loggt on in unix. (who)
but they dont show all users only some how stand in the file ./user
and the result of the search must in the variable user1.

i think something of the syntax is wrong.

Please can you help me?

thank you
Reply With Quote
  #2 (permalink)  
Old 11-21-02, 06:01
Damian Ibbotson Damian Ibbotson is offline
Padawan
 
Join Date: Jun 2002
Location: UK
Posts: 525
I think your problem is with using UNTIL. This will execute the contents of the loop until "user1=`who | cut -b 1-8 | fgrep -v -f ./user`" returns an exit status of zero. So, when you find a new user, the code breaks out of the loop.

Try:

until true
do
<some commands>
done

...and you'll see that nothing happens.

Unless I haven't seen what exactly you are trying to achieve here, the code seems to have several flaws. What happens if a user logs off and then logs back on again? What if the same user logs in more than once?

You could have a far more comprehensive script that could trap logins and logouts with an exact time by using all of the information output from the who command.

e.g.

who > file1; sleep 60; who > file2; diff file1 file2

You could write a script around this and format the output as you like.

HINT:

^> = login
^< = logout
Reply With Quote
  #3 (permalink)  
Old 11-26-02, 10:36
WingMan WingMan is offline
Registered User
 
Join Date: Aug 2002
Location: UK
Posts: 87
What is you have a User name greater than 8 characters ...

who -u | awk ' {print$1}

will return the list of users currently logged in wih no limit on the number of characters in the user name.
Reply With Quote
  #4 (permalink)  
Old 11-27-02, 15:06
backer backer is offline
Registered User
 
Join Date: Nov 2002
Posts: 7
Smile

Quote:
Originally posted by Damian Ibbotson
I think your problem is with using UNTIL. This will execute the contents of the loop until "user1=`who | cut -b 1-8 | fgrep -v -f ./user`" returns an exit status of zero. So, when you find a new user, the code breaks out of the loop.

Try:

until true
do
<some commands>
done

...and you'll see that nothing happens.

Unless I haven't seen what exactly you are trying to achieve here, the code seems to have several flaws. What happens if a user logs off and then logs back on again? What if the same user logs in more than once?

You could have a far more comprehensive script that could trap logins and logouts with an exact time by using all of the information output from the who command.

e.g.

who > file1; sleep 60; who > file2; diff file1 file2

You could write a script around this and format the output as you like.

HINT:

^> = login
^< = logout

============================================
I also am trying to figure out what you are trying to do... If you are trying to trap login information, I suggest you investigate modifying your login rules.

If all you are after is creating a file that has login information in it, perhaps take a look at the command 'last' which already has information in it?


I'm not sure I completely understand what you are trying to accomplish, but let me toss a few ideas your way..
(kinda messy, but I think this might be sorta what you are looking for)

#!/bin/sh
#variables and declarations
user=`echo $LOGIN`
userlist=`who | awk '{print $1}'
exist=`echo $userlist | grep $user`
file="/home/filename.txt"

#this just says, if the file exists and
#user is already in the list, then exit, if not in the list
# put him/her in the list

if [ -e $file ] && [ $user = $exist ]; then
exit 0
else
echo $user >> $file
fi
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On