Downloading Java JDK through Script - linux

I have been using the following to download JDK 8u112 via a script.
wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/8u112-b15/jdk-8u112-linux-x64.tar.gz
Recently, it throws ERROR 404: Not found and when you go to the link, it shows the same text in Downloading Java JDK on Linux via wget is shown license page instead
I've also tried http://download.oracle.com/otn/java/jdk/8u112-b15/jdk-8u112-linux-x64.tar.gz but it throws 401 Authorization Error.
Is there a new work around on this?

It seems like the most recent version of jdk can be downloaded by wget but not the files in the archives.
As such, I'm using casper.js script to login to Oracle and to download.
Following is my script to download Japanese version of jdk8u121. The current script will only attempt to download but will fail on redirect. I'm using download.sh bash script to scan the log to get the url with session parameter and using wget to do the actual download.
You'll need to replace <username> and <password> with valid ones to login to Oracle site.
Change values of jdkTag and jdkFileLink to get the jdk version you want to download.
oraclejdk.js
var casper = require('casper').create({
verbose: true,
logLevel: 'info', // debug
pageSettings: {
userAgent: "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36",
loadImages: false,
loadPlugins: false
}
});
// login info
var loginUrl='http://www.oracle.com/webapps/redirect/signon?nexturl=https://www.oracle.com/technetwork/java/javase/downloads/java-archive-javase8-2177648.html';
var username='<username>';
var password='<password>';
// accept license page info
var jdkUrl='http://www.oracle.com/technetwork/';
var jdkTag='jdk-8u121-oth-JPR';
// download jdk info
var jdkFileLink='jdk-8u121-oth-JPRXXXjdk-8u121-linux-x64.tar.gz';
// open login page
casper.start(loginUrl);
casper.thenEvaluate(function(username, password) {
// this.capture('loginPage.png', {top:0, left:0, width:600, height:800});
document.querySelector("#sso_username").value = username;
document.querySelector("#ssopassword").value = password;
doLogin(document.LoginForm);
}, {
username: username,
password: password
});
// login to oracle site
casper.then(function() {
this.waitForUrl(jdkUrl, function() {
// this.capture('jdkPage.png', {top:0, left:0, width:1200, height:800});
this.evaluate(function(jdkTag) {
disableDownloadAnchors(document, false, jdkTag);
hideAgreementDiv(document, jdkTag);
writeSessionCookie('oraclelicense', 'accept-securebackup-cookie');
}, {
jdkTag: jdkTag
});
}, null, null, 5000);
});
// accept license
casper.then(function() {
this.waitFor(function checkLink() {
return this.evaluate(function(jdkTag) {
return (document.getElementById('agreementDiv' + jdkTag).getAttribute('style') === 'visibility: hidden;');
}, {
jdkTag: jdkTag
});
}, function then() {
// this.capture('acceptedLicense.png', {top:0, left:0, width:1200, height:800});
downlink = this.evaluate(function(jdkFileLink) {
var jdkElement = document.getElementById(jdkFileLink);
if (jdkElement) {
var jdkLink = jdkElement.getAttribute("href");
jdkElement.click();
return jdkLink;
}
}, {
jdkFileLink: jdkFileLink
});
}, null, 5000);
});
casper.run();
download.sh
#!/bin/bash
url=$(casperjs --web-security=no oraclejdk.js |grep "http://download.oracle.com/otn/java/jdk" $() | sed -e 's/^.*: //')
jdk=$(echo "${url}" | sed -e 's/^.*jdk-/jdk/' |sed -e 's/?.*//')
wget -O "${jdk}" "${url}"

This is not a direct answer to your question...but Here is how i get URL to latest jdk download URL
#!/bin/bash
jdkwebinstallerDownloadPage="https://www.oracle.com"$(curl -s https://www.oracle.com/technetwork/java/javase/downloads/index.html | unix2dos | grep "<a name=\"JDK8\"" | sed 's/^.*\<a name=\"JDK8\" href=//g' | sed -r 's/>.*//g' | sed s/\"//g)
## Above yields https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
jdkinstallerDownloadURL=$(curl -s $jdkwebinstallerDownloadPage | grep windows | grep downloads | grep x64 | grep jdk | grep -v demos | sed -r 's/^.*https/https/g' | sed -r 's/\".*//g')
## yields https://download.oracle.com/otn/java/jdk/8u221-b11/230deb18db3e4014bb8e3e8324f81b43/jdk-8u221-windows-x64.exe
I am now looking to how to download from this url using wget...given that i have cedentials to login into oracle's login webpage which is https://login.oracle.com/mysso/signon.jsp

Related

How to get a list of subfolders and files in jfrog Artifactory

I am looking to fetch the subfolders and files inside jfrog artifactory repo and for that I am running the below script which I am running in Groovy
def test = sh(script: "curl -u uname:password -X POST -k https://artifactory.xxxx.com/artifactory/api/search/aql -d 'items.find({\"type\" : \"file\",\"\$or\":[{\"repo\" : {\"\$match\" : \"war*\"}, \"repo\" : {\"\$match\" : \"web*\"} }]}).include(\"name\",\"repo\",\"path\",\"size\").sort({\"\$desc\": [\"size\"]}).limit(10)'", returnStdout: true).trim()
echo "The list is ${test}"
But its not returning any value.
Any solution would be helpful.
Thanks
You can use api/storage get the children of a artifact path.
For example, your Artifactory has repository: maven-prerelease-local for maven, you can open
https://artifactory.xxxx.com/maven-prerelease-local in browser, it will list file and folders under it.
By adding api/storage in URL, it will return a JSON response.
def test = sh(script: """
curl -u uname:password -X GET -k \
"https://artifactory.xxxx.com/api/storage/maven-prerelease-local/com/xxx/xxx/"
""", returnStdout: true).trim()
echo "The list is ${test}"
To get detailed information about the existing subfolders under a specific directory/repository, you can use the following format of execution.
$ jfrog rt search --spec=test.aql
[Info] Searching artifacts...
[Info] Found 1 artifact.
[
{
"path": "delta-generic-local/alpha/beta",
"type": "folder",
"created": "2022-08-04T13:53:36.173Z",
"modified": "2022-08-04T13:53:36.173Z"
}
]
& the spec file includes the following content.
$ cat test.aql
{
"files":
[
{
"aql":
{
"items.find" :
{
"type":"folder",
"repo":{"$eq":"delta-generic-local"},
"path":{"$eq":"alpha"}
}
}
}
]
}
I am guessing you are in escape special character hell. Put your query in a *.aql file and then point to it. See below.
// Create the aql file and write the query to it
writeFile file: 'sizeQuery.aql', text: 'items.find({"type":"file"}).sort({"$desc":["size"]}).limit(10)'
// Pass the aql file to your curl command
sh 'curl -u uname:password -H "Content-Type: text/plain" -X POST -d #sizeQuery.aql "https://artifactory.xxxx.com/artifactory/api/search/aql"'

"local: not in a function"

We want to send information to the channel in Mattermost, but I get this error in the script.
#!/bin/bash
#start
matterSend() {
# Lowercase variable names; declare them local
local endpoint=https://mattermost.ltd/hooks/hash..
local username=$USER
# Pro tip: don't use a variable for the payload if it's effectively static
payload=$(cat <<-__EOF
payload={
"username" : "$username",
"channel" : "Genel_Log",
"text" : "#### ---\\n| Yedekeleme | Drive Gönderim | İşlem *** |\\n|:-----------|:-----------:|-----------------------------------------------:|\\n| ${2} | ${3} | ${1} :white_check_mark: |\\n"
}
__EOF
)
echo "CURL: curl -i -X POST -d $payload $endpoint"
curl -i -X POST -d "$payload" "$endpoint"
}
STRING="Starting.."
matterSend
Result:
fileName.sh: 5: local: not in a function
What is the reason?

Passing variables to curl command in child_process.exec fails

I was trying to use child_process.exec to call curl with a long command in order to send some data to an API. Something similar to the following example:
exec('git log --oneline | wc -l', function(error, stdin, stderr) {
if (stdin > 1) {
exec('curl -H "Content-Type: application/json" -X POST -d \'{"value1": "\'"$arg"\'"}\' https://https://maker.ifttt.com/trigger/{event}/with/key/<my-key>', { "env" : {"arg": stdin } });
}
})
So if a git repo includes more than one line in its git log output, then you execute a POST request to some API (here, a simple webhook in ifttt.com), in which you're passing some variable (arg) in the process.
Notice that this is the best attempt, but in general, I was struggling quite a bit to escape single and double quotes. In this particular case, the HTTP request was not sent correctly because the body includes a line break:
POST / HTTP/1.1
Host: <some-host>
User-Agent: curl/7.50.1
Accept: */*
Content-Type: application/json
Content-Length: 16
{"value1": "2
"}
At the end, I had to use an external bash script:
exec('./send_request.sh $arg', { "env": {"arg": stdin } });
but I'm still very curious on how to make it work within the same js file.
If it helps, I'm running node 6.11.0 and curl 7.52.1.
Try:
exec('git log --oneline | wc -l', function(error, stdin, stderr) {
if (stdin > 1) {
exec('curl -H "Content-Type: application/json" -X POST -d \'{"value1": "\'"$arg"\'"}\' https://https://maker.ifttt.com/trigger/{event}/with/key/<my-key>', { "env" : {"arg": stdin.replace(/\n/g, '') } });
}
})
What is happening is that your variable 'stdin' (you should rename it to 'stdout') has a \n at the end of it.

Error 403 when trying to connect to websocket api

I currently develop a realtime kik connector for the unification engine.To receive the messages, I connect to the websocket endpoint using my users name and password.Sadly, I get an error 403 everytime.Is there anything else I have to look out for?
Some examples:
$ curl -XPOST https://apiv2.unificationengine.com/v2/connection/list -u $USER_NAME:$PASSWORD --data "{}" -k -s | jq
{
"status": 200,
"info": "200 OK",
"connections": {
"kik": {
"uri": "kik://kik_user#kik.com"
}
}
}
Websocket:
$ wscat --auth "$USER_NAME:$PASSWORD" -c wss://apiv2.unificationengine.com/v2/ws/start
error: Error: unexpected server response (403)
Are you using this library?
https://github.com/websockets/wscat
Does this library support authentication in this way?
wscat --auth "$USER_NAME:$PASSWORD" -c wss://apiv2.unificationengine.com/v2/ws/start
Done research on this, wscat is using npm ws, https://github.com/websockets/ws for webscoket connection.
Can you try header like this and check
var ws = new WebSocket('wss://apiv2.unificationengine.com/v2/ws/start', {
origin: 'https://apiv2.unificationengine.com',
headers: { Authorization: 'base64 auth' }
});
You can create base64 auth like this in nodejs
var auth = "Basic " + new Buffer(USER_ACCESS_KEY + ":" + USER_ACCESS_SECRET).toString("base64");

Unable to execute "hive -e 'select * from table" using .exec() method of simple-ssh npm module

I am unable to execute a hive -e command using simple-ssh module .exec() in nodejs.
I think there is a problem with the single/double quotes ' or ". I don't know which quote to put in what sequence. I tried a lot of combination, but none of them worked.
Here is the code below:
var runSSH(obj){
var ssh = new SSH({
host: remote1,
user: 'root',
timeout: 1500000,
key: require('fs').readFileSync("C:/Users/Aiman/Desktop/hRep_prv"),
agent: process.env.SSH_AUTH_SOCK,
agentForward: true
});
ssh.exec('timeout 900 ssh -i /root/rsaPrvtKeyPath/to/remoteHost2 '+remoteHost2+' \'for i in '+remote3+' '+remote4+'; do clush -w ${i} "hive -e \'select * from table_name limit 3;\'" done\' ',{
out: function(stdout) {
devHive_check += stdout;
obj.devHive_check = devHive_check;
console.log(stdout);
}
}) //-->not executing
.exec('timeout 300 ssh -i /root/rsaPrvtKeyPath/to/remoteHost2 '+remoteHost2+' \'for i in '+remote3+' '+remote4+'; do clush -w ${i} "ps -ef | grep HiveServer2"; done;\' ',{
out: function(stdout) {
devHS2_check += stdout;
obj.devHS2_check = devHS2_check;
console.log(stdout);
}
})//-->running fine
.exec('echo "parse and save"',{
out: function(){
parseData(obj);
ssh.end();
}
}).start(); //-->running fine
}
I am logging into remoteHost1, running a couple of shell scripts (which are runnig fine), then I am doing an ssh to remoteHost2 to check Hive (hive is running on remote3 and remote4).
HiveServer2 is running fine, but Hive isn't.
Please help me.
Its solved now.
Instead of the single quotes inside hive, it requires a doulbe quotes, i.e. instead line ssh.exec('timeout 900 ssh -i /root/rsaPrvtKeyPath/to/remoteHost2 '+remoteHost2+' \'for i in '+remote3+' '+remote4+'; do clush -w ${i} "hive -e \'select * from table_name limit 3;\'" done\' ',{
I did
ssh.exec('timeout 900 ssh -i /root/rsaPrvtKeyPath/to/remoteHost2 '+remoteHost2+' \'for i in '+remote3+' '+remote4+'; do clush -w ${i} "hive -e \\\"select * from table_name limit 3;\\\" " done\' ',{, and it worked.
Thanks #mscdex for your support.

Resources