This is a discussion on Alphabetical file name and list logged in user script within the Shell scripting forums, part of the Development/Scripting category; Hi, i couldnt figure out how to write this script. can any one help me ? please responce asap problem ...
|
|||||||
| Register | FAQ | Members List | Calendar | Forgotten your password? | Mark Forums Read |
|
|||
|
Hi, i couldnt figure out how to write this script. can any one help me ? please responce asap
problem 1: Write a shell script (/bin/sh) to write the names of the first (alphabetically) five files of the current directory to a new file called ‘zzz’. problem 2: Write a shell script (/bin/sh) called 'loggedOn' which is passed two usernames as command line parameters. Using the ‘who’ command, the script should see whether both users are logged on and, if so, should indicate which of them is logged onto the system the most times. If only one or neither is logged on, an error message should be written. |
| Sponsored Links | ||
|
|
|
||||
|
Quote:
Code:
#!/bin/sh ls | head -5 Quote:
Code:
#!/bin/bash
USR1=$1
USR2=$2
u1times=0
u2times=0
if [ $# -ne 2 ]; then
echo "Syntax: $0 user1 user2"
exit 1
fi
who | egrep -w $USR1 > /dev/null
if [ $? -eq 0 ]; then
u1times=$(last | egrep -w $USR1)
else
echo "Error $USR1 not logged in"
exit 1
fi
who | egrep -w $USR2 > /dev/null
if [ $? -eq 0 ]; then
u2times=$(last | egrep -w $USR2)
else
echo "Error $USR2 not logged in"
exit 1
fi
if [ $u1times -gt $u2times ]; then
echo "$USR1 logged most of the time"
else
echo "$USR2 logged most of the time"
fi
Hope you are able to explain it to your tutor
__________________
Rocky Jr. You may have my body & soul, but you will never touch my pride! If you have knowledge, let others light their candles at it. Certified to work on HP-UX / Sun Solaris / RedHat |
|
|||
|
thanks for your help buddy. but the first problem u solved is not clear for me. because there is something i need to make, such as creat a new file and u didnt complete the whole thing
|
![]() |
| Bookmarks |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) |
|
| Thread Tools | |
| Display Modes | |
|
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Getting the list of directory names into a file | hiddenrider007 | Shell scripting | 2 | 04-09-2008 10:59 AM |
| AIX /etc/security/user like file for Linux | ftengcheng | Getting started tutorials | 4 | 03-25-2008 02:28 AM |
| script for mailing to user the o/p of the script | ricc | Shell scripting | 3 | 07-11-2007 05:59 AM |
| list every user's crontab script | marinm | Shell scripting | 5 | 07-20-2005 12:24 AM |
| shell script for finding users not logged on for last 10 day | ganes | Shell scripting | 4 | 07-06-2005 12:01 PM |