Merge branch 'master' of github.com:ole-tange/tangetools
This commit is contained in:
commit
e90e4a0219
59
w4it-for-port-open/w4it-for-port-open
Executable file
59
w4it-for-port-open/w4it-for-port-open
Executable file
|
@ -0,0 +1,59 @@
|
|||
#!/bin/bash
|
||||
|
||||
HOST=$1
|
||||
PORT=$2
|
||||
|
||||
usage () {
|
||||
echo "Usage:"
|
||||
echo " $0 host [port]"
|
||||
echo " port defaults to 22 (ssh)"
|
||||
exit 1
|
||||
}
|
||||
|
||||
print_not_reachable () {
|
||||
if [ "$NOT_REACHABLE" = "1" ] ; then
|
||||
echo -n .
|
||||
else
|
||||
echo -n $HOST:$PORT is not reachable
|
||||
NOT_REACHABLE=1
|
||||
fi
|
||||
}
|
||||
|
||||
print_up_but_port_closed () {
|
||||
if [ "$PORT_CLOSED" = "1" ] ; then
|
||||
echo -n .
|
||||
else
|
||||
echo -n $HOST is up but port $PORT is closed
|
||||
PORT_CLOSED=1
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
port_is_open () {
|
||||
# If tcptraceroute stops working use:
|
||||
# echo | nc -w 2 $HOST $PORT || failed
|
||||
OUT=$(tcptraceroute -f 255 -m 255 -q 1 -w 1 $HOST $PORT 2>&1)
|
||||
if echo "$OUT" | grep 'Destination not reached' >/dev/null ; then
|
||||
print_not_reachable
|
||||
OPEN=no
|
||||
elif echo "$OUT" | grep '\[closed\]' >/dev/null ; then
|
||||
print_up_but_port_closed
|
||||
sleep 1
|
||||
OPEN=no
|
||||
else
|
||||
OPEN=yes
|
||||
fi
|
||||
}
|
||||
|
||||
if [ -z "$HOST" ] ; then
|
||||
usage
|
||||
fi
|
||||
if [ -z "$PORT" ] ; then
|
||||
PORT=22
|
||||
fi
|
||||
|
||||
port_is_open
|
||||
while [ "$OPEN" = "no" ] ; do
|
||||
port_is_open
|
||||
done
|
||||
echo
|
80
zram-init/zram
Executable file
80
zram-init/zram
Executable file
|
@ -0,0 +1,80 @@
|
|||
#!/bin/bash
|
||||
### BEGIN INIT INFO
|
||||
# Provides: zram
|
||||
# Required-Start:
|
||||
# Required-Stop:
|
||||
# Default-Start: 2 3 4 5
|
||||
# Default-Stop: 0 1 6
|
||||
# Short-Description: Increased Performance In Linux With zRam (Virtual Swap Compressed in RAM)
|
||||
# Description: Adapted from systemd scripts at https://github.com/mystilleef/FedoraZram
|
||||
### END INIT INFO
|
||||
# Author: tradetaxfree http://crunchbanglinux.org/forums/topic/15344/zram-a-good-idea/
|
||||
|
||||
start() {
|
||||
# get the number of CPUs
|
||||
num_cpus=$(grep -c processor /proc/cpuinfo)
|
||||
# if something goes wrong, assume we have 1
|
||||
[ "$num_cpus" != 0 ] || num_cpus=1
|
||||
|
||||
# set decremented number of CPUs
|
||||
decr_num_cpus=$((num_cpus - 1))
|
||||
|
||||
# get the amount of memory in the machine
|
||||
mem_total_kb=$(grep MemTotal /proc/meminfo | grep -E --only-matching '[[:digit:]]+')
|
||||
mem_total=$((mem_total_kb * 1024))
|
||||
|
||||
# load dependency modules
|
||||
modprobe zram zram_num_devices=$num_cpus
|
||||
|
||||
# initialize the devices
|
||||
for i in $(seq 0 $decr_num_cpus); do
|
||||
echo $((mem_total / num_cpus)) > /sys/block/zram$i/disksize
|
||||
done
|
||||
|
||||
# Creating swap filesystems
|
||||
for i in $(seq 0 $decr_num_cpus); do
|
||||
mkswap /dev/zram$i
|
||||
done
|
||||
|
||||
# Switch the swaps on
|
||||
for i in $(seq 0 $decr_num_cpus); do
|
||||
swapon -p 100 /dev/zram$i
|
||||
done
|
||||
}
|
||||
|
||||
stop() {
|
||||
# get the number of CPUs
|
||||
num_cpus=$(grep -c processor /proc/cpuinfo)
|
||||
|
||||
# set decremented number of CPUs
|
||||
decr_num_cpus=$((num_cpus - 1))
|
||||
|
||||
# Switching off swap
|
||||
for i in $(seq 0 $decr_num_cpus); do
|
||||
if [ "$(grep /dev/zram$i /proc/swaps)" != "" ]; then
|
||||
swapoff /dev/zram$i
|
||||
sleep 0.1
|
||||
fi
|
||||
done
|
||||
|
||||
sleep 0.1
|
||||
modprobe -r zram
|
||||
}
|
||||
|
||||
case "$1" in
|
||||
start)
|
||||
start
|
||||
;;
|
||||
stop)
|
||||
stop
|
||||
;;
|
||||
restart)
|
||||
stop
|
||||
sleep 3
|
||||
start
|
||||
;;
|
||||
*)
|
||||
echo "Usage: $0 {start|stop|restart}"
|
||||
RETVAL=1
|
||||
esac
|
||||
exit $RETVAL
|
Loading…
Reference in a new issue