Categories
System/Linux/Unix*

[memo] 用 shell awk 加總 column

ls -l `find /mnt/tslog/archive/ -name "*20190[1..6]*" -type f` | awk '{sum += $5} END {print sum}'
160038650315

ls -l `find /mnt/tslog_bak -name "*20190[1..6]*" -type f` | awk '{sum += $5} END {print sum}'
160038650315

ls -l `find /mnt/tslog_backup2 -name "*20190[1..6]*" -type f` | awk '{sum += $5} END {print sum}'
160038650315

Categories
DATABASE System/Linux/Unix*

Trace 某 Linux process 的 環境變數 environ

Lazy 的 apache 有作這個設定 

export NLS_NAME=”American_Taiwan.UTF8″

螢幕快照 2014 10 28 下午8 42 01

 

 

  838  cd /proc/

 

  840  ps auwwx|grep apache <– 找一個 apache 的 process id , ex: 21192

  841  cd 21192

  843  cat environ <– 把環境變數列出來

 

.

螢幕快照 2014 10 28 下午8 39 09

Categories
JOB Programming/C System/Linux/Unix*

get my ip address useing c / sample code

C CODE

902c2c377de669ec360e37664cc1f041

/*
  FILENAME : my_local_ip.c
*/
#include
#include
#include
#include
#include
#include
#include
#include 

int main(int argc, char **argv) {
  int s;
  struct sockaddr_in sin;
  int slen;
  int port;

  if( argc<3 ) {
    printf("Usage: %s  \n", argv[0]);
    printf("\n\tsample %s 203.66.88.89 80\n",argv[0]);
    return -1;
  }

  port = atoi(argv[2]);

  s = socket(PF_INET, SOCK_STREAM, 0);
  memset(&sin, 0, sizeof(sin));
  sin.sin_family = PF_INET;
  sin.sin_port = htons(port);
  sin.sin_addr.s_addr = inet_addr(argv[1]);
  if(connect(s, (struct sockaddr *)&sin, sizeof(sin)) < 0) {
    printf("127.0.0.1");
    return -1;
  }

  memset(&sin, 0, sizeof(sin));
  slen = sizeof(sin);
  if(getsockname(s, (struct sockaddr *)&sin, &slen) < 0) {
    printf("127.0.0.1");
    close(s);
    return -1;
  }

  printf("%s", inet_ntoa(sin.sin_addr));

  close(s);
  return 0;
}

可以依自己的需求來改這SHELL:

#!/bin/sh
ADDR=`my_local_ip 168.95.1.1 53`
FILENAME=${ADDR=}".txt"

echo $FILENAME
Categories
Copy_N_Paste System/Linux/Unix*

unix shell programming / sh / csh syntax

Shell script syntax

Bourne shell (sh) syntax samples

test:
[ number -lt|-le|-eq|-ne|-ge|-gt number ]
[ string = != string ]

if [ test ]
then
   commands
elif [ test ]
   commands
else
   commands
fi

for var in item1 item2 item3
do
  commands
done

while test
do
  commands
done

case expression in
  case1)         commands ;;
  case2|case3)   commands ;;
  *)             default-commands ;;
esac


# How to read an input file into shell variables:
while read variable1 variable2
do
  ...
done < $input_file

# How to redirect stdout/stderr
echo something 1>&2
echo something 2>&1

# How to throw out stdout and stderr
some_command > /dev/null 2>&1

# Shell functions:
func () {
	echo $1 $2 $3
}
func a b c


C shell (csh) syntax samples

test:
( expression ==|!=|>>|<< expression )

if ( test ) command

if ( test ) then
   commands
else if ( test ) then
   commands
else
   commands
end if

foreach var ( list list list )
  commands
end

while condition
   commands
end

# How to throw out stdout and stderr
some_command >& /dev/null

另一個

#!/bin/sh
count=0
while [ $count -lt 5 ]
do
  count=`expr $count + 1`
  echo $count
done
Categories
System/Linux/Unix*

UTF8 / BIG5 / PUTTY / SHELL / SCREEN 真難搞系列

因為工作上都要改成 UTF8 , 所以很多以前熟悉的工具都要作一番改變 , 於是順手記在這邊 , 免得又忘記了.

我的 .screenrc

caption always "%-Lw%{= BW}%50>%n%f* %t%{-}%+Lw%<"
bind b encoding big5 utf8
bind u encoding utf8 big5

我的 .bashrc

EDITOR="/usr/bin/vim"

我的 putty setting