get_task_id 脚本内容

#!/usr/bin/expect
#配置登陆数据库的端口
set port 22
#配置登陆数据库的ip地址
set oracleip 10.0.4.41
#配置数据库实例名
set DSN bms
#配置数据库用户名
set username sa
#配置数据库登陆密码                                                                                                                                                            
set password oracle
spawn ssh -p $port oracle@$oracleip
expect {
  "yes/no" {send "yes\r"}
  "*Password: " {send "oracle\r"}
 }
expect "oracle@linux*"
send "sqlplus $username/$password\r"
expect "SQL>"
send "spool taskid.txt\r"
send "select task_id from data_task_records where task_source=2 and download_flag=0 and task_state=0;\r"
send "spool off\r"
send "quit\r"
spawn scp oracle@$oracleip:/home/oracle/taskid.txt .
expect "Password: "
send "oracle\r"
expect eof

task_file脚本内容

#!/bin/bash
#配置任务需要的号码文件个数(不包括0文件)
numfile=1
#配置号码文件的大小
taskfilesize='158'
#配置号码文件下载的ftp服务器的ip地址
ftpip='10.0.4.41'
#配置号码文件下载的ftp服务器的用户名
ftpname='msgplus'
#配置号码文件下载的ftp服务器登陆密码
ftppswd='cdsf119'
#配置延迟时间长短(s:秒,m:分钟)
delay='5m'
#ftp上传的路径
upload_file='/home/msgplus/sp/task'
#本地文件命名
file_name='11.txt'


Upload_ftp_task_file()
{
 ftp -i -n $ftpip <<EOF
 user $ftpname $ftppswd
 cd $upload_file
 put $taskname
 bye
EOF
}
Create_task_file()
{
 taskid=$(grep "^    [0~9]*" taskid.txt)
 for list in $taskid
 do
  for ((i=$numfile;i>=0;i=i-1))
  do
    case `expr length "$i"` in
    1)
    taskname=$list'_RECEPTOR_000'$i'_'$taskfilesize'.txt';;
    2)
    taskname=$list'_RECEPTOR_00'$i'_'$taskfilesize'.txt';;                                                                                                                     
    esac   
    cp $file_name $taskname
    Upload_ftp_task_file $ftpip $ftpname $upload_file $ftppswd $taskname
    echo `date "+%Y-%m-%d %H:%M:%S"`" 任务$list上传号码文件$taskname成功" >>file.log
    rm $taskname
  done
 done
}

main ()
{
 touch file.log
 while true
 do
  expect -f get_task_id.sh
  Create_task_file $numfile $taskfilesize $file_name
  sleep $delay
 done
}
main $delay