0

One wildcard batch copy works for me:

sudo cp /home/jenkins/dist/*.war /opt/tomcat/webapps/

but another similar doesn't:

sudo cp /opt/tomcat/webapps/*.war /home/jenkins/archive
cp: cannot stat '/opt/tomcat/webapps/*.war': No such file or directory

But actually both folders have that sort of files:

sudo ls -l /opt/tomcat/webapps/
total 330536
drwxr-x--- 5 tomcat paysoft      4096 Sep 26 02:12 ROOT
-r-x------ 1 tomcat tomcat  127981631 Sep 26 02:10 ROOT.war
drwxr-x--- 4 root   root         4096 Feb 26  2023 site-api
-r-x------ 1 tomcat tomcat  106277537 Sep 26 02:11 site-api.war
drwxr-x--- 4 tomcat paysoft      4096 Sep 26 02:11 web-api
-r-x------ 1 tomcat tomcat  104181448 Sep 26 02:11 web-api.war

and

sudo ls -l /home/jenkins/dist/
total 569312
-rw-r--r-- 1 jenkins jenkins 112948432 Aug  1  2022 money-transfer-web.jar
-rw-r--r-- 1 jenkins jenkins 127981631 Sep 26 02:03 ROOT.war
-rw-r--r-- 1 jenkins jenkins 106277537 Sep 26 02:03 site-api.war
-rw-r--r-- 1 jenkins jenkins 131561362 Sep 26 02:03 terminal-server.jar
-rw-r--r-- 1 jenkins jenkins 104181448 Sep 26 02:03 web-api.war

what is the reason?

P.S. The directories themselves are:

sudo ls -l /home/jenkins/
total 8
drwxr-xr-x 2 root    root    4096 Jul 11 15:20 archive
drwxr-xr-x 2 jenkins jenkins 4096 Jun 30  2022 dist
1
  • 1
    I see a permissions difference that may be important... but what are permissions for the directories? If the tomcat webapps directory does not have the x flag set, directory search would not be permitted, and that might be why cp can't look for files in there.
    – tsc_chazz
    Commented Sep 25, 2023 at 20:50

1 Answer 1

2

sudo cp /home/jenkins/dist/*.war /opt/tomcat/webapps/

Here, your (non-privileged) shell will attempt to expand the '*' before passing the resulting command line to sudo - hence its behaviour will depend on your permissions to read from /home/jenkins/dist/.

You didn't show us what the permissions were on the directories - only their contents.

Conversely in the following case, the expansion is done by the root shell:

sudo 'cp /home/jenkins/dist/*.war /opt/tomcat/webapps/'
3
  • Hi! I have updted the question with ls -l of the directories. Could you check now, please? Commented Sep 26, 2023 at 5:57
  • That ls is useless, since you ran it with sudo again. The point is, that the shell tries to expand the path before sudo is invoked, which most probably fails. Also, it was run on the wrong directory. sudo namei -l /opt/tomcat/webapps/ would shed some light on this. Commented Sep 26, 2023 at 6:30
  • @symcbean you accidently swapped the paths, your examples use the path where it worked, not where it didn't. Commented Sep 26, 2023 at 6:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .