This belongs to my program,
launched in formality forground: OK
but launched in formality background: suspended
do you have an idea?
the script SFTP_FOR_C1.exp recalled to the inside it is this:
Code:
#!/usr/local/bin/expect -f #<---insert here your expect program location
# procedure to attempt connecting; result 0 if OK, 1 elsewhere
proc connect {passw} {
expect {
-re ".*Are.*.*yes.*no.*" {
send "yes\r"
exp_continue
}
-re ".*PASSWORD.*" {
send "$passw\r"
expect {
"sftp*" {
return 0
}
}
}
-re ".*password.*" {
send "$passw\r"
expect {
"sftp*" {
return 0
}
}
}
-re ".*Password.*" {
send "$passw\r"
expect {
"sftp*" {
return 0
}
}
}
}
# timed out
return 1
}
# read the input parameters
set user [lindex $argv 0]
set passw [lindex $argv 1]
set host [lindex $argv 2]
set remotepath [lindex $argv 3]
set localpath [lindex $argv 4]
set file1 [lindex $argv 5]
set file2 [lindex $argv 6]
# check if all were provided
if { $user == "" || $passw == "" || $host == "" || $remotepath == "" || $localpath == "" || $file1 == "" } {
puts "Usage: <user> <passw> <host> <remote path> <local path> <file to send> [<file to send>]\n"
exit 1
}
# sftp to specified host and send the files
spawn /usr/local/bin/sftp $user@$host
set rez [connect $passw]
if { $rez == 0 } {
send "lcd $localpath\r"
send "cd $remotepath\r"
set timeout -1
send "put $file1\r"
if { $file2 != "" } {
send "put $file2\r"
}
send "quit\r"
expect eof
exit 0
}
puts "\nError connecting to server: $host, user: $user and password: $passw!\n"
exit 2
##### Constants
# recupero properties da file
. ../cfg/init.cfg
function CopyC1
{
for dir in ${dir_list}
do
LPATH=${PARTIALPATH}${dir}
cd ${LPATH}
gunzip *.gz
PRODNUM=`ls -1 | grep "\.cdr$" | wc -l | awk '{print $1}'`
writeInfo "Numero dei file pronti per essere inviati: ${PRODNUM}"
STARTTIME=$Now
writeInfo "Connessione SFTP e trasferimento files start: $STARTTIME..."
writeInfo "=========================================================================================="
SFTPLOG=`${EXEPATH}SFTP_FOR_C1.exp ${USER} ${PASS} ${HOST} ${RPATH} ${LPATH} '*.cdr'`
writeInfo "USER : ${USER}"
writeInfo "PSWD : ${PASS}"
writeInfo "HOST : ${HOST}"
writeInfo "RPATH: ${RPATH}"
writeInfo "LPATH: ${LPATH}"
SFTPNUM=`echo "${SFTPLOG}" | grep "100%" | wc -l | awk '{print $1}'`
RepDate=`date +%y%m%d-%H%M%S`
echo "${STARTTIME}|${RepDate}|SFTP_START|SFTP_END|${PRODNUM}|${SFTPNUM}" >> ${SPLFILE}
if [ ${SFTPNUM} -ne ${PRODNUM} ]
then
writeError "ERRORE: numero file trasferiti (${SFTPNUM}) diverso da quello atteso (${PRODNUM})!"
Close 2
fi
writeInfo "Numero file trasferiti: ${SFTPNUM}"
writeInfo "Compressione file"
gzip *.*
VARSLEEP=`grep -i SLEEP ${FILE_CFG} | cut -f2 -d =`
writeInfo "Tempo di sleep: ${VARSLEEP}"
sleep ${VARSLEEP}
writeInfo "=========================================================================================="
done
Close 0
}