代码:
#!/bin/bash
target=$1
# Get the expiration date
expdate=$(whois $1 | grep -iE 'expir.*date|expir.*on' | head -1 | grep -oE '[^ ]+$')
# Turn it into seconds (easier to compute with)
expdate=$(date -d"$expdate" +%s)
# Get the current date in seconds
curdate=$(date +%s)
# Print the difference in days
echo $(((expdate-curdate)/86400))
执行结果:
./a.sh 163.com
1320