0

Code is working very slow. and output is not as expected, getting only two files in output directory instead of 4. Since i have 4 servers so i should get 4 files. Seems it is creating output file for only first and last server.

Log_report.sh:

#!/bin/bash
MAIN_PATH=/migration/CS_ETL/DM_AUTOMATION
file`enter code here`name='FTP_config.csv'
n=1
while read line; do
IP="`echo $line | awk -F"," '{print $1}'`"
echo $IP
USER_NAME="`echo $line | awk -F"," '{print $2}'`"
PASS_KEY="`echo $line | awk -F"," '{print $3}'`"
SCP_PATH="`echo $line | awk -F"," '{print $4}'`"
CBP_PATH="`echo $line | awk -F"," '{print $5}'`"
CBP_ID="`echo $line | awk -F"," '{print $6}'`"
REMOTE_TOOL_PATH="`echo $line | awk -F"," '{print $7}'`"
MASTER_BACKUP="`echo $line | awk -F"," '{print $8}'`"
./Log_sftp.sh $IP $USER_NAME $PASS_KEY $SCP_PATH $CBP_PATH $CBP_ID $REMOTE_TOOL_PATH $MASTER_BACKUP
n=$((n+1))
mv $MASTER_BACKUP/Exception.log $MASTER_BACKUP/Exception_$CBP_ID.log
done < $MAIN_PATH/TASK/$filename

Log_sftp.sh:

#!/usr/bin/expect -f

set username [lindex $argv 1];
set password [lindex $argv 2];
set ip [lindex $argv 0];
set scp_path [lindex $argv 3];
set cbp_path [lindex $argv 4];
set cbp_id [lindex $argv 5];
set slave_path [lindex $argv 6];
set master_bkp [lindex $argv 7];

spawn sftp $username@$ip:$slave_path/Logs
expect "password: "
send $password\r
expect "$ "
set timeout -1
send "lcd $master_bkp\r"
send "get Exception.log\r"
send "exit\r"
expect "$ "
  • [How do I format my code blocks?](https://meta.stackexchange.com/questions/22186/how-do-i-format-my-code-blocks) – Cyrus May 21 '20 at 10:01
  • I tried to format it. but not able to bring the first script in the formatted code – Sumit Kumar Gupta May 21 '20 at 10:16
  • @Cyrus do you know anyone who can help? – Sumit Kumar Gupta May 21 '20 at 12:23
  • "not as expected getting only two files in output directory" Could you clarify what you mean by this? I see only "get" command in your expect script. Really, you should [edit] your question to provide more detail on what your program is supposed to do and what it's actually doing. – Kenster May 21 '20 at 13:16
  • @Kenster I have edited the question, please let me know whether it's clear. I think the mv command is getting skipped for 2nd and 3rd server in Log_report.sh, and expect is making my script very slow. it is waiting for sometime before executing commands – Sumit Kumar Gupta May 21 '20 at 13:29
  • @kenster did i make it clear? – Sumit Kumar Gupta May 21 '20 at 17:22

1 Answers1

0

Have you tried using autoexpect -p to see what would be generated when you try doing this interactively?

You may also want to use log_file to debug what's happening with your script.

If it's behaving slowly that's probably an indication of expect timing out. Try adding a

set timeout 2

line to see whether it runs more quickly. If it does then probably one of your expect patterns is wrong.

BernardF
  • 21
  • 3