常用代码段

常用代码段

  1. 用于找到执行脚本的绝对路径,避免软链接问题

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    #! /bin/bash
    # -*- sh -*-
    # extend the ulimit size, ensure local spark tmp file process
    ulimit -n 65536
    PRG="$0"
    while [ -h "$PRG" ]; do
    ls=`ls -ld "$PRG"`
    link=`expr "$ls" : '.*-> \(.*\)$'`
    if expr "$link" : '.*/.*' > /dev/null; then
    PRG="$link"
    else
    PRG=`dirname "$PRG"`/"$link"
    fi
    done
    PRGDIR=`dirname "$PRG"`
    # 注释的两句可要可不要,是获取脚本名称的
    # PRG_NAME=`basename "$PRG"`
    # PRG_NAME_MAIN="${PRG_NAME%.*}"
    cd $PRGDIR/..
    ROOT_DIR=`pwd -P`

    cd - >/dev/null
  2. 计算时间

    1
    2
    3
    4
    5
    6
    ts=$(date -d ${d} +%s)
    next_day_ts=$(($ts + 86400)) # 后一天的时间戳
    action_time=$(date -d ${d} +"%Y%m")
    cur_import_time="${d}00"
    next_import_time=$(date -d @${next_day_ts} +"%Y%m%d00")

  • 版权声明: 本博客所有文章除特别声明外,著作权归作者所有。转载请注明出处!
  • Copyrights © 2022-2023 ligongzhao
  • 访问人数: | 浏览次数:

请我喝杯咖啡吧~

支付宝
微信