![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Include PERL script with in the unix shell script | ganapati | UNIX for Dummies Questions & Answers | 1 | 04-29-2008 09:18 AM |
| help me in sending parameters from sqlplus script to unix shell script | Hara | Shell Programming and Scripting | 2 | 01-29-2008 12:31 PM |
| FTP script for sending a file from one unix directory to another unix server director | raja_1234 | Shell Programming and Scripting | 1 | 11-30-2006 04:57 AM |
| how to convert unix .ksh script to windows .batch script | 2.5lt V8 | Shell Programming and Scripting | 1 | 11-28-2006 09:52 AM |
| 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 07:43 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Hey everyone!
I hope someone here is good with Unix CGI scripts. I'm having trouble with my CGI. Here's the deal I've created a program that searches the passwd file and cuts the users real name when it's given the login name. When i converted it to CGI i ran into some problems: 1) when you put one login name in, it echo's a statement (user is online/offine) 6 times! BUT when you put 2 or more, there is no repeating. 2) i dont think $* works when doing for loop. i had to hard code up to 6 variables (could be more though) can anyone offer any help? I also ported this into an HTML version, but still have the same problems. (could have swore i had this working, but when i saved the HTML one, i over wrote the working one, and i forgot what changed i made I think it's my quotes but i'm not really sure anymore lol here's my code: Code:
#!/bin/sh
echo "Content-Type: text/plain"
echo ""
slice=`echo $QUERY_STRING|cut -d= -f2`
if [ "$slice" = "" ]; then
echo Please go back and enter a login name
fi
name1=`echo $slice|cut -d+ -f1`
name2=`echo $slice|cut -d+ -f2`
name3=`echo $slice|cut -d+ -f3`
name4=`echo $slice|cut -d+ -f4`
name5=`echo $slice|cut -d+ -f5`
name6=`echo $slice|cut -d+ -f6`
names="$name1 $name2 $name3 $name4 $name5 $name6"
for name in $names
do
who | grep $name > /dev/null
if [ $? = "0" ]; then
echo "Yes `grep "$name" /etc/passwd | cut -f5 -d:` is online"
else
echo "No `grep "$name" /etc/passwd | cut -f5 -d:` is offline"
fi
done
primal p.s. if you would like to see what i mean go to http://hal.humberc.on.ca/~crrd0120/ login name: crrd0120 |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
If you insert "set -x" just before your loop (or anywhere after the Content-type) you will get lots of debugging info about what is going on. That may help you find the problem.
|
|
#3
|
||||
|
||||
|
I went to the URL and it appears to be working fine. Have you already fixed it?
If not, I think it may be a combo of problems between the lines: name1=`echo $slice|cut -d+ -f1` name2=`echo $slice|cut -d+ -f2` name3=`echo $slice|cut -d+ -f3` name4=`echo $slice|cut -d+ -f4` name5=`echo $slice|cut -d+ -f5` name6=`echo $slice|cut -d+ -f6` and the $? = "0" I think if you are doing a cut -f6 but you did not feed it a 6th name, name6 will be set to nothing. When you do a who | grep > /dev/null, this may return 0 on some systems because it runs but does not produce output. I tried on Sun and actually got a return code of 2 plus a STDERR about the correct usage of grep. You could simply add a test to the loop that checks to see if $name != "". If it doesn't, then process the username, otherwise just exit because you know if name3 is blank, name4,5, and 6 are aswell. |
|
#4
|
|||
|
|||
|
Oh yea, i got it working eventually. Had to code in an if statement.
Having a little trouble with the HTML version, but I'm gonna try and work through it. if not... I'll be back for anyones help! thanks people primal |
|||
| Google The UNIX and Linux Forums |