Xfce Forum

Sub domains
 

You are not logged in.

#1 2023-12-08 08:39:28

Regretful
Member
Registered: 2023-12-08
Posts: 5

Feeding complex command string to xfce4

Hi everyone!

I'm in a bit of a pickle here because I'm trying to use xfce4-terminal to spawn a standalone terminal that will ssh into a target computer, cd to a folder and then tail a log file there.
However the construction of the command to be executed does not seem to be fed correctly to the new terminal.

Following is an attempt at an "MWE"

#!/bin/bash

total_command="ssh $target_adress 'bash -s' <<< \"cd /homes/$USER/ && tail -f *.log[0-9]*\""

echo "Trying: $total_command"

xfce4-terminal --hold -e "$total_command"

When I execute the echoed total_command it works as expected. However the xfce4-terminal does not seem to properly ssh before trying to execute the commands. Giving the error "No such file or directory".

Anyone have any clues as to why this is not working?

Kind Regards,

Offline

#2 2023-12-08 21:17:30

ToZ
Administrator
From: Canada
Registered: 2011-06-02
Posts: 11,485

Re: Feeding complex command string to xfce4

Hello and welcome.

You're commands work here for me. I do notice though, that "$target_adress" is misspelled. Can you confirm you have that variable correct?

Also, which version of xfce4-terminal are you using?


Please remember to mark your thread [SOLVED] to make it easier for others to find
--- How To Ask For Help | FAQ | Developer Wiki  |  Community | Contribute ---

Offline

#3 2023-12-11 06:18:42

Regretful
Member
Registered: 2023-12-08
Posts: 5

Re: Feeding complex command string to xfce4

ToZ wrote:

Hello and welcome.

You're commands work here for me. I do notice though, that "$target_adress" is misspelled. Can you confirm you have that variable correct?

Also, which version of xfce4-terminal are you using?

So you managed to ssh and subsequently cd then tail a file?

Yes the variable is misspelled at assignment too tongue

xfce4-terminal 1.0.4 (Xfce 4.16)

Offline

#4 2023-12-11 14:16:27

ToZ
Administrator
From: Canada
Registered: 2011-06-02
Posts: 11,485

Re: Feeding complex command string to xfce4

With respect to:

However the xfce4-terminal does not seem to properly ssh before trying to execute the commands.

...yes. I was testing with these commands:

total_command="ssh localhost 'bash -s' <<< \"ls\""
xfce4-terminal --hold -e "$total_command"

However, re-reading your original post just now, I thought I would try to tail a log file, but that didn't work for me either, until I escaped all the spaces and ampersands:

total_command="ssh localhost 'bash -s' <<< \"cd\ /var/log\ \&\&\ tail\ -f\ pacman.log\""

I'm not exactly sure why this is needed - it seems to process the spaces and ampersands as something other than that.

Edit: it would process it all as one long command name. Interesting.

xfce4-terminal 1.1.1 (Xfce 4.18)

Last edited by ToZ (2023-12-11 14:18:50)


Please remember to mark your thread [SOLVED] to make it easier for others to find
--- How To Ask For Help | FAQ | Developer Wiki  |  Community | Contribute ---

Offline

#5 2023-12-11 18:58:13

Regretful
Member
Registered: 2023-12-08
Posts: 5

Re: Feeding complex command string to xfce4

ToZ wrote:

With respect to:

However the xfce4-terminal does not seem to properly ssh before trying to execute the commands.

...yes. I was testing with these commands:

total_command="ssh localhost 'bash -s' <<< \"ls\""
xfce4-terminal --hold -e "$total_command"

However, re-reading your original post just now, I thought I would try to tail a log file, but that didn't work for me either, until I escaped all the spaces and ampersands:

total_command="ssh localhost 'bash -s' <<< \"cd\ /var/log\ \&\&\ tail\ -f\ pacman.log\""

I'm not exactly sure why this is needed - it seems to process the spaces and ampersands as something other than that.

Edit: it would process it all as one long command name. Interesting.

xfce4-terminal 1.1.1 (Xfce 4.18)

Let me just say WOW!
Thank you for making such an excellent find!
I will now escape wink

Cheerio!

Offline

#6 2023-12-12 06:36:37

Regretful
Member
Registered: 2023-12-08
Posts: 5

Re: Feeding complex command string to xfce4

I have now tested it and it works as expected, I would never have figured out to escape the spaces and ampersands... What made you consider that?

Regards,

Offline

#7 2023-12-12 11:21:30

ToZ
Administrator
From: Canada
Registered: 2011-06-02
Posts: 11,485

Re: Feeding complex command string to xfce4

Regretful wrote:

I have now tested it and it works as expected, I would never have figured out to escape the spaces and ampersands... What made you consider that?

Basically trial and error. Read up on "bash -s", looked at the error message in ~/.xsession-errors and realized it wasn't processing the string properly.


Please remember to mark your thread [SOLVED] to make it easier for others to find
--- How To Ask For Help | FAQ | Developer Wiki  |  Community | Contribute ---

Offline

#8 2023-12-13 06:42:57

Regretful
Member
Registered: 2023-12-08
Posts: 5

Re: Feeding complex command string to xfce4

ToZ wrote:
Regretful wrote:

I have now tested it and it works as expected, I would never have figured out to escape the spaces and ampersands... What made you consider that?

Basically trial and error. Read up on "bash -s", looked at the error message in ~/.xsession-errors and realized it wasn't processing the string properly.

Ah, wouldn't have thought to look in ~/.xsession-errors. Lots of things to learn, still new to bash it seems!

Offline

Registered users online in this topic: 0, guests: 1
[Bot] ClaudeBot

Board footer

Powered by FluxBB
Modified by Visman

[ Generated in 0.009 seconds, 8 queries executed - Memory usage: 549.61 KiB (Peak: 566.89 KiB) ]