Skip to main content

Posts

Showing posts with the label script

[Linux/BashScript/Vim] Encrypted vim file, cat util.

cat_vim_file.sh =============== #!/bin/bash usage() {   echo "$1 <filename>" } FILENAME=$1 if [ "$FILENAME" == "" ]; then   usage $0 elif [ -f ${FILENAME} ]; then   echo -n "EnterPassword:"   # Without echo (-s)   read -s szPassword   echo $szPassword| vim -es '+%print' '+:q!' $FILENAME else   echo "FileNotFound: $FILENAME"   usage $0 fi =============== Reference: https://stackoverflow.com/questions/3980668/how-to-get-a-password-from-a-shell-script-without-echoing

[AWK] C struct to fprintf script

example code #!/bin/bash awk ' { if ($1 == "u_int" ) FORMAT="%u"; \ else if ($1 == "u_short" ) FORMAT="%u"; \ else if ($1 == "uint64_t" ) FORMAT="%lu"; \ else if ($1 == "int" ) FORMAT="%d"; \ else if ($1 == "int32_t" ) FORMAT="%d"; \ else if ($1 == "int64_t" ) FORMAT="%ld"; \ else if ($1 == "u_char" ) FORMAT="%s"; \ else if ($1 == "char" ) FORMAT="%s"; \ else FORMAT="ERROR"; \ if ( substr($2,length($2),1) == ";" ) KEY=substr($2,0, length($2)-1); else KEY=$2; \ print "fprintf(stdout, \"" KEY "= [" FORMAT "]\\n\", p_x->" KEY " );" } ' a.dat # a.dat typedef struct {       u_int    m1;       int myport;       u_short  ushort2;       u_int    int1;       u_short  data;       u_char   dummy[8];       uint64_t length;

[bash] unix time to date format

----------------------- function print_date_by_unix_time {   LOCALE="+9hour"   date -d "1970-01-01 $1 seconds ${LOCALE}" } ----------------------- Output Example # print_date_by_unix_time `date +%s` Fri Jan 29 20:40:23 KST 2016 # print_date_by_unix_time 1354067587 Wed Nov 28 10:53:07 KST 2012