2016年12月30日 星期五

Docker Save, Export 差別

docker save [ID or Name] > image.tar
docker load <image.tar
所有dockfile 設定保留

docker export [ID or Name] > image.tar
cat image.tar | docker import - some_image_name
所有dockfile 設定全去除

2016年12月15日 星期四

Bash筆記:Linux 一般帳號 mount cifs


限制
1.只能掛載至登入帳號擁有的目錄下
2.配合 sudo 使用

cifsmount.sh 
E_STAT=/usr/bin/stat;
E_MOUNT=/bin/mount;
E_GREP=/bin/grep;
E_WHOAMI=/usr/bin/whoami;

# Check_Mount ='' do'nt check Mounted;
Check_Mount='1';

function help(){ echo Usage: $0 {service} {mount-point} [password];
  echo exp:;echo  $0 user@//server-name/share-name /home/user;echo $0 user@//server-ip/share-name /home/user password;
};

[ -z $2 ] && { help;exit 1;};
[ -d $2 ] && { Username=${1%@*};Share=${1##*@};}||{ echo "Couldn't chdir to $2: No such directory"; exit 2;};

[ -z "$Share" ] && { help;exit 5;};
[ -z "$Check_Mount" ] || [ -z "$($E_MOUNT|$E_GREP "$Share/ on $2 type cifs")" ]||{ echo "$Share had mounted on $2"; exit 4;};

[ "$SUDO_USER" == "" ] && Real_USER=$($E_WHOAMI)|| Real_USER=$SUDO_USER;
[ "$($E_STAT -c '%U' $2 2>/dev/null)" == "$Real_USER" ]||{ echo "Couldn't chdir to $2: not owner"; exit 3;};

[ -z $3 ] && { :;
_Cmd="$E_MOUNT -t cifs $Share $2 -o uid=$Real_USER,username=$Username";}||{ :;
_Cmd="$E_MOUNT -t cifs $Share $2 -o uid=$Real_USER,username=$Username,password=$3";};
$_Cmd;


cifsumount.sh
E_GREP=/bin/grep;
E_MOUNT=/bin/mount;
E_UMOUNT=/bin/umount;
E_STAT=/usr/bin/stat;
E_WHOAMI=/usr/bin/whoami;

function help(){ echo Usage:$0 {mount-point};echo exp:;echo $0 /home/user;};

[ -z $1 ] && { help;exit 1;};
[ -z "${_T:=$($E_MOUNT | $E_GREP " on $1 type cifs ")}" ] && { echo $1 not mount or not mount on cifs; exit 2;};

[ "$SUDO_USER" == "" ] && Real_USER=$($E_WHOAMI)|| Real_USER=$SUDO_USER;
[ "$($E_STAT -c '%U' $1 2>/dev/null)" == "$Real_USER" ]||{ echo "Couldn't umount $1: not owner"; exit 3;};

_cmd="$E_UMOUNT $1 $2";
$_cmd;

去除 ^M

tr -d "\r" < dos_file  > file

sed  "s/\r//" dos_file  > file

dos2unix filename

sudo 不輸入密碼

編輯 /etc/sudoers 加入 ALL ALL=NOPASSWD: /usr/local/bin/script.sh

cifs mount 選項參數

uid 更改目錄擁有者
dir_mode 更改目錄權限
file_mode 更改檔案權限
username 登入帳號
password 登入密碼

2016年12月14日 星期三

Bash 設定未定義變數值

a="123"
variable=$(( $a == 123 ? 1 : 0 ))
echo $variable

echo b=$b
: ${b:=$(whoami)}
echo b=$b