2013-12-12 7 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

당신은 쿠키를 사용할 수 있습니다

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

-b(--cookie) 수단를 Cookies.txt, 에서 쿠키를 사용하고 -c(--cokie-jar) 수단를 Cookies.txt하기 위해 쿠키를 덤프합니다.

스크립트에 curl을 사용할 때 항상 두 옵션을 추가하여 세션을 유지할 수 있도록하십시오. 참고로

는 :

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 name=data을 사용하여 인증 사용자 이름과 암호를 전달하고 --cookie-jar <filename>을 사용하여 쿠키를 저장할 수 있습니다.