[Bourne shell] Asking stuff with #!bin/sh urgent!


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting [Bourne shell] Asking stuff with #!bin/sh urgent!
# 1  
Old 04-05-2010
[Bourne shell] Asking stuff with #!bin/sh urgent!

1. Accept a “userid” as a command line argument
2. Produce the following output:
User userid has a home directory of /path/directory
the default shell for this user is /path/shell
3. At this level, it may be assumed that the “userid” is a unique string in the file that is being searched
4. Provide a suitable error message if the user does not exist
5. Trap any error messages generated by programs called by the script using either I/O redirection or
pre-validation of program arguments
6. Successfully deals with userids that are substrings of other userids
e.g. Two users in the system, “foo” and “foobar” -
Standard search tools, without specifying a correct search string would find both “foo” and “foobar”
when searching for “foo”
Meeting this requirement means selecting just “foo” and not both

anyone can help me with this? very urgent!
# 2  
Old 04-05-2010
Define the problem, no need scream in subject. Subject is interesting or not.
You have accepted the rules.

Make some script ex. xxx:
Code:
#!/bin/sh 
userid="$1"
# grep user, userid + delimiter, then it's uniq
data=`grep "^$userid:" /etc/passwd 2>/dev/null `
# if you have ksh, bash, dash, ... then syntax is (previous also works but ...)
#data=$(  grep "^$userid:" /etc/passwd 2>/dev/null  )
[ "$data" = "" ] && echo "not user $userid" >&2 && exit 1
echo "ok"

And chmod a+rx xxx
and call ex. ./xxx root
# 3  
Old 04-06-2010
sorry for the in appropriate post, but this is some how really urgent for me.

i dont know how or why, but it always returning not user value even when the data inside is matched.
i try another program which quite near to what i shoudl do, but i just cant get the right argument for it. this is teh code i made

for myUSER in `awk -F: '{print $1}' passwd`
do
myUID=`awk -F: '{if ($1 == "'$myUSER'") print $3}' passwd`
if [ $myUID -lt $SysAcct ] || [ $myUID -gt $Special1 -a $myUID -lt $Special2 ] ; then
printf "%s is a system account\n" $myUSER
else
myHOME=`awk -F: '{if ($1 == "'$myUSER'") print $6}' passwd`
mySHELL=`awk -F: '{if ($1 == "'$myUSER'") print $7}' passwd`
printf "%s has a home directory %s and uses the %s shell\n" $myUSER $myHOME $mySHELL
fi
done
# 4  
Old 04-06-2010
Hi Grandios,

what the "passwd" here stands for ???

I suspect you should use "/etc/passwd".
# 5  
Old 04-06-2010
oh yha, i put the etc, its just my previous code. i put etc/passwd but still not giving me the result i want
# 6  
Old 04-06-2010
There are many variable you are using in the script like :SysAcct , Special2 and not sure what these variables holding and difficult guess what went wrong.

and the path should be : /etc/passwd and not etc/passwd
# 7  
Old 04-06-2010
those variable are used to detect whether the myUser are included in system account or not. if not then they will print thr home directory etc. the problem is, i dont know how to get the account from myUSER to userid (own created variable rather than built in)
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

URGENT Reading a file and assessing the syntax shell script URGENT

I am trying to write a shell script which takes an input file as an arguement in the terminal e.g. bash shellscriptname.sh input.txt. I would like for the file to be read line by line each time checking if the .txt file contains certain words or letters(validating the syntax). If the line being... (1 Reply)
Discussion started by: Gurdza32
1 Replies

2. Shell Programming and Scripting

UNIX: passing stuff to a shell function

I have users that print files to selected printers. Instead of creating one function for each printer I would like to have just one and passing the files to print as well as the wanted printer. The following code does not work, of course. I'm expecting that $1 is the list of files to be printed... (6 Replies)
Discussion started by: emare
6 Replies

3. Shell Programming and Scripting

Usage of #!/bin/sh vs #!/bin/bash shell scripts?

Some question about the usage of shell scripts: 1.) Are the commands of the base shell scripts a subset of bash commands? 2.) Assume I got a long, long script WITHOUT the first line. How can I find out if the script was originally designed für "sh" or "bash"? 3.) How can I check a given... (3 Replies)
Discussion started by: pstein
3 Replies

4. Cybersecurity

'Shell Shock' vulnerability in Bourne shell

A severe vulnerability was discovered in Bourne shell. Just google for: bash vulnerability ... for more details. (5 Replies)
Discussion started by: Cochise
5 Replies

5. Shell Programming and Scripting

Bourne shell & Korn shell

Could some one tell me the difference btw Bourne shell and the Kshell? Which is more flexible and reliable in terms of portability and efficiency. When i type the following command .. $ echo $SHELL yields me /bin/sh Does this tells me that I am in Bourne shell. If yes, how can i get... (6 Replies)
Discussion started by: bobby1015
6 Replies

6. Shell Programming and Scripting

How to activate Korn Shell functionnalities in Bourne Shell

Hi All I have writing a Korn Shell script to execute it on many of our servers. But some servers don't have Korn Shell installed, they use Borne Shell. Some operations like calculation don't work : cat ${file1} | tail -$((${num1}-${num2})) > ${file2} Is it possible to activate Korn Shell... (3 Replies)
Discussion started by: madmat
3 Replies

7. Shell Programming and Scripting

I need to understand the differences between the bash shell and the Bourne shell

I do not claim to be an expert, but I have done things with scripts that whole teams of folks have said can not be done. Of course they should have said we do not have the intestinal fortitude to git-r-done. I have been using UNIX actually HPUX since 1992. Unfortunately my old computer died and... (7 Replies)
Discussion started by: awk_sed_hello
7 Replies

8. Shell Programming and Scripting

Changing the Bash Scripts to Bourne Scripts:URGENT

Hi, I have to write a program to compute the checksums of files ./script.sh I wrote the program using bash and it took me forever since I am a beginner but it works very well. I'm getting so close to the deadline and I realised today that actually I have to use normal Bourne shell... (3 Replies)
Discussion started by: pgarg1989
3 Replies

9. UNIX for Dummies Questions & Answers

fuser: difference with bin/sh and bin/ksh shell script

Hi, I have a problem I don't understand with fuser. I launch a simple shell script mysleep.sh: I launch the command fuser -fu mysleep.sh but fuser doesn't return anything excepted: mysleep: Then I modify my script switching from #!/bin/sh to #!/bin/ksh I launch the command fuser -fu... (4 Replies)
Discussion started by: Peuj
4 Replies

10. Shell Programming and Scripting

shell script help: sorting, incrementing environment variables and stuff

First: me == noob. Whats a good resource for shell script info cause I'm having trouble finding good info. I'm writing a shell script to automate the setup of a flash 'page flip'. My current code is below. the page flip takes an xml file of format <content> <pages... (1 Reply)
Discussion started by: secoif
1 Replies
Login or Register to Ask a Question