944,218 Members | Top Members by Rank

Ad:
  • Perl Discussion Thread
  • Unsolved
  • Views: 1718
  • Perl RSS
Nov 9th, 2009
0

suggestions for writing automation script

Expand Post »
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
perl Syntax (Toggle Plain Text)
  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
perl Syntax (Toggle Plain Text)
  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!
Similar Threads
Reputation Points: 10
Solved Threads: 1
Light Poster
klactose is offline Offline
43 posts
since Feb 2008
Nov 9th, 2009
0
Re: suggestions for writing automation script
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().
Perl Syntax (Toggle Plain Text)
  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.
text Syntax (Toggle Plain Text)
  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.......
Reputation Points: 153
Solved Threads: 142
Master Poster
d5e5 is offline Offline
740 posts
since Sep 2009
Nov 9th, 2009
0
Re: suggestions for writing automation script
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
perl Syntax (Toggle Plain Text)
  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.
Reputation Points: 10
Solved Threads: 1
Light Poster
klactose is offline Offline
43 posts
since Feb 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Perl Forum Timeline: variable concat and exec cmd question
Next Thread in Perl Forum Timeline: matching and replacing workaround





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC