顯示具有 script 標籤的文章。 顯示所有文章
顯示具有 script 標籤的文章。 顯示所有文章

2012年8月13日

FTP上傳備份資料Script


將備份檔案以7zip壓縮並上傳FTP的Script,記綠一下。

backup.sh

#!/bin/bash
bd=$(date +%Y%m%d)
cd /where you want to backup/

tar pcvf - directoryname|7za a -si /bak/directoryname.${bd}.tar.7z

mysqldump -uusername -ppassword dbname > /bak/dbname.${bd}.sql
svnadmin dump /home/svn/repository/project > /bak/project.dump

cd /bak/

HOST='IP'
USER='username'
PASS='password'
ftp -ivn $HOST << EOF
user $USER $PASS
bin
put backupfilename
quit
EOF


Note:FTP常用指令
ls     查看 Server 端的目錄或檔案
pwd    查看 Server 端目前所在的目錄
cd     變更 Server 端目前的目錄
cdup   變更 Server 端目前的目錄到上一目錄
lls    查看 Local 端的目錄或檔案
lcd    變更 Local 端目前的目錄
asc    設定傳輸模式為文字檔方式
bin    設定傳輸模式為二進位檔方式
get    將 Server 端的檔案拷貝至 Local 端現在目錄下
mget   拷貝多個 Server 端的檔案至 Local 端現在目錄下
put    將 Local 端的檔案拷貝至 Server 端現在目錄下
mput   拷貝多個 Local 端的檔案至 Server 端現在目錄下
delete 刪除 Server 端的檔案
mkdir  在 Server 端建立目錄
rmdir  刪除 Server 端的目錄
!      shell 指令
!ls    查看 Local 端的目錄或檔案
prompt 變換交談模式 (on/off),
?,help 指令使用說明
bye    結束 FTP

2010年6月19日

ADSL固定IP自動重撥

So-Net撥接固定IP有時侯會撥到別的IP,此Script是判斷如果IP不是原本那個,就再重撥.

#!/bin/bash


checkip=`/sbin/ifconfig ppp0 grep 'inet addr' sed 's/^.*addr://g' | sed 's/ P-t-P.*$//g'`

if [ "$checkip" != "你的固定IP" ];
then
/usr/sbin/pppoe-stop
/usr/sbin/pppoe-start
sleep 10

if !(cat /proc/net/dev | grep ppp0) > /dev/null 2>&1
then
/usr/sbin/pppoe-stop
/usr/sbin/pppoe-start
fi
fi

2010年5月27日

開機自動執行

apt-get install sysv-rc

/etc/update-rc.d script.sh defaults 50

2010年5月12日

netstat 統計連線狀態數量

netstat -n awk '/^tcp/{++S[$NF]} END {for(a in S) print a,S[a]}'
TIME_WAIT 6
ESTABLISHED 4
LAST_ACK 3

2010年4月28日

網路檢測script

#!/bin/sh
#網路檢測程式 v_0.1
#create by Vega 2005.10.17
#

ip01='1.1.1.1'

net=`ping -c 1 "$ip01"|grep '100% packet loss'`
if [ "$net" != "" ]; then
echo ""$ip01" 無法連線."
echo ""$ip01" 無法連線." > netstate
mail ap -s ""$ip01" 連線異常" < netstate
else
echo "" > netstate
fi

硬碟大小監控script

#!/bin/sh
#
# 網路監控
# 本機硬碟大小監控
# 建立日期 2006.04.21 by Vega

day=`date +%Y%m%d-%R`
cd /root/monitor
df -BMB > df
mail vega,ap -s 硬碟空間-"$day" < df

FTP Script

#!/bin/sh

ftp -inv xx.xx.xx.xx << EOF

-i turns off interactive prompting.
-n Restrains FTP from attempting the auto-login feature.
-v enables verbose and progress.


user temp temp
prompt
verbose
bin
cd l7
mget iptables*
quit
EOF