suggestions for writing automation script

Please support our Perl advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Feb 2008
Posts: 33
Reputation: klactose is an unknown quantity at this point 
Solved Threads: 1
klactose klactose is offline Offline
Light Poster

suggestions for writing automation script

 
0
  #1
Nov 9th, 2009
Hello,

I have created a simple webservice and I am now in the testing mode. I am trying to write a simple script that will use curl to create user accounts and another one to delete user accounts.

I have tried to use system to send curl commands
  1. my $cmd = "c:\\curl\\curl -X PUT -d \"user[email]=email$_\" "
  2. + "-d \"user[password]=pass$_\" "
  3. + "http://localhost:3000/site/users/user$_";
  4. print "create user failed\n" if system($cmd);

I've also tried using backtick
  1. $userResponses[$_] =
  2. `c:\\curl\\curl -u user$_ -X DELETE http://localhost:3000/site/users/user$_`;

BTW, I have been using curl to manually test the service because it supports all of the HTTP methods instead of just GET and POST.

Anyway, the problem I am running into is that I can't figure out a way to interact with curl to provide the required password after sending a command that requires authorization. Is there a way to do this?

Any help would be greatly appreciated. I am open to suggestions, including ones that that don't depend on curl.

Thanks!
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 52
Reputation: d5e5 is an unknown quantity at this point 
Solved Threads: 7
d5e5's Avatar
d5e5 d5e5 is offline Offline
Junior Poster in Training
 
0
  #2
Nov 9th, 2009
In case it makes a difference, is your platform *nix, Windows or Mac?

I don't know much about http or curl but before using the system command make sure the $cmd variable has been built successfully. You may want to use Perl's quote operator qq().
  1. #!/usr/bin/perl -w
  2. use strict;
  3. my $cmd = "c:\\curl\\curl -X PUT -d \"user[email]=email$_\" "
  4. + "-d \"user[password]=pass$_\" "
  5. + "http://localhost:3000/site/users/user$_";
  6. #For now, comment out the system command and see if $cmd contains correct string value
  7. ##print "create user failed\n" if system($cmd);
  8. print $cmd;
Running the above gives a lot of error messages.
  1. C:\Users\David\Programming\Perl>test.pl
  2. Use of uninitialized value $_ in concatenation (.) or string at C:\Users\David\P
  3. rogramming\Perl\test.pl line 3.
  4. Use of uninitialized value $_ in concatenation (.) or string at C:\Users\David\P
  5. rogramming\Perl\test.pl line 3.
  6. ...etc.......
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 33
Reputation: klactose is an unknown quantity at this point 
Solved Threads: 1
klactose klactose is offline Offline
Light Poster
 
0
  #3
Nov 9th, 2009
Hi thanks for the reply. Perhaps I should have added a bit more detail. I am running in a windows vista 64bit environment, and the code snippets I provided actually are statements in a loop (that's why you are getting uninitialized value errors if you try to run them on their own).

So if you are trying to duplicate what I am experiencing you need to wrap the snippits in a loop like
  1. for(0..n){
  2. <snippits go here>
  3. }
However, the code I provided wasn't intended to be run outside of my specific test environment, as there are a many environmental conditions that you would have to try to match as well, which isn't really practical.

My question is more conceptual than anything. I realize that to do what I want I need to somehow split the processes so that perl isn't waiting for curl to return, but not really sure how to do that. I'm going to read up on the perlfork and open functions, hopefully I'll find a solution in one of those.
Reply With Quote Quick reply to this message  
Reply

Tags
http, perl

Message:




Views: 723 | Replies: 2
Thread Tools Search this Thread



Tag cloud for http, perl
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC