473,791 Members | 2,816 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

CGI script input

11 New Member
hi
i HAVE WRITTEN A perl script that will search a file and print output I have created a simple html doc i want to be able to click a link and it will print the output in of a specific file so i need the perl script to read a file 1-15 depending on the input from the html

Expand|Select|Wrap|Line Numbers
  1. #!c:\perl\bin\perl.exe
  2.  
  3. use warnings;
  4. use strict;
  5.  
  6. print <<HTTPHDR;
  7. Content-type: text/html
  8.  
  9. HTTPHDR
  10.  
  11. print <<HEADER;
  12. <HTML>
  13. <HEAD>
  14. <TITLE>NAS Disk</TITLE>
  15. </HEAD>
  16. HEADER
  17.  
  18. #print <<OPENBODY;
  19. #<BODY><H2>Nas Disk capacity</H2>
  20. #<PRE>
  21. #OPENBODY
  22.  
  23. my $data_file = 'nas02.txt';####there is fifteen of these 
  24.  
  25. open DATA, "$data_file" or die "can't open $data_file $!";
  26. my @read_data = <DATA>;
  27. my @array_of_data = map { SpecialChars($_); } @read_data;
  28. close DATA;
  29.  
it would be great if some one could tell me what to search for in google so i click on a link 1 to 15 and the perl script has to know what file to read 1 to15 depending on input from html
Aug 28 '07 #1
3 1724
numberwhun
3,509 Recognized Expert Moderator Specialist
First, always put your code in code tags. It neatens things up and makes it so our wonderful moderators don't have to clean up behind you.

Second, you REALLY need to use punctuation. This isn't text messaging and it would really make your post much clearer.

Speaking of clearer, can you possibly re-word your request for help? At this time I (and possibly others) have absolutely no idea exactly what you are asking for.

Please repost with a better, clearer explanation.

Regards,

Jeff
Aug 28 '07 #2
KevinADC
4,059 Recognized Expert Specialist
Use the CGI module to get the input from the form and plug it into a variable:


use CGI qw/:standard/;

my $input_file = param('file_num ');

where 'file_num' is the name of the form field that sends the number (1-15) to your script.
Aug 28 '07 #3
markoj
11 New Member
Hi folks back again this is the first time i have written a script of any description and I think my difficulty is not understanding some of the answers and cannot use them correctly
1. I have a html page with 15 links each link is linked to one perl script
2. Each link corresponds to a server.
3. When I click on a link I have it directly linked to my perl script
4.so my perl script needs to know what log file to open and read depending on what link I click this is what i cannot get done. how do i do this
5. The nas01.txt is the log file and there are 15 of these
6. Do i put the path of all 15 log files into an array and then use an if statement i.e. if this link is clicked do this or is it something simpler

Any help would be appreciated

Here is my code so far

Expand|Select|Wrap|Line Numbers
  1. #!c:\perl\bin\perl.exe
  2.  
  3. use warnings;
  4. use strict;
  5. use CGI qw/:standard/;
  6.  
  7.  
  8. print <<HTTPHDR;
  9. Content-type: text/html
  10. HTTPHDR
  11. print <<HEADER;
  12. <HTML>
  13. <HEAD>
  14. <TITLE>NAS Disk</TITLE>
  15. </HEAD>
  16. HEADER
  17.  
  18. my $data_file = "nas01.txt";
  19.  
  20. open DATA, "$data_file" or die "can't open $data_file $!";
  21. my @read_data = <DATA>;
  22. my @array_of_data = map { SpecialChars($_); } @read_data;
  23. close DATA;
  24.  
  25.  
  26.  
  27. foreach my $line ( @array_of_data ) {
  28.     if ($line =~ m/levels/i) {
  29.         print "$line\n\n\n";
  30.  
  31.     } elsif ($line =~ m/date/i) {
  32.         print "$line\n\n\n";
  33.  
  34.     } elsif ($line =~ m/hostname/i) {
  35.         print "$line\n\n\n";
  36.  
  37.     } elsif ($line =~ m/uptime/i) {
  38.         print "$line\n\n\n";
  39.     }
  40. }
  41.  
  42. print "========================================================================================================<br>\n";
  43.  
  44.  
  45. print "</PRE>\n";
  46.  
  47. print "<TABLE border=1>\n";
  48. my $disk = 0;
  49. foreach my $lines ( @array_of_data ) {
  50.     if ($lines =~ m/(\d+)[%]/i) {
  51.     my $val = $1;
  52.     if ($val > 80) {
  53.     $disk++;
  54.     print <<DISK;
  55. <tr style="color: red"><td><PRE>$lines</PRE></td><th>Please look at this disk immediately.</TH></TR>
  56. DISK
  57.  
  58.         } else {
  59.             print <<OKDISK;
  60. <tr style="color: indigo"><td><PRE>$lines</PRE></td><th>Disk levels are ok.</th></tr>
  61. OKDISK
  62.         }
  63.     }
  64. }
  65.  
  66. if ($disk == 0) { print <<ALLDISKOK; <TR style="color:
  67.     green"><TH colspan=2>Disk levels are ok.</th>
  68.     </tr> ALLDISKOK } print "</TABLE>\n";
  69.  
  70. print <<HTMLFOOT;
  71. </BODY>
  72. </HTML>
  73. HTMLFOOT
  74.  
  75. # Remove special chars from input
  76. sub SpecialChars($) {
  77. my ($line) = @_;
  78.     $line =~ s/&/&amp;/sg;     
  79.     $line =~ s/</&lt;/sg;
  80.     $line =~ s/>/&gt;/sg;
  81.     return($line);
  82. }
  83.  
  84.  
Aug 31 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
7478
by: Wayne Deleersnyder | last post by:
Hi, I'm a newbie at Perl and CGI and hoping someone can point me in the right direction. Recently I've been going through an older book I have on CGI programming to get a start. Most of it involves using Perl 5 though. The book is "Sams Teach Yourself CGI Programming In A Week", by Rafe Colburn. Until recently, things were going smoothly. Then, depending on the script that I'd copy from the book, I'd start getting "Premature end of...
1
8731
by: Les Juby | last post by:
A year or two back I needed a search script to scan thru HTML files on a client site. Usual sorta thing. A quick search turned up a neat script that provided great search results. It was fast, returned the hyperlinked page title, filename, and the body txt (30 preceding and following words) in context with the search word highlighted. Excellent.! See it working at: http://www.ipt.co.za Just search for "firearm"
6
2027
by: Rtritell | last post by:
Please can you find out what's wrong, fix the script and tell me what was wrong. Im just beginning <html> <head> <title>Random Mad Lib!</title> <script language="JavaScript"> <!-- Hide
5
1665
by: zaw | last post by:
Hi I am working on implementing this script to shopping cart. Basically, it copies fill the shipping address from billing automatically. I believe one or more syntax is not netscape compatible. Can anyone point out which one it is and how to make it both netscape and MS browser compatible? I hope if I can make the script compatible for those two at extreme, it will probably work with most browser out there. As you would notice, this form...
1
2913
by: Dan | last post by:
This is one that has me stumped and I need an expert's input. Any ideas why the values from the second script-generated drop down list isn't recognized by the script to add time values to the text boxes? What this script is suppose to do is change the value of a second drop down list based on the selection from the first. Then a value is chosen from the script generated drop down list in the
2
3116
by: Muzzy | last post by:
Hi, I've used information on these newsgroups to build many pages. So I thought that now that I have my script working (something that I've been working on for about a week), I should post it so that it may help others. If posting this script is against the rules in this group then please accept my appologies. I developped this script so that I can add and remove rows in a table in which I have various input fields and I would use the...
24
7734
by: owz2008 | last post by:
This has probably been covered before but could not find a similar thread. Basically I have created a form which can be viewed at www.icomworks.co.uk/canvaspayform.html I want to submit the form along with the file so that they are both placed on my server... I have created a folder on my server in my public_html called myscripts and have saved my upload.cgi script into that folder. my form points to that script but when I fill in the...
82
10071
by: happyse27 | last post by:
Hi All, I modified the user registration script, but not sure how to make it check for each variable in terms of preventing junk registration and invalid characters? Two codes below : a) html b) perl script (print and inserting into database) Cheers... Andrew
7
16170
by: jeddiki | last post by:
Hi, As I am in Turkey at present, I can not see vidoes on youtube. So I have tried a few proxies but keep finding them slow or not working. So I have installed myphpProxy on my server under the domain name www.blog-start.com Unfortuantely it is not not working correctly
11
2604
by: sshade25 | last post by:
I am trying to insert some data into my postgresql database table using an html form and a php script. The problem here is that when the script is run, it does not insert data into the last two coulmns and also it would insert a 0 into the third column. but when i run the query directly on the database using this sql INSERT INTO crops (crop_id,crop_type,crop_name,cultivation_yrs, local_name)VALUES('6','food crop','garri','6','utara'); ...
0
9669
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9515
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10426
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10154
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9029
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5430
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5558
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4109
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2913
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.