hide's memo
19 Feb, 2022

Get data from Salesforce using curl Salseforce

[japanese(日本語)]

1.Using refreshtoken

#!/bin/sh

MY_INSTANCE="miura2-dev-ed"
CLIENT_ID="*** your client id ***"
CLIENT_SECRET="*** your client secret ***"
REFRESH_TOKEN="*** your refresh token ***"

#----------------------------------------------
# Get Access token from Refresh token.
#----------------------------------------------
RESULT=`curl -X POST https://$MY_INSTANCE.my.salesforce.com/services/oauth2/token -d "grant_type=refresh_token" -d "client_id=$CLIENT_ID" -d "client_secret=$CLIENT_SECRET" -d "refresh_token=$REFRESH_TOKEN"`

ACCESS=`echo $RESULT | awk 'BEGIN{FS="access_token\":"}{print $2}' |awk 'BEGIN{FS=","}{print $1}' | sed -s 's/\"//g'`

#----------------------------------------------
#Get data using Access token
#----------------------------------------------
curl -s https://$MY_INSTANCE.my.salesforce.com/services/data/v52.0/sobjects/Account -H "Authorization: Bearer $ACCESS" -H "Content-type: application/json"

 

How to get a Refreshtoken. (Refresh token is valid for 365 days) Salesforce.

19 Feb, 2022

port forwarding on linux

[japanese(日本語)]

this is a sample of  port forwarding on linux.

 

1.add forwarding settings.

# sysctl -w net.ipv4.ip_forward=1
# echo "net.ipv4.ip_forward = 1" >> /etc/sysctl.conf

2.add forwarding parameter.

#iptables -t nat -A PREROUTING -m tcp -p tcp --dst WAITING_ADDR --dport WAITING_PORT -j DNAT --to-destination DET_ADDR:DEST_PORT
#iptables -t nat -A POSTROUTING -m tcp -p tcp --dst DEST_ADDR --dport DEST_PORT -j SNAT --to-source WAITING_ADDR
19 Feb, 2022

port forwarding on Windows

[japanese(日本語)]

port forwarding on windows.

1.input commands as follows

netsh interface portproxy add v4tov4 listenport=[listen port] listenaddr=[My address(not 127.0.0.1)] connectport=[destination port] connectaddress=[destination address]

2. 上記定義の削除

netsh interface portproxy delete v4tov4 listenport=[listen port] listenaddr=[My address(not 127.0.0.1)
19 Feb, 2022

Using date string on a file

[japanese(日本語)]

This is a sample to attach the date string on your file.

Set DD=%date:~0,4%%date:~5,2%%date:~8,2%
set time2=%time: =0% 
Set TT=%time2:~0,2%%time2:~3,2%%time2:~6,2%
move logerr.log logerr_%DD%_%TT%.log
move logstd.log logstd_%DD%_%TT%.log
19 Feb, 2022

sample shell script to loop between the date ±1 specified by argument

[japanese(日本語)]

This is sample shell script to loop between the date ±1 specified by argument.

#!/bin/sh
START=$1
END=$2


START_1DAY_BEFORE=`date '+%Y%m%d' -d "1 days ago ${START}"`
END_1DAY_AFTER=`date '+%Y%m%d' -d "-1 days ago ${END}"`


echo $START_1DAY_BEFORE

for j in {0..10000}; do
    TARGET_YYYYMMDD=`date '+%Y%m%d' -d "-$j days ago ${START_1DAY_BEFORE}"`
    echo ${TARGET_YYYYMMDD}

    if [ ${TARGET_YYYYMMDD} -gt ${END_1DAY_AFTER} ]; then
       break
    fi
done
19 Feb, 2022

sendmail

[japanese(日本語)]

 

1.sendmai forward setting.

sendmail.cf (sendmail.mc) , you can change SMART_HOST’s behaviof by using  “[“.

[example] If you wanto to make sendmail forward always to  mailserver.hoge.com, you should write the setting as follows.

DS[mailserver.hoge.com]

If you don’t use “[“, sendmail will decide the forward destination by searching MX record.

so It is no guarantee to forward mailserver.hoge.com.

 

2. stop forwarding except for specific domain.

(1)add alias

#echo 'trash: /dev/null' >> /etc/aliases
#newaliases

(2)modify mailertable

#vi /etc/mail/mailertable
hoge.jp.com	smtp:[forwarding mail server]
.	local:trash
(using "[ ]" to avoid searching MX record )

(3)convert mailertable

#makemap hash /etc/mail/mailertable < /etc/mail/mailertable

(4)resart sendmail

#/etc/rc.d/init.d/sendmail restart

 

3. If you could’t access  DNS, and you want to forward another SMTP by sendmail.

make /etc/mail/service.switch. and write down as follows.

hosts  files

19 Feb, 2022

Sample code for NTML Authentication(Java)

[japanese(日本語)]

NTML Authentication sample code for Java

// HttpClient Version is 4.3.3
String userName = "test";
String password = "test";
HttpClientBuilder builder = HttpClientBuilder.create();
CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
credentialsProvider.setCredentials(AuthScope.ANY, new NTCredentials(userName + ":" + password));
builder.setDefaultCredentialsProvider(credentialsProvider);
 
HttpClient httpClient = builder.build();
HttpGet httpGet = new HttpGet("http://hogehoge");
 
try {
    HttpResponse response = httpClient.execute(httpGet);
    response.getEntity().writeTo(System.out);
} catch (ClientProtocolException e) {
    e.printStackTrace();
} catch (IOException e) {
    e.printStackTrace();
}

 


 
		
19 Feb, 2022

Using WebAccess activities response body to next WebAccess activities request body(Azure Data Factory)

[japanese(日本語)]

Using WebAccess activities response body to next WebAccess activities request body(Azure Data Factory)

[Alert] Web Access activity  can’t  handle more than 4MB. [Microsoft’s web site]

Web2 Settings

Method:POST

Body: @concat(‘{ “records”:’, activity(‘Web1’).output.records, ‘}’)

Thre result of Web1 Activity is not a simple strings. You can get value by using “activity(‘Web1’).output.records”.

But it is an array object and ommited the first

{
     "records" : [

And the last

   ]
}

So. You can build string by using concat function.