2013-12-12 190 views
1

我在cronjob上有一个bash脚本。cURL命令行登录(bash)

do 
curl -d "test=working" https:/mysite.com/test 
echo "done" 
done 

现在,它只是在我的网站上发布一个帖子请求。

但现在我想在一个成员只有区域POST请求2次

所以,我怎么能登录保持会话,并张贴2倍? 我不能测试这个,因为我在我的手机上一段时间,但它一直在窃听我。

do 
curl -d "uname=a&pass=b" https:/mysite.com/login 
for run in {1..2} 
do 
curl -d "test=working" https:/mysite.com/memberarea 
echo "done" 
done 

这项工作?

回答

2

可以使用的cookie:

curl -b cookies.txt -c cookies.txt -e website.com -d 'xx=yy' http://website.com/path/to/resource 

-b(--cookie)手段使用来自cookie.txt的, 饼干和-c(--cokie-jar)手段转储cookie来cookie.txt的。

因此,在脚本中使用curl时,请始终添加两个选项,以便您可以保持会话。

FYI:

do 
curl -b cookies.txt -c cookies.txt -e mysite.com -d "uname=a&pass=b" https:/mysite.com/login 
for run in {1..2} 
do 
curl -b cookies.txt -c cookies.txt -e mysite.com -d "test=working" https:/mysite.com/memberarea 
echo "done" 
done 
+0

这应该工作。谢谢。 – user2318029

1

如果您的网站使用cookie保存经过身份验证的会话,则可以使用--cookie name=data传递验证用户名和密码,并使用--cookie-jar <filename>来存储Cookie。