Visit The New, Modern Unix Linux Community

Help with Shell Script: User Lookup

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with Shell Script: User Lookup
# 1  
Help with Shell Script: User Lookup

Hi everyone,

Let me start by stating this question is for homework help (not "help, my boss needs this ASAP")

I have spent the last few days re-visiting this script, and cannot figure out where I am going wrong (something simple I'm sure).

I am to build a script that searches for a user within the ~/SLASH/etc/passwd file, and return the line of the file that contains the user name.

Execution of the script will look like [ bob]

I am sure there are better commands to use, but [cat ~/SLASH/etc/passwd | grep (user input)] is the desired command to display the results. Testing the command at the shell prompt [cat ~/SLASH/etc/passwd | bob] does work, I'm just not sure where I'm going wrong bringing that command to this script:

#! /bin/bash

output= 'cat ~/SLASH/etc/passwd | grep (userName)'
if [ "$output == "" ]; then
echo "Cannot find user "
echo "$output"



The shell returns "no such file or directory" (relates to my 'output' line).
Also returns "Cannot find user", even though "bob" is definitely in the file.
(If inputted name is not found in the file, then "Cannot find user" is returned)

Last edited by jjc032681; 07-02-2017 at 10:22 PM.. Reason: Code did not insert
# 2  
Welcome to the forum!

Homework question should be posted in Homework & Coursework Questions filling in the correct form to its entirety according to the forum rules.

In either case, please show us what you have tried so far to solve this problem on your own, using (CODE) tags where applicable.

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #180
Difficulty: Medium
The Apple II was invented by Steve Jobs.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Korn shell - lookup table

Hi All I need to pass country code into a pipe delimited file for lookup. It will search country code (column 3) in the file, if the country code matched, it will return value from other columns. Here is my mapping file. #CountryName|CountryRegion|CountryCode-3|CountryCode-2... (5 Replies)
Discussion started by: lafrance
5 Replies

2. Shell Programming and Scripting

How to Switch from Local user to root user from a shell script?

Hi, I need to switch from local user to root user in a shell script. I need to make it automated so that it doesn't prompt for the root password. I heard the su command will do that work but it prompt for the password. and also can someone tell me whether su command spawns a new shell or... (1 Reply)
Discussion started by: Little
1 Replies

3. UNIX for Dummies Questions & Answers

Shell script to read lines in a text file and filter user data Shell Programming and Scripting

sxsaaas (3 Replies)
Discussion started by: VikrantD
3 Replies

4. Shell Programming and Scripting

How to Login as another user through Shell script from current user[Not Root]

Hi Every body, I would need a shell script program to login as different user and perform some copy commands in the script. example: Supppose ora_toms is the active user ora_toms should be able to run a script where user: ftptomsp pass: XXX should login through and run the commands ... (9 Replies)
Discussion started by: ujjwal27
9 Replies

5. Shell Programming and Scripting

Shell Script to change a user password using script

Hi Experts, I had tried to executes this script to change the user password through script: No lines in buffer #!/bin/ksh cat /etc/passwd | grep -v userid >> /tmp/pass.tmp1 cat /etc/passwd | grep userid >> /tmp/pass.tmp2 PASS1=`cat /tmp/pass.tmp2 | cut -d ":" -f2` PASS2=`q2w3e4r5` sed... (3 Replies)
Discussion started by: indrajit_renu
3 Replies

6. Shell Programming and Scripting

root user command in shell script execute as normal user

Hi All I have written one shell script for GPRS route add is given below named URL="" VBURL="" echo "Setting route for $URL for GPRS" URL_Address=`nslookup $URL|grep Address:|grep -v "#"|awk -F " " '{print $2}'|head -1` echo "Executing ... (3 Replies)
Discussion started by: mnmonu
3 Replies

7. Shell Programming and Scripting

variable lookup problem in shell script

Hi I have one properties file containing as $INSTALL_BASEPATH/mssages/ $INSTALL_BASEPATH/resource/ and $INSTALL_BASEPATH is set in .bash_profile but from shell script when I read this file and use in copy statement then it... (7 Replies)
Discussion started by: mnmonu
7 Replies

8. UNIX for Advanced & Expert Users

Clueless about how to lookup and reverse lookup IP addresses under a file!!.pls help

Write a quick shell snippet to find all of the IPV4 IP addresses in any and all of the files under /var/lib/output/*, ignoring whatever else may be in those files. Perform a reverse lookup on each, and format the output neatly, like "IP=, ... (0 Replies)
Discussion started by: choco4202002
0 Replies

9. Shell Programming and Scripting

How do i change to super user then revert back to ordinary user ,using shell script?

Hi all, I am trying to eject the cdrom from a livecd after certain stage... Now assuming that it is possible to eject,please consider my issue!!! The OS boots into a regular user by i am unable to use the eject command to push out the drive... However if i try pfexec eject it... (3 Replies)
Discussion started by: wrapster
3 Replies

10. UNIX for Dummies Questions & Answers

Lookup between 2 files ( korn shell )

Hi All., i have a problem. I hope i can get some help on this issue here; i have 2 txt files say file1 and file 2 file1 has; WLMT:XXXXXXXX:cp DOLR:YYYYYYY:ascii,unblock WLG:TTTTTTT:dd:73:ascii,unblock MAR:SSSSSS:dd:152:ascii,unblock GGG:QQQQQQQQQQ:112:ascii,unblock EIE:CCCCCCCC:cp... (17 Replies)
Discussion started by: pavan_test
17 Replies

Featured Tech Videos