Shell指令碼美化登入介面裝飾圖(含農曆)_linux shell

來源:互聯網
上載者:User

今天同事閑得無聊,要我幫忙在linux登入頁面裡加點他認為很獨特的東西,看了下他發的東西,對他表示很無語,下面來看看吧.

指令碼1:

cat clcal.sh

#!/bin/bash# show Chinese lunisolar calender.# 2011/11/24## Licensed under GPL version 3##日期資料 {{{# calendar_data format:# +--------+---------+--------------+------------+---------+# |單位(位)|  1-4  |   5-16   |   17   | 18-20 |# +--------+---------+--------------+------------+---------+# | 說 明 |閏月月份 | 每月的大小月 |閏月的大小月|  空  |# +--------+---------+--------------+------------+---------+calendar_data=(0x04bd8 0x04ae0 0x0a570 0x054d5 0x0d260 0x0d950 0x16554 0x056a0 0x09ad0 0x055d20x04ae0 0x0a5b6 0x0a4d0 0x0d250 0x1d255 0x0b540 0x0d6a0 0x0ada2 0x095b0 0x149770x04970 0x0a4b0 0x0b4b5 0x06a50 0x06d40 0x1ab54 0x02b60 0x09570 0x052f2 0x049700x06566 0x0d4a0 0x0ea50 0x06e95 0x05ad0 0x02b60 0x186e3 0x092e0 0x1c8d7 0x0c9500x0d4a0 0x1d8a6 0x0b550 0x056a0 0x1a5b4 0x025d0 0x092d0 0x0d2b2 0x0a950 0x0b5570x06ca0 0x0b550 0x15355 0x04da0 0x0a5b0 0x14573 0x052b0 0x0a9a8 0x0e950 0x06aa00x0aea6 0x0ab50 0x04b60 0x0aae4 0x0a570 0x05260 0x0f263 0x0d950 0x05b57 0x056a00x096d0 0x04dd5 0x04ad0 0x0a4d0 0x0d4d4 0x0d250 0x0d558 0x0b540 0x0b6a0 0x195a60x095b0 0x049b0 0x0a974 0x0a4b0 0x0b27a 0x06a50 0x06d40 0x0af46 0x0ab60 0x095700x04af5 0x04970 0x064b0 0x074a3 0x0ea50 0x06b58 0x055c0 0x0ab60 0x096d5 0x092e00x0c960 0x0d954 0x0d4a0 0x0da50 0x07552 0x056a0 0x0abb7 0x025d0 0x092d0 0x0cab50x0a950 0x0b4a0 0x0baa4 0x0ad50 0x055d9 0x04ba0 0x0a5b0 0x15176 0x052b0 0x0a9300x07954 0x06aa0 0x0ad50 0x05b52 0x04b60 0x0a6e6 0x0a4e0 0x0d260 0x0ea65 0x0d5300x05aa0 0x076a3 0x096d0 0x04bd7 0x04ad0 0x0a4d0 0x1d0b6 0x0d250 0x0d520 0x0dd450x0b5a0 0x056d0 0x055b2 0x049b0 0x0a577 0x0a4b0 0x0aa50 0x1b255 0x06d20 0x0ada00x14b63)gan=('甲' '乙' '丙' '丁' '戊' '己' '庚' '辛' '壬' '癸')zhi=('子' '醜' '寅' '卯' '辰' '巳' '午' '未' '申' '酉' '戌' '亥')sheng_xiao=('鼠' '牛' '虎' '兔' '龍' '蛇' '馬' '羊' '猴' '雞' '狗' '豬')jieqi_name=('小寒' '大寒' '立春' '雨水' '驚蟄' '春分' '清明' '穀雨' '立夏' '小滿' '芒種' '夏至' '小暑' '大暑' '立秋' '處暑' '白露' '秋分' '寒露' '霜降' '立冬' '小雪' '大雪' '冬至')jieqi_data=(0 21208 42467 63836 85337 107014 128867 150921 173149 195551 218072 240693 263343 285989 308563 331033 353350 375494 397447 419210 440795 462224 483532 504758)yueri_name1=('初' '十' '廿' '三' '大' '小' '閏')yueri_name2=('十' '一' '二' '三' '四' '五' '六' '七' '八' '九' '十' '十一' '臘' '正')#農曆節日jieri=([101]='春節' [115]='元宵節' [505]='端午節' [707]='七夕節' [715]='中元節'[815]='中秋節' [909]='重陽節' [1208]='臘八節' [1223]='小年' [100]='除夕')# 公歷節日festival=([101]='元旦' [214]='情人節' [308]='婦女節' [312]='植樹節' [315]='消費者權益日'[401]='愚人節' [501]='勞動節' [504]='青年節' [701]='香港迴歸紀念日 中共誕辰'[707]='抗日戰爭紀念日' [801]='建軍節' [910]='教師節' [918]='九·一八事變紀念日'[1001]='國慶節' [1002]='國慶節假日' [1003]='國慶節假日' [1220]='澳門迴歸紀念'[1224]='平安夜' [1225]='聖誕節')#}}}# 農曆年月日計算函數 {{{# 農曆某年哪個月是閏月,沒有閏為0# which_run_yue nianwhich_run_yue() { echo $((${calendar_data[$1-1900]} & 0xF));}# 農曆某年閏月的天數# days_of_run_rue niandays_of_run_rue() {  (($(which_run_yue $1))) \  && echo $((${calendar_data[$1-1900]} & 0x10000?30:29)) \  || echo 0}# 農曆某年的天數# days_of_nian niandays_of_nian() {  local nian=$(($1-1900))  local sum=0  for ((i=0x8000; i>8; i>>=1)); do    ((${calendar_data[$nian]}&$i)) && ((sum++))  done  echo $(($sum+$(days_of_run_rue $1)+348))}# 顯示幹支名稱# show_ganzhi ganzhi_numshow_ganzhi() {  echo ${gan[$1%10]}${zhi[$1%12]}}# 是否為西曆閏年# is_bissextile yearis_bissextile() {  ((($1%4 == 0 && $1%100 != 0) || $1%400 == 0)) && return 0 || return 1}# 西曆某年年初到某月前一月的天數,一月忽略# sum_to_premonth year monthsum_to_premonth() {  local sum=$(($2-1?($2-1)*30:0))  for ((i=1; i<=($2-1); i++)); do    case $i in      1|3|5|7|8|10|12) ((sum++)) ;;      2) ((sum-=2)) && is_bissextile $1 && ((sum++)) ;;    esac  done  echo $sum}# 計算兩個西曆日期的相差天數# sub_two_date laterDate earlyDatesub_two_date() {  local year1=${1:0:4}  local year2=${2:0:4}  # 兩個年份到年初的天數相減並加上365/366  sum=$(($(sum_to_premonth $year1 10#${1:4:2}) +365 -\    $(sum_to_premonth $year2 10#${2:4:2})))  is_bissextile $year2 && ((sum--))  ((sum+=10#${1:6:2}-10#${2:6:2}))  # 閏年365+1  for ((i=year2+1; i<year1; i++)); do    is_bissextile $i && ((sum++))  done  if (((year1-year2)>0)); then    ((sum+=(year1-year2-1)*365))  elif ((year1==year2)); then    ((sum-=365))  else    echo "input is error."&& exit  fi  echo $sum}# 西曆某年的第n個節氣為幾號(從0小寒算起)# which_day_is_jieqi year nwhich_day_is_jieqi() {  local days_of_permonth=(0 31 28 31 30 31 30 31 31 30 31 30 31)  is_bissextile $1 && ((days_of_permonth[2]++))  # 1900年1月6日2點05分為小寒,精確到分往後推算  local a=$((525948*($1-1900)-$(sub_two_date ${1}0106 19000106)*24*60+${jieqi_data[$2]}+125))  # 若為小寒且在6日00點以前,天數減1  local c=$(($a/(24*60)+6))  (($a<0)) && ((c--))  for ((i=0;i<13 && c>28;i++)); do    ((c-=${days_of_permonth[$i]}))  done  echo $c}# 計算農曆年月日calc_cal() {  local run_yue var1  local is_run_yue=0  local percalc_val=( 0 18279 36529)  local all_days=$(($(sub_two_date $1 19000131)))  # 此處為最佳化演算法,每隔50年置一預計算值,減少碳排放量 ^_^  for ((i=0; i<5; i++)); do    ((${1:0:4}>($i*50+1900) && ${1:0:4}<=(($i+1)*50+1900))) && break  done  ((all_days-=${percalc_val[$i]}))  for ((i=$i*50+1900; all_days>0 && i<2050; i++)); do    var1=$(days_of_nian $i)    ((all_days-=$var1))  done  # --------------------------------------  ((all_days<0))&& {((all_days+=var1)); ((i--));}  year=$i  run_yue=$(which_run_yue $i)  # TODO 此處尚待最佳化  for ((i=1; i<13 && all_days>0; i++)); do    #如果有農曆閏月    if ((run_yue>0 && i==(run_yue+1) && is_run_yue==0)); then      ((--i))      is_run_yue=1      var1=$(days_of_run_rue $year)    else      var1=$(((${calendar_data[$year-1900]} & (0x10000>>$i))?30:29))    fi    ((all_days-=var1))    ((is_run_yue==1 && i==run_yue+1)) && is_run_yue=0  done  ((all_days<0)) && {((all_days+=var1));((i--));}    if ((all_days==0 && run_yue>0 && i==run_yue+1)); then    if ((is_run_yue==1)); then      is_run_yue=0    else      is_run_yue=1      ((--i))    fi  fi  month=$i  ((day=all_days+1))}#}}}# 協助及分析命令列選項 {{{show_help() {cat <<EOF clcal,顯示中國傳統農曆 用法: clcal [-a | -c | -g | -n | -z | -d date | date ] 選項: -g  顯示西曆年月日 -c  顯示農曆年月日 -z  顯示四柱 -a  顯示所有項 -n  不顯示農曆日曆 -d  指定西曆年月日時,格式0000年00月00日00時 -h  顯示此協助EOFexit}while getopts 'acd:ghnz' argv;do  case "${argv}" in    a) SHOW_ALL=true ;;    c) SHOW_CHINESE_DATE=true ;;    d) thisdate="${OPTARG}" ;;    g) SHOW_DATE=true ;;    n) DONOT_SHOW_CHINESE_CALENDAR=true ;;    z) SHOW_SIZHU=true ;;    h) show_help ;;  esac  HAVE_ARG=truedone(($#==1)) && [[ ! $HAVE_ARG ]] && thisdate=$1# }}}# 若沒有輸入則使用當前年月日時thisdate=${thisdate=$(date +"%Y%m%d%H")}calc_cal $thisdate# 計算四柱 {{{## 年柱,以立春劃分,1900年立春後為庚子年nian_zhu=$((${thisdate:0:4}-1900+36))# 調整立春前的年柱(((10#${thisdate:4:2}==2 && 10#${thisdate:6:2}<$(which_day_is_jieqi ${thisdate:0:4} 2)) || 10#${thisdate:4:2}==1)) && ((nian_zhu--))# 月柱,以節(西曆每月的第一個節氣為節,第二個為氣)劃分,1900年1月小寒前一天為丙子月yue_zhu=$(((${thisdate:0:4}-1900)*12+10#${thisdate:4:2}+12))# 調整節前的月柱((10#${thisdate:6:2}<$(which_day_is_jieqi ${thisdate:0:4} $(((10#${thisdate:4:2}-1)*2))))) && ((yue_zhu--))# 日柱,前一天的23時與當天的00時為子時,1900年1月1日為甲戌日ri_zhu=$(($(sub_two_date $thisdate 19000101)+10))# 時柱shi_zhu=$((($(sub_two_date $thisdate 19000101)*24+10#${thisdate:8:2}+1)/2))# }}}# 調整顯示 {{{# 判斷大小月if ((is_run_yue)); then  month_prefix=${yueri_name1[6]}  month_suffix=$((${calendar_data[$year-1900]} & 0x10000?4:5))else  month_suffix=$((${calendar_data[$year-1900]} & 0x10000>>$month?4:5))fi# 判斷“除夕”jieri_index=$(($month*100+$day))if ((month_suffix==4 && jieri_index==1230)); then  jieri_index=100elif ((month_suffix==5 && jieri_index==1229)); then  jieri_index=100fi# 判斷節氣((10#${thisdate:6:2}==$(which_day_is_jieqi ${thisdate:0:4} $(((10#${thisdate:4:2}-1)*2))))) &&\jieqi=${jieqi_name[$(((10#${thisdate:4:2}-1)*2))]}((10#${thisdate:6:2}==$(which_day_is_jieqi ${thisdate:0:4} $(((10#${thisdate:4:2}-1)*2+1))))) &&\jieqi=${jieqi_name[$(((10#${thisdate:4:2}-1)*2+1))]}# 調整日期方便顯示((day==10)) && ((day=0))((day<10)) && day=0$day# }}}# 顯示西曆年月日[[ $SHOW_ALL || $SHOW_DATE ]] &&echo ${thisdate:0:4} ${thisdate:4:2} ${thisdate:6:2}# 顯示農曆年月日[[ $SHOW_ALL || $SHOW_CHINESE_DATE ]] &&echo $year $month $day# 顯示農曆年生肖、月份、日、農曆節日、節氣、西曆節日[[ $SHOW_ALL || ! $DONOT_SHOW_CHINESE_CALENDAR ]] &&echo $(show_ganzhi $nian_zhu)${sheng_xiao[nian_zhu%12]}年$month_prefix${yueri_name2[month==1?month+12:month]}月${yueri_name1[month_suffix]}${yueri_name1[${day:0:1}]}${yueri_name2[${day:1:1}]} ${jieri[$jieri_index]} $jieqi ${festival[10#${thisdate:4:2}*100+10#${thisdate:6:2}]}# 顯示四柱[[ $SHOW_ALL || $SHOW_SIZHU ]] &&echo $(show_ganzhi $nian_zhu)年$(show_ganzhi $yue_zhu)月$(show_ganzhi $ri_zhu)日$(show_ganzhi $shi_zhu)時  exit# vi: set ts=2 sw=2 noet:指令碼2:cat md.sh#!/bin/bash/bin/sh /root/soft_shell/clcal.sh>/root/data.txtda=`cat /root/data.txt|awk '{print $1}'`cat<<EOF                 _oo0oo_                 088888880                 88" . "88                 (| -_- |)                 0\ = /0                ___/'---'\___               .' \\\\|   |// '.              / \\\\||| : |||// \\              /_ ||||| -:- |||||- \\             |  | \\\\\\ - /// |  |             | \_| ''\---/'' |_/ |             \ .-\__ '-' __/-. /            ___'. .' /--.--\ '. .'___           ."" '< '.___\_<|>_/___.' >' "".          | | : '- \'.;'\ _ /';.'/ - ' : | |          \ \ '_.  \_ __\ /__ _/  .-' / /        ====='-.____'.___ \_____/___.-'____.-'=====                 '=---='         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^            佛祖保佑  iii  永不死機               $daEOF

最後在crontab裡定時執行:

crontab -l1 0 * * * /bin/sh /root/soft_shell/md.sh > /etc/motd

下面就是他要的效果圖:

最後我只能說真的是閑得蛋疼.

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.