0
votes

Description

I want to copy all files ending on .jpg from my local machine to the remote machine with scp. For this i have a small "script". It looks like this:

#!/bin/bash


xfce4-terminal -e "scp -r -v /path/to/local/folder/*.jpg <user>@<IP>:/var/path/to/remote/folder/" --hold

Problem

When i open a terminal and enter scp -r -v /path/to/local/folder/*.jpg <user>@<IP>:/var/path/to/remote/directory/ it works. So SSH is working correct.

When i start the script it doesnt. The script works, when i copy the whole local folder. It then looks like this (simply the *.jpg is removed):

#!/bin/bash

xfce4-terminal -e "scp -r -v /path/to/local/folder/ <user>@<IP>:/var/path/to/remote/folder/" --hold

But then i have the local folder inside the remote folder, where i only want to have the files.

I dont know, if it is important but currently i use a computer with Linux Mint 19.3, xfce terminal and zshell.

Question

So how do i run a script correctly that copys files from a local folder to remote folder?

1

1 Answers

2
votes

It's the shell who expands the wildcard, but when you run -e in xfce4-terminal, it runs the command without letting the shell parse it. You can run a shell to run the command, though:

xfce4-terminal -e "bash -c 'scp -r -v /path/to/local/folder/*.jpg user@ip:/var/path/to/remote'" --hold

Are you sure you need the -r? Directories are usually not named .jpg.