需要bash脚本行,才能使用curl/wget或类似工具每天使用cron登录WordPress

需要bash脚本行,才能使用curl/wget或类似工具每天使用cron登录WordPress,wordpress,bash,curl,post,wget,Wordpress,Bash,Curl,Post,Wget,我有一个端点URL,需要每天点击它来执行API调用。它需要登录。我似乎无法获得将成功登录的cURL或wget命令。我已尝试此cURL命令: /usr/bin/curl -L --silent --data "log=login&pwd=password&ag_login_accept=1&ag_type=login" https://www.the-url.com 2>&1 | /usr/bin/mail -s "subject" email@doma

我有一个端点URL,需要每天点击它来执行API调用。它需要登录。我似乎无法获得将成功登录的cURL或wget命令。我已尝试此cURL命令:

/usr/bin/curl -L --silent --data 
"log=login&pwd=password&ag_login_accept=1&ag_type=login" 
https://www.the-url.com 2>&1 | /usr/bin/mail -s "subject" 
email@domain.com
但是输出是登录页面的html,而不是手动登录然后转到url时得到的api输出

我还尝试了wget:

wget --save-cookies ~/sites/scripts/cookies.txt --keep-session-cookies 
--post-data="log=login&pwd=password&ag_login_accept=1&ag_type=login" \ 
"https://www.the-url.com"

同样的结果。

我做这种事情:

#!/bin/bash

WPUSR=user_name_goes_here
WPPWD=password_goes_here

COOKIEFILE=`mktemp`
COPT="--load-cookies $COOKIEFILE --save-cookies $COOKIEFILE --keep-session-cookies"
WGET="wget -nv -q ${COPT}"
MSG=`which banner || which figlet || which echo`

function printout() {
    links -dump ${1} | grep -v "^ *$" | grep -A 10 "Skip to content"
    }

function message() {
    $MSG "$1"
    }

# login
message 'Login'
    LOGIN="log=${WPUSR}${LOGIN}&pwd=${WPPWD}"
    LOGIN="${LOGIN}&redirect_to=http://127.0.0.1/wp/?p=1"
    ${WGET} -O page_01.html --post-data="${LOGIN}" 'http://127.0.0.1/wp/wp-login.php'
    printout page_01.html

# show post
message 'View Post'
    ${WGET} -O page_02.html 'http://127.0.0.1/wp/?p=2'
    printout page_02.html

rm "${COOKIEFILE}"
输出:

| |    ___   __ _(_)_ __  
| |   / _ \ / _` | | '_ \ 
| |__| (_) | (_| | | | | |
|_____\___/ \__, |_|_| |_|
            |___/         
   Skip to content
   Sitename
   Sitename
   Just another WordPress site
   Posted on 2018-04-11 by jmullee
                                  Hello world!
   Welcome to WordPress. This is your first post. Edit or delete it, then
   start writing!
One Reply to “Hello world!”
    1. A WordPress Commenter says:
       2018-04-11 at 16:05
__     ___                 ____           _   
\ \   / (_) _____      __ |  _ \ ___  ___| |_ 
 \ \ / /| |/ _ \ \ /\ / / | |_) / _ \/ __| __|
  \ V / | |  __/\ V  V /  |  __/ (_) \__ \ |_ 
   \_/  |_|\___| \_/\_/   |_|   \___/|___/\__|

   Skip to content
   Sitename
   Sitename
   Just another WordPress site
                                  Sample Page
   This is an example page. It’s different from a blog post because it will
   stay in one place and will show up in your site navigation (in most
   themes). Most people start with an About page that introduces them to
   potential site visitors. It might say something like this:
     Hi there! I’m a bike messenger by day, aspiring actor by night, and this
     is my website. I live in Los Angeles, have a great dog named Jack, and I

另一种建议是,从php bash脚本连接到ssh:

需要额外的php包:php-ssh2

sudo apt安装php-ssh2

#/usr/bin/php

您需要执行两个请求,一个用于登录,另一个用于获取所需内容。您还需要将cookie保存在一个文件中,以便两个请求可以共享它们。我从中尝试了一个php脚本,它可能会工作……如果它能工作,我可以用这个来回答我的问题。
#!/usr/bin/php
<?php
$connect = ssh2_connect('20.32.66.66.xx', 22);
ssh2_auth_password($connect, 'root', 'PtrDHfutyxxx');
$shell = ssh2_shell($connect, 'xterm');
$stream = ssh2_exec($connect, 'ls -a'); // Example command execute ls
stream_set_blocking($stream, true);
$stream_out = ssh2_fetch_stream($stream, SSH2_STREAM_STDIO);
echo stream_get_contents($stream_out); // Output command result
// ...