Solved

quick script (important)

Posted on 2000-02-20
6
192 Views
Last Modified: 2013-12-25
Can someone please write me a script which will do the following:

Divide a variable $x by $y, if this value is smaller than $a divided by $b then return $Yes to the browser and if it is bigger then return the string "No" to the browser.

This will be run on a unix server and can this script please include code to have it be able to run only once at a time (i cant get flock() to work) and for it to return the string "Running" if it is already being run.

Thanks
0
Comment
Question by:wormboy__6
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 3

Accepted Solution

by:
monas earned 100 total points
ID: 2540398
use CGI;

$q = new CGI;

$x = $q->param('x');
$y = $q->param('y');
$a = $q->param('a');
$b = $q->param('b');

print $q->header;
$lock_dir = '/path/to/lock/directory/';

if (mkdir $lock_dir, 0600){
  # direcotry created - we can proceed
  eval {$d = ($x/$y) - ($a/$b);}
  if ($d <0){print "Yes";}
  else {print "No";}
  rmdir $lock_dir;

} else {
  # directory not created
  print "Running"
  ### you may add directory age checking here...
}
0
 

Author Comment

by:wormboy__6
ID: 2582625
ok, i have edited the code to this:

#!/usr/bin/perl
$Count = 10;
$CurrentTime = 100;
$Limit = 200;
$TotalTime = 500;
$lock_dir = 'Testings';
$d = mkdir $lock_dir, 0777;
if ($d = 1) {
  # direcotry created - we can proceed
  eval '$FirstRatio = ($Count/$CurrentTime)';
  eval '$MainRatio = ($Limit/$TotalTime)';
if ($FirstRatio < $MainRatio){print "Yes";}
  else {print "No";}
  rmdir $lock_dir;

} else {
  # directory not created
print "Running";
  ### you may add directory age checking here...
}

My problem however is that when i put this script onto a webserver (a free one with scripting) it does not work. I can not get it to create a directory. Can u change this to make it work? Is there permission problems or what?

Do i need that stuff at the start of your script? The $q and param stuff?

Also, if i create a directory on my computer named the same name as the locking directory, the script deletes the directory. Should it do this? I am using win98.

Thanks
0
 
LVL 3

Expert Comment

by:monas
ID: 2582642
re directory: if this directory is present - this shows that script is running. And every time you try to run script it first trys to create if it succeeds - it removes this dir when finished. Otherwise I can't say is this script already running.

In principle this "lock directory" shoul be missing when you start your script!

As for $q and param stuff. If that's not CGI script - you don't need them.  

If this IS cgi scipt and  you can live with hardcoded values - you don't need param stuff. Althoug I would recomend you very much to keep "$q= new CGI" and "print $q->header". These two lines will ensure that your script will produce correct headers required by CGI protocol.

As for not creating directory... I don't have computer with w98+perl - I can't check. But the only idea would be - try to write full path like "D:\\TEMP\\Locking" where you have directory creating permitions for sure.

Good Look!
0
The Orion Papers

Are you interested in becoming an AWS Certified Solutions Architect?

Discover a new interactive way of training for the exam.

 
LVL 84

Expert Comment

by:ozo
ID: 2582643
perl -Mdiagnostics -w
Found = in conditional, should be == at - line 8 (#1)
   
    (W) You said
   
        if ($foo = 123)
   
    when you meant
   
        if ($foo == 123)
   
    (or something like that).
0
 

Author Comment

by:wormboy__6
ID: 2584227
The script i wrote works on win98 with perl. How come it does not work on unix?

What do i need to change to make it work? (i think i may have the make directory line incorrect, please check)
0
 

Author Comment

by:wormboy__6
ID: 2585816
I have figured it out thanks to your help, cheers.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Making a simple AJAX shopping cart Couple years ago I made my first shopping cart, I used iframe and JavaScript, it was very good at that time, there were no sessions or AJAX, I used cookies on clients machine. Today we have more advanced techno…
In this tutorial I will show you how to make a simple HTML bar chart with the usage of WhizBase, If you want more information about WhizBase please read my previous articles at http://www.experts-exchange.com/ARTH_5123186.html (http://www.experts-ex…
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

729 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question