Question

Create a new script named ifcommand.sh that accepts a username as input and checks to see...

Create a new script named ifcommand.sh that accepts a username as input and checks to see if that user is logged in. If the user is logged in, print "yes", otherwise print "no"

Example;

example@general:~$ ./ifcommand.sh cjingers
yes
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer) First I test whether user has enter only one username or not, then I check by the who and grep command that user has loggedin or not because who command give the details of all the users who have logged in and grep is used to search the username from the who command. I bypass the output by /dev/null

Any doubt please comment me.

vi ifcommand.sh

if test $# -gt 1
then
echo "Type only one username"
exit
fi
if (who|grep $1)>/dev/null
then
echo "yes"
else
echo "no"
fi

save the file

screenshot

~]$ ./ifcommand.sh hadoop ~]$ ./ifcommand.sh hadoopl ~]$ ./ifcommand.sh root ~]$ ./ifcommand.sh root abcd ~]$ ./ifcommand.sh rootl yes no yes Type only one username no

Add a comment
Know the answer?
Add Answer to:
Create a new script named ifcommand.sh that accepts a username as input and checks to see...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • LINUX 140U Create a file named script1.sh that contains a bash script that: Accepts NO command...

    LINUX 140U Create a file named script1.sh that contains a bash script that: Accepts NO command line arguments and does NOT use the read command. I will give you no credit if your bash script includes a read command. Also, you need to have at least one for..in loop in your code even if there may be other ways to do this problem. The script will go through a list of entries in the current directory (do not process subdirectories):...

  • Using java program, create a Username class. ask user to type username 1)username length have to...

    Using java program, create a Username class. ask user to type username 1)username length have to >1 and <15 2)username can not include any special character (ex.!@##$}{|\....) ,but it also have to type Spanish or other foreign language 3)user can not include any empty space (ex. user name) all of three error have to print out. and if there is any error contains, have to ask user to input user name again. for example: input username: #$%he f username can't...

  • Create a powershell script to create a user named: Week10User (provide whatever other details that may...

    Create a powershell script to create a user named: Week10User (provide whatever other details that may be required to create the user.) II. Create a script to create a group named: Week10Group III. Create a script to add the user Week10User into the Week10Group. IV. Create a script to create an organizational unit named: Week10OU V. Create a script to delete the user Week10User from the group named Week10Group. VI. Create a script to add a user named Week10User into...

  • Create a powershell script to create a user named: Week10User (provide whatever other details that may...

    Create a powershell script to create a user named: Week10User (provide whatever other details that may be required to create the user.) II. Create a script to create a group named: Week10Group III. Create a script to add the user Week10User into the Week10Group. IV. Create a script to create an organizational unit named: Week10OU V. Create a script to delete the user Week10User from the group named Week10Group. VI. Create a script to add a user named Week10User into...

  • In UNIX Write a script that checks each minute and reports on who logs in and...

    In UNIX Write a script that checks each minute and reports on who logs in and who logs out. You can follow the steps below (not the only way): Using the commands who and cut, extract the list of usernames currently logged in the system To check after a minute, the sleep command can be used: sleep 60 Get the new list of users logged in after a minute For each user in the list; check if he is in...

  • Create a new Netbeans project application from scratch called MyAge. Create a GUI that accepts user...

    Create a new Netbeans project application from scratch called MyAge. Create a GUI that accepts user input. The final script should be able to calculate your age when your date of birth is entered. Include a simple try and catch for arithmetic errors.

  • Need Java help: 1. Create a Java program that accepts input String input from a user...

    Need Java help: 1. Create a Java program that accepts input String input from a user of first name. 2. Create a Java program that accepts input String input from a user of last name. 3. Concatenate the Strings in a full name variable and print to the console.

  • Please write the code using matlab 1) i. Create an anonymous function named optimist, that accepts...

    Please write the code using matlab 1) i. Create an anonymous function named optimist, that accepts a single variable as input i Create a row vector Tthat represents the number of seconds in two minutes, starting ii. Call the function optimist on the vector T, store the result in variable R1 and returns the double of that variable from one and ending at a hundred and twenty v. Create an anonymous function named pessimist, that accepts a single variable as...

  • Python Create a function that checks user input in an attempt to create a password. The...

    Python Create a function that checks user input in an attempt to create a password. The valid_password function accepts a password as an argument and returns either true or false to indicate whether the password is valid. A valid password must be at least 7 characters in length, have at least one uppercase letter, one lowercase letter, and one digit. Respond with output to the user as to whether the password is valid or not, and allow the user to...

  • Write a Python (3) program to simulate** a buffer overflow (this is a new script, not...

    Write a Python (3) program to simulate** a buffer overflow (this is a new script, not part of the intranet assignment), then implement input validation to prevent it. There are two parts to this assignment: 1) The program should display a welcome message and prompt the user for a username. Create a simulated buffer overflow condition by allowing a user to input more data than the size of the allocated memory (causing the program to crash). 2) Implement input validation...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT