UNIX CGI script


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers UNIX CGI script
# 1  
Old 11-08-2001
Question UNIX CGI script

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 Smilie )
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

Thanks!
primal

p.s. if you would like to see what i mean go to http://hal.humberc.on.ca/~crrd0120/ login name: crrd0120
# 2  
Old 11-09-2001
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  
Old 11-10-2001
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  
Old 11-10-2001
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 Smilie
primal
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Perl cgi pages out of cgi-bin folder in WINDOWS

Hi team, I have a typical problem with cgi pages in apache webserver in WINDOWS I am able to execute(display) the pages that are saved in cgi-bin folder. But I am not able to execute the pages stored in htdocs or other folder other than cgi-bin folder. Could anyone please let me know how... (1 Reply)
Discussion started by: scriptscript
1 Replies

2. Programming

CGI Perl script to execute bash script- unable to create folder

Hi I have a bash script which takes parameters sh /tmp/gdg.sh -b BASE-NAME -n 1 -s /source/data -p /dest/data/archive -m ARC gdg.sh will scan the /source/data and will move the contents to /dest/data/archive after passing through some filters. Its working superb from bash I have... (0 Replies)
Discussion started by: rakeshkumar
0 Replies

3. Web Development

problem with exporting vairable from one perl cgi to another perl cgi script while redirecting.

Can anyone tell me how to export a variable from one perl CGI script to another perl cgi script when using a redirect. Upon running the login.pl the user is prompted to enter user name and password. Upon entering the correct credentials (admin/admin) the user is redirected to welcome page. My... (3 Replies)
Discussion started by: Arun_Linux
3 Replies

4. Shell Programming and Scripting

Execution problem unix commands in Perl CGI

I am trying to run SSH , mkdir and other unix commands using Perl CGI. But i am not able to Execute these commands. Please help me out !!!! SSH and mkdir is necessity for me. I will be thankful to you...!!!!! I am trying like: In perl CGI file i am writing like: @list = `ssh... (28 Replies)
Discussion started by: Navrattan Bansa
28 Replies

5. Web Development

cgi script and external UNIX commands (like swadm)

Hi, I am trying to implement a server monitoring dashboard using cgi scripting. I am planning to run the necessary unix scripts from the web page using cgi. This method works fine for standard unix commands but I am unable to run some external unix commands (like swadm show_processes, swadm... (9 Replies)
Discussion started by: jofinjoseph
9 Replies

6. UNIX Desktop Questions & Answers

CGI execution problem on Unix

Hello everyone, I have developed a cgi application on windows. i have created a folder in webapps of tomcat, within that a WEB-INF folder and in that cgi folder. This cgi folder contains one executable. The web.xml is as follows: <servlet> <servlet-name>cgi</servlet-name> ... (2 Replies)
Discussion started by: Preeti_t
2 Replies

7. UNIX for Dummies Questions & Answers

How to share CGI Scripts across UNIX web server?

Hi, is it possible to create a CGI folder somewhere on the server and allow all domains on that server be able to access the scripts? I tried a ScriptAlias addition in httpd.conf but still no luck. Would greatly appreciate any tips! Thanks. Linux version 2.4.20-021stab028.3.777-enterprise Plesk... (5 Replies)
Discussion started by: karlsworld
5 Replies

8. Shell Programming and Scripting

How to share CGI Scripts across UNIX web server?

Hi, is it possible to create a CGI folder somewhere on the server and allow all domains on that server be able to access the scripts? I tried a ScriptAlias addition in httpd.conf but still no luck. Would greatly appreciate any tips! Thanks. Linux version 2.4.20-021stab028.3.777-enterprise Plesk... (1 Reply)
Discussion started by: karlsworld
1 Replies

9. Shell Programming and Scripting

CGI passing arrays/hashes to another CGI script

If I have a Perl CGI script (script01), which fills an array(s) with information and outputs a HTML page with a link to another CGI page (script02); is there anyway to pass the array(s) from "script01" to "script02" when the page visitor clicks the link? Hope that makes sense! :) (2 Replies)
Discussion started by: WIntellect
2 Replies

10. UNIX for Dummies Questions & Answers

HTML-CGI on Unix

AAAHHH!! I've made a perl program that you can run on a web browser. This program needs to be run everyday, and I don't want to have to run it everyday. The problem is when I try running the program from my terminal, all it does is print stuff to the terminal page (the program involves a lot of... (4 Replies)
Discussion started by: sstevens
4 Replies
Login or Register to Ask a Question