Hi All,
The final SFTP program can look like this;
sftp -b - server-1 <<-EOF
get /root/restore/$each.tar
bye
EOF
Describing the above program with the (space)/(no-space)/(no-characters) characters to make it more clear to understand the code; (space) means either a whitespace / a tab.
sftp -b - server-1(space)<<
-EOF
(no-space)(no-characters)
(space)get /root/restore/$each.tar(space)
(space)bye(space)
(no-space)(no-characters)EOF
(no-space)(no-characters)
-------------------------------------------
In addition, here is some sample programs for you to test; Hope with this you may undestand the usage of "heredocument". It's better always use a '-' after << and before the first CONTENT tag
Program 1
RESULT="`sqlplus $USER/$PWD@$TNS <<-CONTENT
select sysdate from dual;
exit;
CONTENT
`";
echo "$RESULT"
Never add any other characters to the second tag (Eg:- Never do this [ CONTENT`";]. You will get error.
Describing the above program with the (space)/(no-space) characters;
RESULT="`sqlplus
$USER/$PWD@$TNS(space)<<-
CONTENT(no-space)
(space)select sysdate from dual;(space)
(space)exit;(space)
(no-characters)(no-space)CONTENT
(no-space)(no-characters)
(space)`";(space)
echo "$RESULT"
-----------------------------------------------------------
Program 2
cat <<-CONTENT
echo "Hello Foo"
echo "Hello"; Hello "Foo";
CONTENT
CONTENT"
CONTENT
Describing the same program with the (space)/(no-space) characters;
cat(space)<<-CONTENT
(no-space)
(no-space)echo "Hello Foo"(no-space)
(no-space)echo "Hello"; Hello "Foo";(no-space)
(space)(space)CONTENT(no-space)
(no-space)CONTENT
"(no-space)
(no-space)CONTENT
(no-space)
Only the Final CONTENT will match with the First CONTENT tag. Others have either a whitespace / a character attached to it and the KSH will not be able to recognise it, because it considers the whole as a string which doesn't match with the string CONTENT.
Output of the above program
echo "Hello"; Hello "Foo";
CONTENT
CONTENT"
To Conclude the CONTENT tag should not be attached with any characters including white space. Always use the '-' afterthe << and before the first CONTENT tag
Eg:-
cat <<-CONTENT
resolved
CONTENT
Description
cat(space)<<-CONTENT
(no-space)(no-characters)
(space)(space)(space)(space)resolved(space)(space)(space)(any-characters)
(no-characters)(no-space)CONTENT
(no-space)(no-characters)
Result follows;
resolved