Skip to main content

Posts

Showing posts with the label bash

[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

[bash-script] git log with refs of body

git log with refs of body #!/bin/bash COMMITS=${1} DELIMITER="|" RET_GITLOG=`git log --format=format:"${DELIMITER} %h ${DELIMITER} %s ${DELIMITER}" ${COMMITS}` HEADER="${DELIMITER} Hash ${DELIMITER} Subject ${DELIMITER} Refs ${DELIMITER}" function func_append_refs {   while true   do     read -r MY_LINE     if [ "${MY_LINE}" == "" ]; then       return     fi     COMMIT_HASH=`echo "${MY_LINE}" | awk -F "${DELIMITER}" ' { print $2 } '`     REFS_LOG=`git log -1 ${COMMIT_HASH} --format=format:'%b' | egrep -i "refs|fix"`     echo "${MY_LINE} ${REFS_LOG} |"   done } echo "${HEADER}" echo "${RET_GITLOG}" | func_append_refs

[bash-script] get_info.sh print cpu allocation infomation of threads

1) way1 ps xH -o 'pid tid cmd comm pcpu psr' 2) way2 #!/bin/bash TMP_FILE=$(mktemp /tmp/abc-script.XXXXXX) echo ${TMP_FILE} ps xH -o 'pid tid cmd comm pcpu ' > ${TMP_FILE} function make_header() {   echo -n "$1"   echo " psr" } function make_values() {   echo -n "$1"   STATUS_FILE=/proc/${2}/task/${3}/status   if [ -f ${STATUS_FILE} ] ; then     CPU_SET=`cat ${STATUS_FILE}  |grep Cpus_allowed_list |awk ' { print $2 } '`   else     CPU_SET="None"   fi   echo " ${CPU_SET}" } let IDX=0 while IFS='' read -r line || [[ -n "$line" ]]; do    LINE_SEP=( $line )    MY_PID=${LINE_SEP[0]}    MY_TID=${LINE_SEP[1]}    if [ ${IDX} -eq 0 ]; then      SZ_HEADER=`make_header "$line"`      echo ${SZ_HEADER}    else      SZ_VALUES=`make_values "$line" ${MY_PID} ${MY_TID}`      echo ${SZ_VALUES}    fi #   echo ${IDX}   let IDX=${IDX}+1 done < "

[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