shell
code style
缩进为两个空格
if [condition]; then # ;then写在一行
while condition; do # ;then写在一行以一下脚本为例
# 为了模块化 # 是导入当前目录下的utils.sh脚本
例子
将某个目录下的某类型的文件都搞到一个文件中
bash的{}扩展
判断是否存在
Last updated
缩进为两个空格
if [condition]; then # ;then写在一行
while condition; do # ;then写在一行 # 为了模块化
# 是导入当前目录下的utils.sh脚本Last updated
#!/bin/bash
. ./utils.sh
path=${PWD}"/../"
today(){
echo $(date +%Y-%m-%d)
}
yesterday(){
echo $(date -d yesterday +%Y-%m-%d)
}
scrapy_data(){
start_date=$1
end_date=$2
cd $path
echo "log: scrapy ${start_date} ~ ${end_date} data"
scrapy crawl paper_edu_spider -a start_date=$start_date -a end_date=$end_date
}
scrapy_today(){
scrapy_data $(today) $(today);
}
scrapy_yesterday(){
scrapy_data $(yesterday) $(yesterday);
}
if [ ! "$1" ]; then
echo "-h for help"
exit 1
fi
while getopts "hty" arg; do
case $arg in
t)
scrapy_today;
;;
y)
scrapy_yesterday;
;;
h)
echo "usage:"
echo " use -t to scrapy today"
echo " use -y to scrapy yesterday"
;;
?)
echo "-h for help"
exit 1
;;
esac
donecp xxx/{a,b} --> cp xxx/a xxx/bif [ -d /opt/python_env/duoduo369 ];thenif [ -e /run/duoduo369-supervisord.pid ] ;then