One Liner Command to Check If Linux Process is Running

I would like to share one liner command to check if a Linux process is running. Below is the one liner command and you can replace “sendmail” to any process you want to check: -

chkdaemon="sendmail" ; ! pgrep $chkdaemon >/dev/null && echo "$chkdaemon not running" || echo "$chkdaemon is running"

I will be sharing more useful commands. Thank you and have fun.

Duck DNS Update Script for MikroTik RouterOS 5.26 Behind NAT

I would like to share another Duck DNS Update Script for MikroTik RouterOS v5.26 which able to work if you place the RouterBOARD behind another router. Please note that this script can only fetch HTTP URL instead of HTTPS URL. You need the following policy read, write, policy, test for this script and remember to set a scheduler.

# Duck DNS Update Script for MikroTik RouterOS 5.26 behind NAT

#--------------- Change Values in this section to match your setup ------------------

:local ducktoken "your-token"
:local duckdomain "your-domain"
:local ddnshost "$duckdomain.duckdns.org"

#------------------------------------------------------------------------------------
# No more changes need

:local ipddns [:resolve $ddnshost]

/tool fetch mode=http address="icanhazip.com" src-path="/" dst-path="/icanhazip.txt"
:delay 3
:local result [/file get icanhazip.txt contents]

:local resultLen [:len $result]
:local endLoc [:find $result "\n" -1]
:local ipfresh [:pick $result 0 $endLoc]
:log info "Duck DNS: IP detected from icanhazip.com is $ipfresh"

:if ($ipddns != $ipfresh) do={
    :log info "Duck DNS: Old IP is $ipddns"
    :log info "Duck DNS: New IP is $ipfresh"
    /tool fetch url="http://www.duckdns.org/update\?domains=$duckdomain&token=$ducktoken&ip=$ipfresh" dst-path=duckdns.txt
    :global ipddns $ipfresh
    :log info "Duck DNS: IP updated to $ipfresh!"
    } else={
     :log info "Duck DNS: Current IP is $ipddns"
     :log info "Duck DNS: Detected IP is same with current IP, dont need changes"
    }
}

Thank you.

Duck DNS Update Script for MikroTik 5.26

I would like to share the following Duck DNS Update Script for MikroTik 5.26 running on RB951G-2HnD.Please note that this script doesn’t work behind NAT and you can only fetch HTTP URL instead of HTTPS URL. You need the following policy read, write, policy, test for this script and remember to set a scheduler.

# Duck DNS Update Script for MikroTik

#--------------- Change Values in this section to match your setup ------------------

# Define User Variables for Duck DNS
:local ducktoken "your-token"
:local duckdomain "your-domain"
:local ddnshost "$duckdomain.duckdns.org"

# Change to the name of interface that gets the dynamic IP address
:local theinterface "PPPoE-interface"

#------------------------------------------------------------------------------------
# No more changes need

:local ipddns [:resolve $ddnshost];
:local ipfresh [ /ip address get [/ip address find interface=$theinterface ] address ]

:if ([ :typeof $ipfresh ] = nil ) do={
   :log info ("DuckDNS: No ip address on $theinterface .")
} else={
   :for i from=( [:len $ipfresh] - 1) to=0 do={ 
      :if ( [:pick $ipfresh $i] = "/") do={ 
      :set ipfresh [:pick $ipfresh 0 $i];
      } 
}
 
:if ($ipddns != $ipfresh) do={
    :log info ("DuckDNS: IP-DuckDNS = $ipddns")
    :log info ("DuckDNS: IP-Fresh = $ipfresh")
    :log info "DuckDNS: Update IP needed, Sending UPDATE...!"
    /tool fetch url="http://www.duckdns.org/update\?domains=$duckdomain&token=$ducktoken&ip=$ipfresh" dst-path=duckdns.txt
    :global ipddns $ipfresh
    :log info "DuckDNS: IP updated to $ipfresh!"
    } else={
     :log info "DuckDNS: dont need changes";
    }
}

Thank you.

Duck DNS Update Script for OpenWrt

Since Dyn stop offering free dynamic DNS, I have choose to use Duck DNS and I would like to share the following script I use to update Duck DNS free dynamic DNS hosted on Amazon EC2 on my OpenWrt Attitude Adjustment 12.09 running on TP-Link TL-WR1043ND v1. Please note that I am using wget in OpenWrt and the free dynamic DNS link have to change to HTTP from HTTPS.

#!/bin/sh

echo "# --------------------------------------------------------------------------"
echo "# Welcome to Duck DNS Update Script"
echo "# --------------------------------------------------------------------------"

# Change to your domain and token generated
domain="your-domain"
token="your-token"

log="/tmp/duckdns.log"
file="/tmp/ipaddress.duckdns"
DuckDNS="http://www.duckdns.org/update?domains="$domain"&token="$token"&ip="

if [ ! -e "$file" ]; then
echo "0.0.0.0" > $file
fi

CHECKIP=`wget -qO- http://icanhazip.com`
CURRENTIP=`cat $file`

if [ $CHECKIP != $CURRENTIP ]; then

echo "New IP $CHECKIP detected and updating current IP..."

wget -q $DuckDNS -O $log
sleep 10

status=`cat $log`
if [ "$status" == "KO" ]; then
echo "Failed to update Duck DNS..."
exit 1
fi

OLDIP=`head -1 $file`
echo $CHECKIP > $file
echo "Current IP $CHECKIP updated and old IP was $OLDIP..."

else

echo "No updated needed for $CHECKIP IP..."

fi

After the above script is save as /root/duckdns.sh you can proceed to add the following line at Scheduled Tasks in OpenWrt. You need to restart cron service.

*/5 * * * * /root/duckdns.sh &> /dev/null

Thank you.

How To Install and Configure Cntlm to Access ISA Server on CentOS 6.5

This blog post describes how to install and configure Cntlm in CentOS 6.5 64-bit connecting to Microsoft ISA server to enable web browsing capability. Decide to write this simple blog post to my previous blog post Install and Configure NTLMAPS to Access ISA Server.

Download Cntlm
Run the command below to download cntlm-0.92.3-1.x86_64.rpm RPM file: -

# wget -c -O cntlm-0.92.3-1.x86_64.rpm http://sourceforge.net/projects/cntlm/files/cntlm/cntlm%200.92.3/cntlm-0.92.3-1.x86_64.rpm/download

Install Cntlm
Run the command below to install Cntlm: -

# rpm -ivh cntlm-0.92.3-1.x86_64.rpm

Configure Cntlm
Run the command below to edit the Cntlm configuration file after Cntlm installed: -

# vi /etc/cntlm.conf

Now modify the below and save the configuration file after modifying it (below is an example only): -

Username your.nt.username
Domain your.domain
Proxy your.isa.server.name:your.isa.server.port
Listen 3128

Next run the command below to generate the password hash: -

# cntlm -H -c /etc/cntlm.conf

Once the password has is created, copy the PassNTLMv2 line and paste it after “Domain” line like below: -

Username your.nt.username
Domain your.domain
PassNTLMv2 your.password.hash
Proxy your.isa.server.name:your.isa.server.port
Listen 3128

Start Cntlm
Run the command below to start NTLMAPS: -

# service cntlmd start

System Wide Configuration
You can setup the proxy environment in /etc/profile as global variable as below (tested with curl, elinks, lynx, wget & yum): -

export http_proxy=http://127.0.0.1:3128

GUI Web Browser Configuration
You can use the following information to configure in your GUI web browser: -

Proxy IP address: 127.0.0.1
Proxy IP address: 3128