Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info

READ-ONLY-MODE: PLEASE DO NOT POST NEW STUFF!
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile       

The time now is Mon 10 Aug 2020, 04:21
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
heredocs ftp and variables
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 1 [6 Posts]  
Author Message
Eesmets

Joined: 18 Jun 2020
Posts: 13

PostPosted: Mon 06 Jul 2020, 11:58    Post subject:  heredocs ftp and variables
Subject description: SOLVED!
 

I have a yad list gui which receives output from the ftpdo function. I want to send commands to the ftpdo function from a another yad gui. The problem is my heredocs EOF statement does not expand the variables from the yad gui.
What's wrong with it?
Code:
function ftpdo (){
ftp -inv "$1" "$2" <<"EOF" | while read line; do svgnum $line; export cnt=$((cnt + 1)); done > /tmp/listpipe
user $3 $4
$5
$6
ls
EOF
}
export -f ftpdo

function ftpfn (){
HOST="$(cat /tmp/ftp | cut -f1 -d'|')"
PORT="$(cat /tmp/ftp | cut -f2 -d'|')"
USER="$(cat /tmp/ftp | cut -f3 -d'|')"
PASSWORD="$(cat /tmp/ftp | cut -f4 -d'|')"
EXEC1="$("$1")"
EXEC2="$($2)"   

[ ! -f /tmp/FTP ] && yad  \
--form \
--field="HOST" "$HOST" \
--field="Port" "$PORT" \
--field="USER:H" "$USER" \
--field="PASSWORD:H" "$PASSWORD" \
--field="EXEC1" "$EXEC1" \
--field="EXEC2" "$EXEC2" \
--field="Do:FBTN" "bash -c \"ftpdo "%1" "%2" "%3" "%4" "%5" "%6" \"" \
--columns=2 > /tmp/ftp
touch /tmp/FTP
case $? in
0) rm -f /tmp/FTP;;
1) rm -f /tmp/FTP
exit;;
esac
}
export -f ftpfn
Back to top
View user's profile Send private message 
phat7

Joined: 05 Jun 2015
Posts: 184

PostPosted: Mon 06 Jul 2020, 20:59    Post subject: Re: heredocs ftp and variables
Subject description: SOLVED!
 

Eesmets wrote:
Subject description: SOLVED!

Question
Back to top
View user's profile Send private message 
Eesmets

Joined: 18 Jun 2020
Posts: 13

PostPosted: Tue 07 Jul 2020, 01:06    Post subject:  

Shortly after posting I found a solution. I had to double quote the variaables within the EOF statement. But it's not perfect .... spaces are treated as seperate arguments when reaching the function.
Back to top
View user's profile Send private message 
misko_2083


Joined: 08 Nov 2016
Posts: 114

PostPosted: Tue 07 Jul 2020, 08:13    Post subject:  

Eesmets wrote:
Shortly after posting I found a solution. I had to double quote the variaables within the EOF statement. But it's not perfect .... spaces are treated as seperate arguments when reaching the function.


Send the fields as a file to the function.


Code:

function ftpdo (){
local field _HOST _PORT _USER _PASS _EXEC1 _EXEC2
for field in _HOST _PORT _USER _PASS _EXEC1 _EXEC2
     do
        read -s $field
done
ftp -inv "$_HOST" "$_PORT" <<"EOF" | while read line; do svgnum $line; export cnt=$((cnt + 1)); done > /tmp/listpipe
user $_USER $_PASS
$_EXEC1
$_EXEC2
ls
EOF
}
export -f ftpdo

function ftpfn (){
HOST="$(cut -f1 -d'|' /tmp/ftp)"
PORT="$(cut -f2 -d'|' /tmp/ftp)"
USER="$(cut -f3 -d'|' /tmp/ftp)"
PASSWORD="$(cut -f4 -d'|' /tmp/ftp)"
EXEC1="$("$1")"
EXEC2="$($2)"   

[ ! -f /tmp/FTP ] && yad  \
--form \
--field="HOST" "$HOST" \
--field="Port" "$PORT" \
--field="USER:H" "$USER" \
--field="PASSWORD:H" "$PASSWORD" \
--field="EXEC1" "$EXEC1" \
--field="EXEC2" "$EXEC2" \
--field="Do:FBTN" \
'bash -c "ftpdo <<EOF
"%1"
"%2"
"%3"
"%4"
"%5"
"%6"
EOF
" ' \
--columns=2 > /tmp/ftp
touch /tmp/FTP
case $? in
0) rm -f /tmp/FTP;;
1) rm -f /tmp/FTP
exit;;
esac
}
export -f ftpfn


edit I think I finaly got the right quoting
Back to top
View user's profile Send private message 
Eesmets

Joined: 18 Jun 2020
Posts: 13

PostPosted: Tue 07 Jul 2020, 12:59    Post subject:  

Hi misko_2083

I tried your code, which at first didn't seem to work, finally unquoting "EOF" > EOF did work. So now sending the command works as desired. However a new problem arose with the output not showing correctly in the column list, but using tee I was able to capture the output to a file, which appears as expected,

Code:
function ftpdo (){
local field _HOST _PORT _USER _PASS _EXEC1 _EXEC2 _EXEC3 _EXEC4
for field in _HOST _PORT _USER _PASS _EXEC1 _EXEC2 _EXEC3 _EXEC4
     do
        read -s $field
done
ftp -inv "$_HOST" "$_PORT" <<EOF | tee $track/stuff | while read line; do svgnum $line; export cnt=$((cnt + 1)); done
user $_USER $_PASS
$_EXEC1
$_EXEC2
$_EXEC3
$_EXEC4
EOF
}
export -f ftpdo


Code:

ls DCIM/Camera

(tee redirected output)

Connected to 192.168.43.1.
220 Service ready for new user.
331 User name okay, need password for marcos.
230 User logged in, proceed.
200 Command PORT okay.
150 File status okay; about to open data connection.
drwx------   3 user group            0 Jul  4 08:57 cache
-rw-------   1 user group      5170040 Apr 19  2019 IMG_20190419_181408.jpg
-rw-------   1 user group      5115968 Apr 19  2019 IMG_20190419_181506.jpg
-rw-------   1 user group      5279320 Apr 19  2019 IMG_20190419_181507.jpg
-rw-------   1 user group      5584121 Apr 19  2019 IMG_20190419_181521.jpg
-rw-------   1 user group      7895737 Apr 19  2019 IMG_20190419_183633.jpg
-rw-------   1 user group      9781535 Apr 19  2019 IMG_20190419_183640.jpg
-rw-------   1 user group       139264 Jul  6 13:06 typescript
226 Closing data connection.
221 Goodbye.



EDIT: there are missing quotes in my code @ svgnum "$line" ... now everything works great!

Thanks again
Eesmets
Back to top
View user's profile Send private message 
misko_2083


Joined: 08 Nov 2016
Posts: 114

PostPosted: Tue 07 Jul 2020, 13:08    Post subject:  

Nice.
Remember to add -r to read for backslash.

I didn't try with ftp.
This is the script I used to test:
Code:
#!/bin/bash

function ftpdo (){

local _HOST _PORT _ABUSER _PASS _EXEC1 _EXEC2 FIELD

for FIELD in _HOST _PORT _USER _PASS _EXEC1 _EXEC2
     do
       read -s -r ${FIELD}
       echo "${FIELD}=${!FIELD}"
done

}
export -f ftpdo

function ftpfn (){ 
yad  \
--form \
--field="HOST" "$HOST" \
--field="Port" "$PORT" \
--field="USER:H" "$_USER" \
--field="PASSWORD:H" "$PASSWORD" \
--field="EXEC1" "$EXEC1" \
--field="EXEC2" "$EXEC2" \
--field="Do:FBTN" \
'bash -c "ftpdo <<EOF | yad --text-info --timeout=3
"%1"
"%2"
"%3"
"%4"
"%5"
"%6"
EOF
" ' \
--columns=2

}

ftpfn
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 1 of 1 [6 Posts]  
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Off-Topic Area » Programming
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0725s ][ Queries: 11 (0.0192s) ][ GZIP on ]