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
Solved

quick script (important)

Posted on 2000-02-20
6
179 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
  • 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Ever wondered how to display how many visitors you have online. In this tutorial I will show you an easy but effective way to display the number of online visitors in WhizBase. In this article I assume you have read my previous articles and know …
It is a general practice to get rid of old user profiles on a computer  in a LAN environment. As I have been working with a company in a LAN environment where users move from one place to some other place at times. This will make many user profil…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

840 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