?
Solved

quick script (important)

Posted on 2000-02-20
6
Medium Priority
?
197 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 400 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
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
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

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

Introduction This tutorial will give you a fast look what you can do with WhizBase. I expect you already know how to work with HTML at least, and that you understand the basics of the internet and how the internet works. WhizBase is a server-s…
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
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…
Suggested Courses

771 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