25.05.2012

Bash - odd or even


echo -n "Enter numnber : "
read n

rem=$(( $n % 2 ))

if [ $rem -eq 0 ]
then
  echo "$n is even number"
else
  echo "$n is odd number"
fi

24.05.2012

FreeBSD dump/restore

dump -L -0 -f- /usr | ssh -2 -C -l remoteuser 10.0.0.1 restore -r -f-
or
on restore side

cd /mnt/disk
nc -l -n -p 6666 | restore -rfv -
on dump side
cat dumpfile | nc remote_ip 6666

11.05.2012

if x even - (x+1)/2*e
if x odd - x/2*e+(e/2)
$ x=0;y=0;for i in {1..15};do x=$(($x+1));y=$(($y+$x));e=$y;echo day $i: $e;done
day 1: 1
day 2: 3
day 3: 6
day 4: 10
day 5: 15
day 6: 21
day 7: 28
day 8: 36
day 9: 45
day 10: 55
day 11: 66
day 12: 78
day 13: 91
day 14: 105
day 15: 120

$ x=0;y=0;for i in {1..347};do x=$(($x+1));y=$(($y+$x));e=$y;echo day $i: $e;done|grep 'day 347'
day 347: 60378
(347+1)/2*347=60378

$ x=0;y=0;for i in {1..347};do x=$(($x+1));y=$(($y+$x));e=$y;echo day $i: $e;done|grep 'day 346'
day 346: 60031
((346/2)*346)+(346/2)=60031