2020年8月27日 星期四

sudo 傳入環境變數

使用方式
sudo --preserve-env=HOME /usr/bin/env
sudo ZEBRA=true /usr/bin/env

修改 /etc/sudoers
ALL ALL=NOPASSWD:SETENV:/bin/mount

2020年8月26日 星期三

pypi mirror site 建置

安裝
mkdir -p /home/pypi
cd /home/pypi 

apt-get install python3-venv
python3 -m venv bandersnatch
bandersnatch/bin/pip install bandersnatch
bandersnatch/bin/bandersnatch mirror  建立設定檔  /etc/bandersnatch.conf
bandersnatch/bin/bandersnatch mirror  #執行 mirror 工作

可在 /etc/crontab 中增加設定
* */1 * * * root bandersnatch mirror |& logger -t bandersnatch[mirror]

client 設定
~/.pip/pip.conf
[global]
trusted-host=10.10.10.10 
index-url=http://10.10.10.10/simple

2020年8月24日 星期一

bash ldapsearch 網域帳號認證

#!/bin/bash

_timeout="/usr/bin/timeout 3"
_ldapsearch=/usr/bin/ldapsearch

user=${1%@*}
_dn=${1#*@};
_dbn=$(for i in $(echo $_dn|tr . " ");do t="$t dc=$i";done;echo $t|tr " " ,);

t=$($_timeout $_ldapsearch -D ${1} -w ${2} -b "$_dbn" -h ${_dn} "sAMAccountname=$user"
 2>/dev/null|grep "sAMAccountName: $user");
[ "$t" = "sAMAccountName: $user" ]&&echo -e "OK"&&exit 0;

echo -e "ERR";



2020年8月23日 星期日

sqlite3 查詢筆記

 .tables
.schema(table_name);
PRAGMA table_info('table_name')

2020年8月20日 星期四

2020年8月19日 星期三

sudo 指令傳入環境變數

 錯誤訊息

sudo: sorry, you are not allowed to preserve the environment

編輯 /etc/sudoers
user  ALL=(ALL)       NOPASSWD:SETENV: /usr/bin

執行方式
sudo var=varvalue 1.sh