| | |
suggestions for writing automation script
Please support our Perl advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Feb 2008
Posts: 33
Reputation:
Solved Threads: 1
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
I've also tried using backtick
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!
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)
my $cmd = "c:\\curl\\curl -X PUT -d \"user[email]=email$_\" " + "-d \"user[password]=pass$_\" " + "http://localhost:3000/site/users/user$_"; print "create user failed\n" if system($cmd);
I've also tried using backtick
perl Syntax (Toggle Plain Text)
$userResponses[$_] = `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!
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().
Running the above gives a lot of error messages.
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)
#!/usr/bin/perl -w use strict; my $cmd = "c:\\curl\\curl -X PUT -d \"user[email]=email$_\" " + "-d \"user[password]=pass$_\" " + "http://localhost:3000/site/users/user$_"; #For now, comment out the system command and see if $cmd contains correct string value ##print "create user failed\n" if system($cmd); print $cmd;
text Syntax (Toggle Plain Text)
C:\Users\David\Programming\Perl>test.pl Use of uninitialized value $_ in concatenation (.) or string at C:\Users\David\P rogramming\Perl\test.pl line 3. Use of uninitialized value $_ in concatenation (.) or string at C:\Users\David\P rogramming\Perl\test.pl line 3. ...etc.......
•
•
Join Date: Feb 2008
Posts: 33
Reputation:
Solved Threads: 1
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
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.
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)
for(0..n){ <snippits go here> }
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.
![]() |
Similar Threads
- Free Game Script (Game Development)
- Code Snippet: Need help writing a perl script to parse multiple files (Perl)
- writing a script for nagios checks... (Shell Scripting)
- Help required writing small script Python (Python)
- Unix shell access from Perl script (Perl)
- run program and rename file script help please (Shell Scripting)
- IP-to-Country converter (php script) (PHP)
- Shell Script Issue (Shell Scripting)
- Samba writing stall error; linux to linux transfer (*nix Software)
Other Threads in the Perl Forum
- Previous Thread: variable concat and exec cmd question
- Next Thread: matching and replacing workaround
| Thread Tools | Search this Thread |
Tag cloud for http, perl






