Thursday, April 24, 2008
Thursday, April 20, 2006
network diagnose
#change hostname
echo "HOSTNAME=<ur_hostname>" >> /etc/sysconfig/network
#server lookup
#hostnames: /etc/hosts
#dns: /etc/resolv.conf
#nic configuration: /etc/sysconfig/network-scripts/
#gateway
netstat -rn
#port defination: /etc/services
#restart network
/etc/rc.d/init.d/network restart
#to change the IP address to 192.168.0.10 temporarily
ifconfig eth0 inet 192.168.0.10 netmask 255.255.255.0
#adds a route to the network 192.56.76.x via "eth0".
route add -net 192.56.76.0 netmask 255.255.255.0 eth0
#nmap & netstat deserve another article
--
For many are called, but few are chosen.
-- Matthew 22:14
Friday, April 07, 2006
Re: [dyno's blog for tech] string manipulation in bash script
#!/bin/sh
#basic string manipulation using shell script
set -v
s=" hello world! racn4 "
# 01234567890123456789
#length
echo ${#s}
expr length "$s"
#index
ss='world'
expr index "$s" $ss
#substr
echo ${s:14}
echo ${s:14:4}
echo ${s:(-2)}
#match
[[ $s =~ "o.*o" ]] && echo "yes"
(echo $s | grep -q "o.*o") && echo "yes"
#trim space
s=${s%% }
s=${s## }
echo "<${s}>"
#basic replace
echo ${s/o/O}
echo ${s/#h/O}
echo ${s/%racn4/O}
echo ${s//o/O}
#trim pre/postfix
echo ${s#h*o}
echo ${s##h*o}
echo ${s%o*4}
echo ${s%%o*4}
#upper/lower case
echo $(tr 'a-z' 'A-Z' <<< $s)
#comparation
[[ $s > "hello" ]] && echo "hello"
#number conversion
x="2"; y=3
echo $(($x + $y))
#for more complicated manipulation using grep/sed/awk instead
--
For many are called, but few are chosen.
-- Matthew 22:14

