January 24 2018 Wednesday
Weather:overcast !
1、需求: 打印一个正三角形(即等边三角形),元素使用*代替;[aming@Dasoncheng ~]$ cat b.sh #!/bin/bash##Print a sanjiaoxingread -p "Please input the lenth:" nfor i in `seq 1 $n` ;do for ((j=$n;j>i;j--)); do echo -n " " done for m in `seq 1 $i`; do echo -n "* " done echodone
[aming@Dasoncheng ~]$ sh b.sh Please input the lenth:5 * * * * * * * * * * * * * * *
2、需求:
域名到期提醒。查询指定域名的过期时间,并在到期前一周,每天发一封提醒邮件。 思路:在Linux环境下使用命令“whois domain_name”,如“whois apelearn.com”获取域名相关信息;(感觉答案写的很好,使用了先判断是否有whois命令+函数+时间戳)[aming@Dasoncheng ~]$ cat c.sh #!/bin/bashY=`date +%Y`M=`date +%m`D=`date +%d`T=`whois apelearn.com |grep 'Registry Expiry Date' |awk '{print $4}' |awk -F 'T' '{print $1}'`Y1=`echo $T |awk -F '-' '{print $1}'`M1=`echo $T |awk -F '-' '{print $2}'`D1=`echo $T |awk -F '-' '{print $3}'`Y2=$[ $Y1 - $Y ]M2=$[ $M1 - $M ]D2=$[ $D1 - $D ]D3=$[ $D1 + 30 - $D ]if [ $Y2 -eq 0 ];then if [ $D1 -gt 7 ]; then if [ $M2 -eq 0 ] && [ $D2 -le 7 ]; then python \/usr\/local\/sbin\/mail.py inbox@163.com "email tatil" "contents" fi else if [ $M2 -eq 1] && [ $D3 -le 7 ]; then python \/usr\/local\/sbin\/mail.py inbox@163.com "email tatil" "contents" fi fifi
参考答案:
1、
#!/bin/bashread -p "please input the lenth:" nfor i in `seq 1 $n`do for ((j=$n;j>i;j--)) do echo -n " " done for m in `seq 1 $i` do echo -n "* " done echodone
2、
[aming@Dasoncheng ~]$ cat e.sh #!/bin/basht1=`date +%s`is_install_whois(){ which whois >/dev/null 2>/dev/null if [ $? -ne 0 ] then yum install -y jwhois fi}notify(){ e_d=`whois $1|grep 'Expiry Date'|awk '{print $4}'|cut -d 'T' -f 1` e_t=`date -d "$e_d" +%s` n=`echo "86400*7"|bc` e_t1=$[$e_t-$n] if [ $t1 -ge $e_t1 ] && [ $t1 -lt $e_t ] then /usr/local/sbin/mail2.py aming_test@163.com "Domain $1 will be expire." "Domain $1 expire date is $e_d." fi}is_install_whoisnotify aminglinux.com