Skip to main content

Sample Scripts

線上範例
Auto-rar.sh

解壓縮多個分割檔案 (*.part0XX.rar)

#!/bin/bash

echo "-> Started: "`date +%m/%d/%y\ %H:%M\ %Z`
echo "-> As:"`whoami`

i=1
ARCHIVES="$@"
for f in $ARCHIVES; do
   PARTCHECK=$(expr "$f" : ".*\([Pp][Aa][Rr][Tt][0-9]\+\.[Rr][Aa][Rr]\)")
   RARCHECK=$(expr "$f" : "\(.*\.[Rr][Aa][Rr]\)")
   echo "-> Processing($i of $#): $f"

   if [ "$PARTCHECK" ] && [ -f $f ]; then
      echo "-> Extracting Multipart Archive"
      unrar x $f
      if [ $? -eq 0 ]; then
           FILES=$(expr "$f" : "\(.*[Pp][Aa][Rr][Tt]\).*")
           echo "-> Extraction Successful"
           echo "-> Removing $FILES*.rar"
           rm $FILES*.rar
      else
           echo "-> **Extraction Failed"
           exit 1
      fi
   else
      if [ "$RARCHECK" ] && [ -f $f ]; then
         echo "-> Extracting Single Archive"
         unrar x $f
         if [ $? -eq 0 ]; then
             echo "-> Extraction Successful"
             echo "-> Removing $f"
             rm $f
         else
             echo "-> **Extraction Failed"
             exit 1
         fi
      fi
   fi
      echo ""
      i=$(( i+1 ))
done
Domaincheck.sh
#!/bin/bash

#Specify all the domains you want to check
DOMAINS="google.com dribbble.com facebook.com youtube.com"

current_epoch=`date '+%s'`
for dm in $DOMAINS
do
  expiry_date=`whois $dm | egrep -i "Expiration Date:|Expires on"| head -1 | awk '{print $NF}'`
  echo -n " $dm - Expires on $expiry_date "
  expiry_epoch=`date --date="$expiry_date" '+%s'`
  epoch_diff=`expr $expiry_epoch - $current_epoch`
  days=`expr $epoch_diff / 86400`
  echo " $days days remaining. "
done
Scripting Basics

bash_scripting_basics.jpg