2019年12月26日 星期四

curl check connection time

#!/bin/sh


while :; do

TIME=`date "+%Y%m%d"`
TIMEMM=`date "+%Y-%m-%d %H:%M:%S"`
DELTIME=`date --date='7 days ago' "+%Y%m%d"`
echo $TIMEMM >> /path/8.10_$TIME.txt

curl  --write-out "%{http_code},%{time_total}\n" -X POST https://xxx.xxx.xxx/api                              /product/termproduct \
  -H 'Accept: */*' \
  -H 'Cache-Control: no-cache' \
  -H 'Content-Type: application/json' \
  -H 'Host:xxx.xxx.xxx.xxx:xxxx' \
  -H 'cache-control: no-cache' \
  -d '{
 "Key":"測試"
}' \
--insecure >> /path/8.10_$TIME.txt



echo "" >> /path/8.10_$TIME.txt

sleep 60

rm -rf  /path/8.10_${DELTIME}.txt
done

2019年12月16日 星期一

awk

awk 'NR == 1 || NR % 6 == 1' filename
awk 'NR == 2 || NR % 6 == 2' filename
awk 'NR == 3 || NR % 6 == 3' filename
awk 'NR == 4 || NR % 6 == 4' filename
awk 'NR == 5 || NR % 6 == 5' filename
awk 'NR == 6 || NR % 6 == 0' filename

2019年11月11日 星期一

Online Carrefour

   <frameset cols="50%,*" rows="50%,*">
   <frame name="Web03" src="https://online.carrefour.com.tw:7113">
   <frame name="Web04" src="https://online.carrefour.com.tw:7114">
   <frame name="Web05" src="https://online.carrefour.com.tw:7115">
   <frame name="Web06" src="https://online.carrefour.com.tw:7116">

   </frameset>

2019年11月5日 星期二

Linux shell date

前一天

  • date -d '-1 days' +%F
  • date -d '-1 days' +%Y-%m-%d"

後一天

  • date -d '+1 days' +%F
  • date -d '+1 days' +%Y-%m-%d

1小時前

  • date -d '-1 hours' "+%Y-%m-%d %H:%M:%S"
  • date -d '-1 hours' "+%F %H:%M:%S"

1小時後

  • date -d '+1 hours' "+%Y-%m-%d %H:%M:%S"
  • date -d '+1 hours' "+%F %H:%M:%S"

1分鐘前

  • date -d '-1 minutes' "+%Y-%m-%d %H:%M:%S"
  • date -d '-1 minutes' "+%F %H:%M:%S"

1分鐘後

  • date -d '+1 minutes' "+%Y-%m-%d %H:%M:%S"
  • date -d '+1 minutes' "+%F %H:%M:%S"

1秒前

  • date -d '-1 seconds' "+%Y-%m-%d %H:%M:%S"
  • date -d '-1 seconds' "+%F %H:%M:%S"

1秒後

  • date -d '+1 seconds' "+%Y-%m-%d %H:%M:%S"
  • date -d '+1 seconds' "+%F %H:%M:%S"

Linux shell script expect

#!/bin/sh

DTIME=`date -d '1 days ago' "+%Y%m%d"`
TIMENOW=`date "+%Y-%m-%d"`
HOST="100.69.10.166"
USER="sftpuser"
PASS="p@ssw0rd"
PATH="/sftp/path/here"
LPATH="/home/hanzo"

sftpget(){
expect -c "
spawn sftp ${USER}@${HOST}
expect \"password: \"
send \"${PASS}\r\"
expect \"sftp>\"
send \"cd $PATH\r\"
expect \"sftp>\"
send \"lcd ${LPATH}\r\"
expect \"sftp>\"
send \"get P4ITM${DTIME}.TXT\r\"
expect \"sftp>\"
send \"get P4ITM${DTIME}.TRG\r\"
expect \"sftp>\"
send \"get P4ITS${DTIME}.TXT\r\"
expect \"sftp>\”
send \”get P4ITS${DTIME}.TRG\r\"
expect \"sftp>\”
send \”get P4ITB${DTIME}.TXT\r\"
expect \"sftp>\”
send \”get P4ITB${DTIME}.TRG\r\"
expect \"sftp>\”
send \”get P4OP${DTIME}.TXT\r\"
expect \"sftp>\”
send \”get P4OP${DTIME}.TRG\r\"
expect \"sftp>\”
send \"bye\r\"

expect \"#\"
"
}

smail(){
echo \"Hello World.\" | mutt -s \"hello world\" -a attachfile.txt -c hanzo.chen@gmail.com
}

case $1 in

get)

sftpget
;;

send)
smail
;;

*)
echo "Usage $0 {get|send}"
;;
esac


2019年5月19日 星期日

nmap command

掃同網段有那些
IP nmap -sP 192.168.0.0/24


nmap -sP 192.168.0.1-254

掃 OS
 nmap -O 192.168.0.1

掃 Port
 nmap -p 21 192.168.0.1

 全面掃描
 nmap -A -T4 192.168.0.1

只列出網段清單
 nmap -sL 192.168.0/24

用 TCP SYN 掃
 nmap -sS 192.168.0.1

用 TCP connect 掃
 nmap -sT 192.168.0.1

掃 UDP
 nmap -sU 192.168.0.1

2019年5月9日 星期四

一個簡單產生 CSR 與 PKCS12 的 Script


#!/bin/sh


if [ $# -lt 2 ] ; then
echo "Usage:$0 {create|pkcs12|check} {domain}"
exit 0
fi

DN=$2 

case "$1" in


create)
openssl genrsa -out $2.key 2048

keycontent(){
cat << EOF
Country Name (2 letter code) []:TW
State or Province Name (full name) []:Taiwan
Locality Name (eg, city) []:Taipei
Organization Name (eg, company) []:Company
Organizational Unit Name (eg, section) []:Digital IT
Common Name (eg, fully qualified host name) []: $DN.company.com.tw
Email Address []:null
A challenge password []:null

EOF
}

keycontent

openssl req -new -sha256 -key $2.key -out $2.csr
;;

pkcs12)
openssl pkcs12 -export -in $2.crt -inkey $2.key -out $2.pfx -certfile ca.crt -password pass:1234567890
#openssl pkcs12 -export -in $2.crt -inkey $2.key -out $2.pfx -password pass:1234567890

echo "done."
echo "Password is 1234567890"

read -p "do you wang to check PKC12 file ? " answer

if [ $answer = "y" ] ; then
     openssl pkcs12 -info -in $2.pfx
fi
;;

check)
openssl req -in $2.csr -pubkey -noout -outform pem | shasum
openssl pkey -in $2.key -pubout -outform pem | shasum
openssl x509 -in $2.crt -pubkey -noout -outform pem | shasum
;;

*)

echo "Usage:$0 {create|pkcs12|check} {domain}"
exit 1
;;

esac