Our Community is getting an upgrade! To get everything ready for the relaunch, we’ll be placing the site in read-only mode starting September 21st.
We really appreciate your understanding while we get things set up behind the scenes. Catch up on all the exciting details about the move here.
Need help or have questions? Drop us a line at [email protected]

Support Questions

Find answers, ask questions, and share your expertise
Announcements
Share your experience with Cloudera on G2 and get a $25 Amazon Gift card.
Hi, I'm CLEO! Something exciting is coming to the Community. Stay Tuned!

Curl command for CM login

avatar
Explorer

Hi Team ,

 

I trying to get information using curl command and seems CM Manager sending me login page. I  already using user name and password .

 

curl -X GET --user 'xxxx':'xxxx' https://CM URL:7183/cmf/serviceRedirect/schemaregistry/instances
<!-- __CLOUDERA__PRE__LOGIN__FORM__ -->

<!DOCTYPE html>
<html>
<head><meta charset="utf-8"></head>
<body></body>
</html>
<script type="text/javascript">
var returnUrl = window.location.pathname + window.location.search + window.location.hash;
var loginPageUrl = "/cmf/login";
if (returnUrl !== "/cmf" && returnUrl !== "/cmf/" && returnUrl !== "/cmf/home" && returnUrl !== "/cmf/home/") {
loginPageUrl = loginPageUrl + "?returnUrl=" + encodeURIComponent(returnUrl);
}
window.location = loginPageUrl;
</script>

 

 

pls some one help.

 

Thanks

1 ACCEPTED SOLUTION

avatar
New Member

Found a dirty workaround: generate a cookie from an API call and then use it to login into the console. As an example, in order to get the HDFS usage report,

 

#!/bin/bash -x

COOKIES=./cookies.txt
USER=""
PASS=""
LOGIN="https://<cloudera_manager>:7183/api/version"
REPORT="https://<cloudera_manager>:7183/cmf/services/11/nameservices/nameservice1/reports/currentDiskUsage?g...
"
SALIDA=./hdfs_usage.csv

function login_cloudera(){
        USER=$1
        PASS=$2
        wget --save-cookies ${COOKIES} --keep-session-cookies --user
"${USER}" --password "$(echo ${PASS}|base64 -d)" --delete-after
${LOGIN}
}

function download_report(){
        USER=$1
        read -p "Password:" -s PASS
        PASS=$(echo $PASS | base64)
        login_cloudera $USER $PASS
        wget --load-cookies ${COOKIES} ${REPORT} -O ${SALIDA}
        rm ${COOKIES}
}

# MAIN
USER=$1
download_report $USER

View solution in original post

4 REPLIES 4

avatar
Expert Contributor

Hello

 

One example

 

$ curl -X GET -u "admin:admin" -i http://cm-host:7180/api/v6/tools/echo?message=hello

 

  • The -X GET sends a GET request, which is the default and can be omitted. You would use PUT, POST and DELETE for other usage scenarios.
  • The -u "admin:admin" authenticates with CM using HTTP basic auth. admin:admin is the CM default user account.
  • The -i tells curl to include HTTP headers in the output, which is useful for debugging.

avatar
Explorer

getting below error 

 

<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
<title>Error 401 Bad credentials</title>
</head>
<body><h2>HTTP ERROR 401</h2>
<p>Problem accessing /api/v6/tools/echo. Reason:
<pre> Bad credentials</pre></p><hr><a href="http://eclipse.org/jetty">Powered by Jetty:// 9.4.14.v20181114</a><hr/>

</body>
</html>

avatar
Explorer

user name and url mark as xxx

curl -X GET --user 'xxxx':'xxxx' -i https://CMURL:7183/cmf/serviceRedirect/schemaregistry/instances
HTTP/1.1 200 Connection established

HTTP/1.1 200 OK
Date: Mon, 12 Apr 2021 06:47:14 GMT
Set-Cookie: CLOUDERA_MANAGER_SESSIONID=node0xzy9bnjzrx6x1s70qz8gu8w2713126907.node0;Path=/;Secure;HttpOnly
Expires: Thu, 01 Jan 1970 00:00:00 GMT
Content-Language: en-AU
Content-Type: text/html;charset=utf-8
Cache-Control: max-age=0, no-cache, no-store
Pragma: no-cache
Expires: Tue, 01 Jan 1980 1:00:00 GMT
X-UA-Compatible: IE=edge
Strict-Transport-Security: max-age=31536000 ; includeSubDomains
X-XSS-Protection: 1; mode=block
X-Frame-Options: SAMEORIGIN
X-Content-Type-Options: nosniff
Content-Length: 546
Server: Jetty(9.4.14.v20181114)

<!-- __CLOUDERA__PRE__LOGIN__FORM__ -->

<!DOCTYPE html>
<html>
<head><meta charset="utf-8"></head>
<body></body>
</html>
<script type="text/javascript">
var returnUrl = window.location.pathname + window.location.search + window.location.hash;
var loginPageUrl = "/cmf/login";
if (returnUrl !== "/cmf" && returnUrl !== "/cmf/" && returnUrl !== "/cmf/home" && returnUrl !== "/cmf/home/") {
loginPageUrl = loginPageUrl + "?returnUrl=" + encodeURIComponent(returnUrl);
}
window.location = loginPageUrl;
</script>

avatar
New Member

Found a dirty workaround: generate a cookie from an API call and then use it to login into the console. As an example, in order to get the HDFS usage report,

 

#!/bin/bash -x

COOKIES=./cookies.txt
USER=""
PASS=""
LOGIN="https://<cloudera_manager>:7183/api/version"
REPORT="https://<cloudera_manager>:7183/cmf/services/11/nameservices/nameservice1/reports/currentDiskUsage?g...
"
SALIDA=./hdfs_usage.csv

function login_cloudera(){
        USER=$1
        PASS=$2
        wget --save-cookies ${COOKIES} --keep-session-cookies --user
"${USER}" --password "$(echo ${PASS}|base64 -d)" --delete-after
${LOGIN}
}

function download_report(){
        USER=$1
        read -p "Password:" -s PASS
        PASS=$(echo $PASS | base64)
        login_cloudera $USER $PASS
        wget --load-cookies ${COOKIES} ${REPORT} -O ${SALIDA}
        rm ${COOKIES}
}

# MAIN
USER=$1
download_report $USER