Dear Sirs,
would like to seek advise.
how to log the sftp output.
#!/usr/bin/bash
Date='date +%Y%m%d'
mkdir -p "/appl/scripts/ftp/logs/ftp-$Date"
LOGFILE=/appl/scripts/ftp/logs/ftp-$Date
while read -r server2
do
sftp etpuser@"$server2" << "_EOSFTP_"
cd /test2
lcd /test3
mget * >> $LOGFILE
done
_EOSFTP_
done < server2
i tried to run the script, i m getting error
Multiple source paths, but destination ">>" is not a directory
Invalid command.
sftp> done
thank yousss Sirs
Please use some code validator for your shell scripts, e.g. ShellCheck.net
#!/usr/bin/env bash
Date=$(date +'%Y%m%d')
mkdir -p "/appl/scripts/ftp/logs/"
LOGFILE=/appl/scripts/ftp/logs/ftp-"$Date"
while read -r server_name
do
sftp etpuser@"$server_name" << "_EOSFTP_"
cd /test2
lcd /test3
mget *
_EOSFTP_
done < server2 >> "$LOGFILE"
1 Like
apple08
February 5, 2025, 10:12am
3
Dear Sirs,
i have tried to ammend , forg8 comments.
#!/usr/bin/bash
Date='date +%Y%m%d'
mkdir -p "/appl/scripts/ftp/logs/ftp-$Date"
cd /appl/scripts/ftp/logs/ftp-"$Date" || exit
while read -r server2
do
sftp etpuser@"$server2" > ftp-"$Date" << "_EOSFTP_"
cd /test2
lcd /test3
mget *
done
_EOSFTP_
done < server2
thank youssss Sirs
This is not the code I posted above. Anyway...
Date='date +%Y%m%d'
this line will not work, because single quote ' is not backtick `, so this is incorrect syntax for command substitution.
sftp etpuser@"$server2" > ftp-"$Date" << "_EOSFTP_"
this line will constantly overwrite the file ftp-"$Date"
, as redirection is not an appending one (apart from Date
variable not storing the correct value, see above).
Is your input data file named server2
? Does it contain valid hostnames/IP addresses?
3 Likes
apple08
February 18, 2025, 5:20am
5
thank yousss so much Sir for g8 expertise. truly appreciate it.