script check the users in SHELL ?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting script check the users in SHELL ?
# 1  
Old 01-31-2008
script check the users in SHELL ?

could you please find a solution for this

script that checks if any of a list of users given on the command line is logged in. For each user the script should say whether this user is logged in or not. The script prints an error message if no parameter is given. And ask the user to enter a name and then the script check again for this user. check if the given name has an account on system or not by check if the given name exists in file /etc/passwd or not.

I really dont know how to do it special i am newer on it, and kind of help will be nice
# 2  
Old 01-31-2008
is who command working in your system ?

Hi

is "who" command working in your system ?

==========
Thanks,
Karthikeyan.
==========
# 3  
Old 01-31-2008
MySQL Try this....

Hi

Below is the piece with which you can achieve your task.

Code:
while [[ -z $user ]]
do
echo "Enter the user name : "
read user
done

echo
echo "Validating the $user ..."
if [[ `grep -c $user /etc/passwd` -eq 0 ]]
then
   echo
   echo "ERROR : PLEASE ENTER A VALID USERNAME."
   echo "Exiting ..."
   exit 1
else
   echo
   echo "$user IS A VALID USER."
   echo "Checking whether the $user is logged on or not ..."
   echo
fi

if [[ `who | grep -c $user` -eq 0 ]]
then
   echo
   echo "$user IS NOT LOGGED INTO THE SERVER !!!"
   echo
   exit 0
else
   echo
   echo "$user IS LOGGED INTO THE SERVER !!!"
   echo
fi

Below are its execution steps.

Quote:
$ > check_user.sh
Enter the user name :
root

Validating the root ...

root IS A VALID USER.
Checking whether the root is logged on or not ...


root IS NOT LOGGED INTO THE SERVER !!!

$ >
==========
Thanks,
Karthikeyan.
==========
# 4  
Old 02-01-2008
thank you very much, it works perfectly.

I have just 3 more things that I really need to know the solution, please allow me to show it.

script that backup a file. The file name to backup should be provided as input parameter, the backup file should have the same file name with the extension ".bak". If the user provides no input parameter, the script should display an error message. If there is an input file name, but it does not exist, the script should display an error message. If the input file exists, the script should create the backup file and overwrite any existing backup file with the same name.

---

script (called phone) that creates a simple telephone list (create an empty file called “phonlist” in home directory) . Each line in this file consist of two fields name and the phone number, the script should do the following:
When user types the command : “phone new <name> <number>” this will add new record (name,number) to the list.
When user type command: “phone <name>” then the script should search in the file “phonelist” and gets the phone number and display the result.

---

a complex command using pipes to Calculate the number of hits per client in Squid log file (access.log), the command should display most active hosts first.

Line example

1197979501.787 1 10.1.14.62 TCP_NEGATIVE_HIT/404 1463 GET http://url

The output should be like:

34 10.1.14.3
33 10.1.14.5
22 10.1.16.1
18 10.1.18.1

I'm deadly need to understand the solutions, I think its a huge step for me to learn the programming on this script.

thanks
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. BSD

Creating an array out of users: shell script

I want to create a shell script for a menu selection consisting of users defined on the machine. To an administrator having the privileges, the selection menu will look as follows: Select the user you want to define the variables for: 1) my-username-1 2) my-username-2 etc Then there would be a... (7 Replies)
Discussion started by: figaro
7 Replies

2. Shell Programming and Scripting

script to check for a directory in /home for all users

Following on from this post: https://www.unix.com/shell-programming-scripting/150201-simple-script-mount-folder-all-users-home.html and getting told off for bumping the thread:( Please could someone help me with a short script to check is a certain directory is present in /home for all users... (8 Replies)
Discussion started by: barrydocks
8 Replies

3. Solaris

Shell script to add users on solaris

Hi admins, I am trying to run a script to add users on solaris with password: I am using crypt for passwords: The part of my scripts is as below: if ; then echo "$username exists!" exit 1 else pass=$(perl -e 'print... (5 Replies)
Discussion started by: snchaudhari2
5 Replies

4. Shell Programming and Scripting

Help with shell script - creating users

echo -e "Enter in a username : \c" read username grep "^$username:" /etc/passwdWhat I'm trying to do is take in a username from my script and I need to be able to check if that username already exists. If it does the script should display a message saying that the user already exists and exit. ... (2 Replies)
Discussion started by: shadowcat
2 Replies

5. Shell Programming and Scripting

shell script for monitoring users activities

hi I need a shell script which runs perpetually in background and monitors different aspects of different users on different files and their usages for example say there r 3 users so i want when they log in i.e. their log in time and their file access, modify and change log of each file of a... (3 Replies)
Discussion started by: rrd1986
3 Replies

6. Shell Programming and Scripting

script check the users in SHELL every 1 minute ?

could you please find a solution for this: I need to write a shell script which checks after every minute whether a friend has logged in or not.The script should report whether that person has logged in along with the amount of time the person was late in logging in. I have no idea how to... (2 Replies)
Discussion started by: blunderblitz
2 Replies

7. Shell Programming and Scripting

Script to check users logged out

Hi, Here is the script that I have written to check if a particular user is has logged out, and if yes, then a mail needs to be sent to the management the details of whatever has been captured by the script command. echo "The current users are:" who | awk '{print $1}' | sort > temp1 cp... (1 Reply)
Discussion started by: ggayathri
1 Replies

8. Shell Programming and Scripting

Script to check top 5 biggest disk space users

Hi all, I am needing a bash shell script to generate a list of the top 5 users using the most disk space. I am thinking that the du command would be used somehow but I am at a loss. Can anyone help? Thanks! (3 Replies)
Discussion started by: sytemx
3 Replies

9. OS X (Apple)

interactive shell script to create users 10.4

Hello everyone, Not sure if this is the right place, but OS X isn't your standard Unix, so I figured here would be best. I am looking at creating a script that will be interactive that admins can run to create users. Now, 10.4 uses netinfo database and netinfo manager to handle it's users. ... (3 Replies)
Discussion started by: tlarkin
3 Replies

10. Shell Programming and Scripting

shell script help for users

Hello guys, I would appreciate if someone can help me for this task: I have a large txt file that contains lots of user ids in different format. I need to run this against a database output ldif file and print to a file whether they exist or not. And if they exist then I need to print their... (9 Replies)
Discussion started by: cmontr
9 Replies
Login or Register to Ask a Question