Feeds:
Posts
Comments

Archive for the ‘Linux/Unix’ Category

For example
find /Users/xxx/Desktop/directory|grep customtext$|awk ‘{print “sed -i -e ‘\”s/aaa/bbb/g’\” ” $1}’|sh

Read Full Post »

ssh-keyscan -H remote-host-domain-or-ip >> ~/.ssh/known_hosts

Read Full Post »

working example:

String [] cmd ={“/bin/sh”,“-c”,“sleep 60;nohup ls -l /Users/zcai/Downloads > /Users/zcai/Downloads/tmp.txt &”};

ProcessBuilder builder = new ProcessBuilder(cmd);

Read Full Post »

solution:

tomcat8443

 

Read Full Post »

:%s/.$//

Read Full Post »

By default, tomcat listens on port 8080, which is specified in the following file./var/lib/tomcat7/conf/server.xml

<Connector port=”8080″ protocol=”HTTP/1.1″
connectionTimeout=”20000″
URIEncoding=”UTF-8″
redirectPort=”8443″ />

If you want tomcat to listen on a port other than 8080, you just need to make change to the file to modify 8080 to other number, save the file and restart tomcat. However, if you want tomcat to listen on port 80, it will work, that is bacause only root user can visit port numbers below 1024.

Here is the solution to set tomcat listening on port 80: Forward port 80 to port 8080

sudo iptables -t nat -A PREROUTING -p tcp –dport 80 -j REDIRECT –to-port 8080
sudo iptables-save > ~/my_iptables.rules

or if you have saved the iptables, you can restore it:
sudo iptables-restore < ~/my_iptables.rules

Read Full Post »

curl and wget

curl is similar with wget, and the difference is that wget save the web page and curl display the content of the web page on the screen.

For example,

curl ifconfig.me will show your ip address on the screen through the web site ifconfig.me

Read Full Post »

Problem:
There is an internal network without internet access, and I want each node of the internal network to be able to access internet.

Solution:
Use one node of the internal network as the gateway. On the gateway node, there are two network interface cards: eht0 and eth1. eth0 connects the internal network and eth1 connects internet. Configure the route table on the gateway node to forward packets from eth0 to eth1.

Example:

Set up 9 Ubuntu virtual machine under Virtualbox with the following hostnames and ip addresses:
ubuntu1 192.168.10.1
ubuntu2 192.168.10.2
ubuntu3 192.168.10.3
ubuntu4 192.168.10.4
ubuntu5 192.168.10.5
ubuntu6 192.168.10.6
ubuntu7 192.168.10.7
ubuntu8 192.168.10.8
ubuntu100 192.168.10.100 (used as gateway)

Configure gateway

set up two network interface cards (Adapter1 and Adapter2) on ubuntu100 192.168.10.100:
Adapter1 connects internal network
Capture35

Adapter2 connects internet
Capture36

configure gateway route table:

sudo sh set_gateway.sh

sudo iptables-save
————————————————————————-

refer to: http://www.debian-administration.org/articles/23

zhengqiu@ubuntu100:~/Desktop$ more set_gateway.sh
#!/bin/sh

PATH=/usr/sbin:/sbin:/bin:/usr/bin

#
# delete all existing rules.
#
iptables -F
iptables -t nat -F
iptables -t mangle -F
iptables -X

# Always accept loopback traffic
iptables -A INPUT -i lo -j ACCEPT

# Allow established connections, and those not coming from the outside
iptables -A INPUT -m state –state ESTABLISHED,RELATED -j ACCEPT
iptables -A INPUT -m state –state NEW ! -i eth1 -j ACCEPT
iptables -A FORWARD -i eth1 -o eth0 -m state –state ESTABLISHED,RELATED -j ACCEPT

# Allow outgoing connections from the LAN side.
iptables -A FORWARD -i eth0 -o eth1 -j ACCEPT

# Masquerade.
iptables -t nat -A POSTROUTING -o eth1 -j MASQUERADE

# Don’t forward from the outside to the inside.
iptables -A FORWARD -i eth1 -o eth1 -j REJECT

# Enable routing.
echo 1 > /proc/sys/net/ipv4/ip_forward
————————————————————————–

configure the two network cards on the gateway server 192.168.10.100:
Capture41

restart network
$sudo /etc/init.d/networking restart
Capture40

check route table
Capture38

check network configuration
Capture39

Configure node

on each node, configure network interface and nameserver like the example on ubuntu5 192.168.10.5 below:
Capture43

On each node of the internal network, you will be able to access the internet.
Capture44

Read Full Post »

without the dash (su anatherusername), only change the UID and username of the system

with the dash (su – anotherusername), change the UID and username of the system, and also inherit the user environment.

Capture34

Read Full Post »

The post takes mongoDB shard server as an example to demostrate running a program automatically as a non-privileged user on Ubuntu boot. Every time you reboot the system the mondod shard server starts automatically.

sudo mkdir -p /mongodb/data/shard12

sudo mkdir -p /mongodb/logs

#add a user named mongodb

sudo adduser mongodb

sudo chown -R mongodb:mongodb /mongodb

sudo vi /etc/init.d/run_mongod_shardsvr.sh (add the following two lines in this file)
#!/bin/bash
su – mongodb -c “/home/zhengqiu/mongodb-linux-x86_64-2.2.1/bin/mongod -shardsvr -replSet shard1 -port 27017 -dbpath /mongodb/data/shard12 -logpath /mongodb/logs/shard12.log -fork &”

sudo chmod +x sudo vi /etc/init.d/run_mongod_shardsvr.sh

#asign the script to detault runlevel
sudo update-rc.d run_mongod_shardsvr.sh defaults

Capture33

reboot the system and the output of the script shown on the screen
Capture32

Read Full Post »

Older Posts »