The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
interactive shell script to create users 10.4 tlarkin OS X (Apple) 3 03-27-2008 11:35 AM
shell script help for users cmontr Shell Programming and Scripting 9 11-15-2007 06:17 AM
check my first shell script gridview Shell Programming and Scripting 2 05-14-2007 12:34 PM
check in unix shell script so that no one is able to run the script manually adi_bang76 Shell Programming and Scripting 1 11-16-2006 06:43 AM
Bourne Shell script - log for users loggin on and off noodlesoup Shell Programming and Scripting 14 09-08-2006 07:30 PM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-31-2008
Registered User
 

Join Date: Jan 2008
Posts: 6
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
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 01-31-2008
Registered User
 

Join Date: Jan 2007
Location: Boston, USA
Posts: 16
is who command working in your system ?

Hi

is "who" command working in your system ?

==========
Thanks,
Karthikeyan.
==========
Reply With Quote
  #3 (permalink)  
Old 01-31-2008
Registered User
 

Join Date: Jan 2007
Location: Boston, USA
Posts: 16
Thumbs up 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.
==========
Reply With Quote
  #4 (permalink)  
Old 02-01-2008
Registered User
 

Join Date: Jan 2008
Posts: 6
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
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 07:24 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0