自动从FTP服务器下载Oracle安装文件的shell脚本

问题:网上找到的ftp自动下载脚本多采用命令直接重定向的方式,保存到Redhat 6.3服务器执行总报错

解决:临时生成用于重定向的命令文本,自动执行后删除

1、检查/创建本地目录

if [ ! -d "/data" ]
then
    echo "not exist directory /data, could not continue "
    exit
fi
if [ ! -d "/data/soft" ]
then
    mkdir -p /data/soft
    chown -R oracle:oinstall /data/
    cd /data/soft
else    
    echo "/data/soft is exist"
fi

2、检查Linux和Oracle安装文件是否已存在

file0=1
if [ ! -f "/data/soft/rhel-server-6.3-x86_64-dvd.iso" ]
then
    file0=0
fi
file1=1
if [ ! -f "/data/soft/p13390677_112040_Linux-x86-64_1of7.zip" ]
then
    file1=0
fi
file2=1
if [ ! -f "/data/soft/p13390677_112040_Linux-x86-64_2of7.zip" ]
then
    file2=0
fi

3、若Linux和Oracle安装文件不齐,则使用ftp下载

if [ $(($file0 + $file1 + $file2)) -lt 3 ]
then
    echo "open ip地址" > ftp25.txt
    echo "user 帐号 密码" >> ftp25.txt 
    echo "binary" >> ftp25.txt 
    echo "cd 路径" >> ftp25.txt 
    if [ $file0 -eq 0 ]
    then
        echo "get rhel-server-6.3-x86_64-dvd.iso" >> ftp25.txt 
    fi    
    if [ $file1 -eq 0 ]
    then
        echo "get p13390677_112040_Linux-x86-64_1of7.zip" >> ftp25.txt 
    fi    
    if [ $file2 -eq 0 ]
    then
        echo "get p13390677_112040_Linux-x86-64_2of7.zip" >> ftp25.txt 
    fi    
    echo "close" >> ftp25.txt 
    echo "bye" >> ftp25.txt 
    ftp -n < ftp25.txt
    rm -f ftp25.txt
fi

4、解压Oracle安装文件

if [ ! -d "/data/soft/database" ]
then
    unzip /data/soft/p13390677_112040_Linux-x86-64_1of7.zip -d /data/soft
    unzip /data/soft/p13390677_112040_Linux-x86-64_2of7.zip -d /data/soft
fi

 

posted on 2015-10-14 21:29  波谲云诡  阅读(392)  评论(0)    收藏  举报