Showing posts with label Script. Show all posts
Forward tcp port on other device to localhost
In this example script ssh port is 2231,
plink forwarding port 3306 to localhost port 3306
@echo off
setlocal

:: Replace with your actual values
set "USER=dev"
set "HOST=dev.mangapul.com"
set "PASSWORD=V3r1HardP4$$w0Rd"
::set "COMMAND=ls -l"

:: Construct the plink command
:: plink -ssh %USER%@%HOST% -pw %PASSWORD% %COMMAND%

:: -pw password
:: -P  connect to specified port
:: -N  don't start a shell/command (SSH-2 only)

:: plink -ssh -L 127.0.0.1:3306:dev.mangapul.com:3306 dev@dev.mangapul.com -P 2231 -pw V3r1HardP4$$w0Rd -N

plink -ssh -L 127.0.0.1:3306:%HOST%:3306 %USER%@%HOST% -P 2231 -pw %PASSWORD% -N


if %ERRORLEVEL% equ 0 (
    echo Command executed successfully.
) else (
    echo Command execution failed.
)

endlocal

Read more »

Here is an example using sed to remove
the ^M carriage returns from a file.

# inplace (works!)
sed -i "s/\r//g" windows-text-file.txt
sed -e "s/^M//" filename > newfilename
Read more »
openssl req -x509 -nodes -days 1825 -newkey rsa:2048 -keyout d:\tobasa.local.selfsigned.key -out d:\tobasa.local.selfsigned.crt

Read more »
From .pfx
-----------------
openssl pkcs12 -in d:\temp\tobasaapp.pfx -clcerts -nokeys -out d:\temp\certificate.crt

openssl pkcs12 -in d:\temp\tobasaapp.pfx -nocerts -nodes -out d:\temp\private.key

openssl pkcs12 -in d:\temp\tobasaapp.pfx -out d:\temp\certificate.pem -nodes
To .pfx
-----------------
openssl pkcs12 -export -out certificate.pfx -inkey PrivateKey.key -in certificate.crt -certfile CACert.crt
Here:

Certificate.crt = Your-domain-Name.crt
CACert.crt = Certificate Authority Bundle
certificate.pfx is the new name of generated file
PrivateKey can be in .key or .txt format
Read more »
Gunakan script berikut untuk menghapus file dalam rentang waktu tertentu.
Ganti startdate dan enddate sesuai keperluan.

#!/bin/sh

startdate=200701010000
enddate=201012312359
touch -t $startdate ./startdatefiles
touch -t $enddate ./enddatefiles

a=0

for file in $(find ./ -type f -newer ./startdatefiles ! -newer ./enddatefiles )
do
  echo "Deleting $file"
  rm $file
  let "a+=1"
done

echo "Found $a files"

Read more »
Logo Postfix Email Server
Langkah-langkah berikut digunakan untuk memeriksa kondisi queue/antrian email di postfix email server.
iRedmail adalah paket instalasi Email Server yang mudah,gratis dan open source, yang menggunakan postfix sebagai MTA-nya.

Melihat isi queue

Bisa menggunakan command mailq atau postqueue -p
hasilnya akan sama. Contoh output:
jefri@mail:~$ mailq
-Queue ID- --Size-- ----Arrival Time---- -Sender/Recipient-------
7C751B0765  4185571 Fri Mar 18 17:23:40  pengirim@example.com
   (connect to mta7.am0.yahoodns.net[98.138.112.34]:25: Connection refused)
                                         penerima@yahoo.com
-- 4088 Kbytes in 1 Request.

jefri@mail:~$

Melihat status/shape queue

Command yang digunakan adalah qshape
Contoh penggunaan:
jefri@mail:~$ sudo qshape
                                         T  5 10 20 40 80 160 320 640 1280 1280+
                                  TOTAL  0  0  0  0  0  0   0   0   0    0     0
jefri@mail:~$ sudo qshape deferred
                                         T  5 10 20 40 80 160 320 640 1280 1280+
                                  TOTAL  1  0  0  0  0  0   0   0   1    0     0
                              yahoo.com  1  0  0  0  0  0   0   0   1    0     0


Mengirim email yang ada di dalam antrian

Mengirim satu email
postqueue -i 7C751B0765
7C751B0765 adalah email queue ID yang kita dapat dari command mailq

Mengirim seluruh email
postqueue -f

Menghapus email dari queue

Menghapus semua email yang tertunda
postsuper -d ALL deferred
Menghapus satu email
postsuper -d 7C751B0765
Menghapus email ke alamat tertentu
mailq | tail -n +2 | grep -v '^ *(' | awk  'BEGIN { RS = "" } { if ($8 == "penerima@example.com" && $9 == "") print $1 } ' | tr -d '*!' | postsuper -d -
Menghapus email dari alamat tertentu
mailq | awk '$7 ~/^pengirim@example.com$/ { print $1 }' | tr -d '*!' | postsuper -d -
Menghapus email dari domain tertentu
mailq | awk '$7 ~ /@example.com$/ { print $1 }' | tr -d '*!' | postsuper -d -


Membaca email dalam queue

postcat -q  DA80E24A0A




Read more »

Dalam file-file konfigurasi di Linux biasanya terdapat comment yang menjelaskan
fungsi/arti dari settingan.
Gunakan kode berikut untuk membersihkan comment-comment tersebut

sed '/ *#/d; /^ *$/d' 
Contoh penggunaan:
cat /usr/local/squid/etc/squid.conf |sed '/ *#/d; /^ *$/d' 

Read more »
Squid menampilkan tanggal di log file nya dalam format unix timestamp
yang kita tidak mengerti. Untuk membacanya dengan jelas gunakan kode berikut:

#!/usr/bin/perl -ps/^\d+\.\d+/localtime $&/e
Buat sebuah file - convert_unixtimestamp.pl,
isi dengan kode tadi, simpan dan pastikan di set menjadi executable(bila di linux) Contoh sebelum diconvert:
$ tail -f /c/squid/var/logs/access.log

1442487610.388      4 172.17.0.91 TCP_DENIED/407 2057 CONNECT apis.google.com:443 - NONE/- text/html
1442487611.874      1 172.17.0.91 TCP_DENIED/407 1737 CONNECT accounts.google.com:443 - NONE/- text/html
1442487612.208      4 172.17.0.91 TCP_DENIED/407 2069 CONNECT accounts.google.com:443 - NONE/- text/html

Sesudah:
$ tail -f /c/squid/var/logs/access.log | convert_unix_timestamp

Thu Sep 17 18:00:10 2015      4 172.17.0.91 TCP_DENIED/407 2057 CONNECT apis.google.com:443 - NONE/- text/html
Thu Sep 17 18:00:11 2015      1 172.17.0.91 TCP_DENIED/407 1737 CONNECT accounts.google.com:443 - NONE/- text/html
Thu Sep 17 18:00:12 2015      4 172.17.0.91 TCP_DENIED/407 2069 CONNECT accounts.google.com:443 - NONE/- text/html

Read more »

Kode berikut akan membuat mapping dari printer share di network Windows/AD
ke port LPT1 atau LPT2 dst,

@echo off
net use LPT1: \\pc-name\eplq1070 /persistent:yes
note:
pc-name : komputer tempat printer terinstall
eplq1070 : nama share printer
Buat menjadi .bat script untuk mempermudah autorun

Read more »

# Membuat default gateway
route add default gw 192.168.84.66

# mengapus default gateway
route del -net 0.0.0.0 gw 192.168.84.94

# menambah route
route del -net 202.159.0.0 netmask 255.255.0.0 gw 192.168.84.66

# mengapus route
route del -net 202.159.0.0 netmask 255.255.0.0 gw 192.168.84.66

Read more »