![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Rules & FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| 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 |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
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 |
| Forum Sponsor | ||
|
|
|
|||
|
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 Quote:
Thanks, Karthikeyan. ========== |
|
|||
|
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 |
|||
| Google UNIX.COM |