Programming2015. 3. 14. 13:12
  1. 현재날짜/시간 format대로 출력
  2. 현재 dir가 그 dir가 맞는지
  3. file/folder 있는지 확인후 만들기, 없으면 에러나 만들기
  4. if else 
  5. for loop, while
  6. 외부 프로그램 실행하기
  7. Input parameter받아 command에 넣기
  8. parameter validate하기
  9. website에서 label읽어오기
  10. sleep, timeout = sleep
  11. 외부파일을 읽어서 parameter 순차적으로 읽기



http://en.wikibooks.org/wiki/Bash_Shell_Scripting

http://wiki.bash-hackers.org/syntax/pattern

http://linuxcommand.org/wss0130.php

http://stackoverflow.com/questions/192249/how-do-i-parse-command-line-arguments-in-bash


Bash header, 날짜구하기, 시간

#!/bin/bash
#-------------------------------
# Fred Oh (email) 
# 2015/01/01 starting new life
#-------------------------------
ulimit
today=`date +%m%d`
source ~/.bashrc

today=`date +%m%d_%H%M%S`

$ NOW=$(date +"%m-%d-%Y")

Pattern Matching

#!/bin/bash
#-------------------------------
# Fred Oh (email) 
# 2015/01/01 starting new life
#-------------------------------

au_archive_dir="....../LA.BF64.1.2.1"
branch_name='LA.BF64.1.2.1'
au_prefix='AU_LINUX_ANDROID'

cd $au_archive_dir

post_fix_temp=`ls -t 05.01.00.0[0-9][0-9].[0-9][0-9][0-9] | head -1`
echo $post_fix_temp
#Removing last :, first of all why it ends with :
post_fix="${post_fix_temp//:}"
echo POST_FIX is $post_fix

#Extract only last 3 digit number
#au_number="${post_fix:-3:3}"  doesn't work T.T
au_number="${post_fix:13:3}"
echo TODAY_AU ${today}_au${su_number}


/^([[:Digit:]]{2}\.){3}([[:Digit:]]{3}\.){2}.*$/{
    printf("matches\n");
}

IF/Loop

#!/bin/bash
#-------------------------------
# Fred Oh (email) 
# 2015/01/01 starting new life
#-------------------------------

if [ -d "$buildpath" ]; then
    buildpath="${buildpath}_1"
    echo new $buildpath
fi

count=1
while [[ -d $buildpath ]]; do
    if [ $count == 1 ]; then
        buildpath=${buildpath}_$count
    fi
    buildpath=${buildpath:0:-2}_$count
    let count=count+1
    echo New $buildpath
done
echo Final $buildpath

mkdir $buildpath
cd    $buildpath

echo PWD is $PWD
if ! [ $buildpath == $PWD ]; then
    echo CD failed
    exit 1
else
    echo same directory
fi


taking input parameter

#!/bin/bash
#-------------------------------
# Fred Oh (email) 
# 2015/01/01 starting new life
#-------------------------------
today=`date +%m%d`
source ~/.bashrc

#check input is NULL
if [ -z $1 ]; then
        echo "give me AU label"
        exit 1
fi
echo "AU Lable = $1"

#or check input is NULL or not
if [ "$1" != "" ]; then
    echo "Positional parameter 1 contains something"
else
    echo "Positional parameter 1 is empty"
fi

Sync to latest label and Build

#!/bin/bash
#-------------------------------
# Fred Oh (email) 
# 2015/01/01 starting new life
#-------------------------------

today=`date +%m%d`
source ~/.bashrc

au_archive_dir="...../LA.BF64.1.2.1"
branch_name='LA.BF64.1.2.1'
au_prefix='AU_LINUX_ANDROID'

cd $au_archive_dir
#must be 16 character like 05.01.00.066.083
#Fred don't know why post_fix_temp ends up with ':', need to remove ':'
post_fix_temp=`ls -t 05.01.00.0[0-9][0-9].[0-9][0-9][0-9] | head -1`
echo $post_fix_temp
post_fix="${post_fix_temp//:}"
echo $post_fix

#au_number="${post_fix:-3:3}"  doesn't work T.T
au_number="${post_fix:13:3}"
echo TODAY_AU ${today}_au${su_number}

buildpath="/local/mnt/workspace/hyosubo/8992_au${au_number}"
count=1
while [[ -d $buildpath ]]; do
    if [ $count == 1 ]; then
        buildpath=${buildpath}_$count
    fi
    buildpath=${buildpath:0:-2}_$count
    let count=count+1
    echo new $buildpath
done

mkdir $buildpath
cd    $buildpath

echo PWD is $PWD
if ! [ $buildpath == $PWD ]; then
    echo CD failed $buildpath $PWD
    exit 1
fi


au_name=$au_prefix'_'$branch_name'.'$post_fix
echo $au_name
#/usr/local/bin/repo init -u git://git.quicinc.com/platform/manifest.git -b LA.BF64.1.2.1
/usr/local/bin/repo init -u git://git.quicinc.com/platform/manifest.git -b refs/tags/$au_name -m  versioned.xml
touch README2.txt
/usr/local/bin/repo sync -j8 -q
#/usr/local/bin/repo sync -j8 > reposync_$today.txt
#/usr/local/bin/repo forall -c 'git checkout -b au33 AU_LINUX_ANDROID_KK.04.04.04.010.033'
#/usr/local/bin/repo start tip$today --all
source build/envsetup.sh
lunch msm8992-userdebug
/usr/bin/make -j12 > Buildlog_$today.txt

'Programming' 카테고리의 다른 글

Web Sequence diagram blog에 넣기  (0) 2015.04.16
Popcorn Time clone해서 build하기  (0) 2015.04.14
BAT/CMD windows script to EXE executable converter  (0) 2015.03.17
windows batch file tips  (0) 2015.03.14
syntax highlight test  (0) 2015.03.03
Posted by 쁘레드