LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > antiX / MX Linux
User Name
Password
antiX / MX Linux This forum is for the discussion of antiX and MX Linux.

Notices


Reply
  Search this Thread
Old 10-08-2021, 11:05 AM   #1
Snugbug
Member
 
Registered: May 2020
Posts: 96

Rep: Reputation: Disabled
MX19.4 XFCE - Why bash doesn't work?


To have some backups, I'm trying to copy some files to several target folders at once, using this bash:

Code:
#!/bin/bash
# Replace "Dummy" (without "") with the number of the according issue number. 
a=Dummy
cp "/home/user/Documents/issues/issue$a.pdf" "/media/user/BACKUP/BACKUPS 19.10.2017 (Win10+Linuxes)/Mint18.2-Home/user/Documents/issue/"
cp "/home/user/Documents/issues/issue$a.pdf" "/media/user/DATA/Old HDD's of old PC/ Int. HDD - (C&D&E of old PC)/LW-D/Documents/issues/"
cp "/home/user/Documents/issues/issue$a.pdf" "/media/user/DATA/Old HDD's of old PC/(K) HDDrive2Go1 (250GB) (LW-K of old PC)/Documents/issues/"
cp "/home/user/Documents/issues/issue$a.pdf" "/media/user/DATA/Old HDD's of old PC/(L) HDDrive2Go2 (500GB) (Mint-Partitions) & (LW-L of old PC)/Mint-Partitions/LM 17.3 MATE - Home/Documents/issues/"
cp "/home/user/Documents/issues/issue$a.pdf" "/media/user/DATA/Old HDD's of old PC/(M) HDDrive2Go3 (1 TB) (LW-M of old PC)/Documents/issues/"
DATA and BACKUP are NTFS partitions which are successfully mounted at boot up by means of the fstab file.

The bash is set to be executable, I run it in a terminal, but still it doesn't work. Nothing is happening.

If I manually try one of the cp commands in the terminal, there's this message, instead:
Code:
cp: Calling stat for '/home/user/Documents/issues/issue.pdf' not possible: File or folder not found.
Does anybody know, what went wrong, please?

Rem.: The very same bash does run perfectly when executed in Mint.

Last edited by Snugbug; 10-08-2021 at 11:15 AM.
 
Old 10-08-2021, 11:14 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,687

Rep: Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274
that is quite clear, that file does not exist: /home/user/Documents/issues/issue.pdf. And obviously you want to copy another file, like /home/user/Documents/issues/issueDummy.pdf (or something like that).
Would be nice to show your script to be able to help you with that.
Also I recommend you to use shellcheck to validate/check your script.
 
Old 10-08-2021, 01:20 PM   #3
Snugbug
Member
 
Registered: May 2020
Posts: 96

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by pan64 View Post
that is quite clear, that file does not exist: /home/user/Documents/issues/issue.pdf. And obviously you want to copy another file, like /home/user/Documents/issues/issueDummy.pdf (or something like that).
Would be nice to show your script to be able to help you with that.
Also I recommend you to use shell/check to validate/check your script.
What you see in my opening post (1st code block), IS that script.

Here's what I want to do:

The source files are as follows and so, the names of the source files are all the same. Only the numbers are different.
Code:
issue01.pdf
issue02.pdf
issue03.pdf
...
The files are all located in...
Code:
/home/user/Documents/issues/
From time to time, there's another file being added there and each time, a new file is added, I want to copy the new file to several folders as backups.

The bash is supposed to work by manually editing the word "Dummy" into the wanted issue number, and then, when the bash is being executed, it should copy that file to several target folders.

As for your comment:
Yes, I agree, according to the message, that file doesn't exist, but in fact, it does exist.
I don't understand why the message denies the existence of that file.

EDIT:
Now I know why the single command didn't work, I just forgot to edit the issue number in that command.
But this still doesn't explain why the bash doesn't work.

Last edited by Snugbug; 10-08-2021 at 01:33 PM.
 
Old 10-08-2021, 01:33 PM   #4
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,592

Rep: Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880
Quote:
cp: Calling stat for '/home/user/Documents/issues/issue.pdf' not possible: File or folder not found.
Copying a line straight from your program to the command line should fail since $a would be an empty variable unless you actually inserted a value number.

Are you sure the drives are being mounted exactly as desired? Post the output of the command lsblk.
 
Old 10-08-2021, 01:52 PM   #5
teckk
LQ Guru
 
Registered: Oct 2004
Distribution: Arch
Posts: 5,102
Blog Entries: 6

Rep: Reputation: 1822Reputation: 1822Reputation: 1822Reputation: 1822Reputation: 1822Reputation: 1822Reputation: 1822Reputation: 1822Reputation: 1822Reputation: 1822Reputation: 1822
You have illegal chars in them
Code:
a=Dummy

echo "cp "/home/user/Documents/issues/issue$a.pdf" "/media/user/BACKUP/BACKUPS 19.10.2017 (Win10+Linuxes)/Mint18.2-Home/user/Documents/issue/""
echo "cp "/home/user/Documents/issues/issue$a.pdf" "/media/user/DATA/Old HDD's of old PC/ Int. HDD - (C&D&E of old PC)/LW-D/Documents/issues/""
echo "cp "/home/user/Documents/issues/issue$a.pdf" "/media/user/DATA/Old HDD's of old PC/(K) HDDrive2Go1 (250GB) (LW-K of old PC)/Documents/issues/""
echo "cp "/home/user/Documents/issues/issue$a.pdf" "/media/user/DATA/Old HDD's of old PC/(L) HDDrive2Go2 (500GB) (Mint-Partitions) & (LW-L of old PC)/Mint-Partitions/LM 17.3 MATE - Home/Documents/issues/"
echo "cp "/home/user/Documents/issues/issue$a.pdf" "/media/user/DATA/Old HDD's of old PC/(M) HDDrive2Go3 (1 TB) (LW-M of old PC)/Documents/issues/""

bash: syntax error near unexpected token `('
bash: syntax error near unexpected token `('
bash: syntax error near unexpected token `('

Couple of examples:
Code:
for i in {01..20}; do
    echo "cp /home/user/Documents/issues/issue"$i" /some/where/"
done


arr=(file1.pdf file2.pdf file3.pdf file4.pdf file5.pdf)

for i in "${arr[@]}"; do
    echo "cp /home/user/Documents/issues/"$i" /some/where/"
done
 
Old 10-08-2021, 02:55 PM   #6
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,592

Rep: Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880
Ouch, I totally overlooked the "()" in your path names. As far as I know you need to use single quotes but that should fail on either operating system.

I would expect the script to fail on either system but would also expect error message versus just not doing anything.
 
Old 10-08-2021, 04:54 PM   #7
Snugbug
Member
 
Registered: May 2020
Posts: 96

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by michaelk View Post
Copying a line straight from your program to the command line should fail since $a would be an empty variable unless you actually inserted a value number.

Are you sure the drives are being mounted exactly as desired? Post the output of the command lsblk.
I noticed this already. I was referring to this in the EDIT section of my previous post.
I also tried to mask the brackets with backslashes, but it didn't work either.

The target drives are mounted like this (in fstab):
Code:
# BACKUP partition on HDD
UUID=52BA31EC484A8A74 /media/user/BACKUP ntfs-3g defaults	0 0
# DATA partition on HDD
UUID=6D9C5567310DBE08 /media/user/DATA ntfs-3g defaults       0 0
HDD is a 2nd internal SATA drive. The 1st drive of that computer is an SSD (on a SATA port, too).

Code:
lsblk
NAME    MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda       8:0    0 465,8G  0 disk 
├─sda1    8:1    0   450M  0 part 
├─sda2    8:2    0   100M  0 part /boot/efi
├─sda3    8:3    0    16M  0 part 
├─sda4    8:4    0 118,7G  0 part 
├─sda5    8:5    0   534M  0 part 
├─sda6    8:6    0   878M  0 part 
├─sda7    8:7    0  31,3G  0 part [SWAP]
├─sda8    8:8    0  48,9G  0 part 
├─sda9    8:9    0  64,7G  0 part 
├─sda10   8:10   0  39,8G  0 part 
├─sda11   8:11   0  57,2G  0 part 
├─sda12   8:12   0  40,9G  0 part /
└─sda13   8:13   0  62,5G  0 part /home
sdb       8:16   0   3,7T  0 disk 
├─sdb1    8:17   0   1,7T  0 part /media/user/BACKUP
├─sdb2    8:18   0   1,7T  0 part /media/user/DATA
└─sdb3    8:19   0 200,3G  0 part /run/timeshift/backup
The many sda partitions are there, because it's a multi boot system.

@ teckk
Thanks, but I don't need a loop for many source files to be copied, usually I only have one source file that's meant to be copied to several target folders at once.
 
Old 10-08-2021, 05:26 PM   #8
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,592

Rep: Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880
Nothing wrong there..

Code:
cp "/home/user/Documents/issues/issue$a.pdf" '/media/user/BACKUP/BACKUPS 19.10.2017 (Win10+Linuxes)/Mint18.2-Home/user/Documents/issue/'
As posted above try using single quotes.
 
Old 10-09-2021, 06:05 AM   #9
shruggy
Senior Member
 
Registered: Mar 2020
Posts: 3,670

Rep: Reputation: Disabled
Quote:
Originally Posted by michaelk View Post
As posted above try using single quotes.
Just replacing double quotes with single ones won't work either because of directory names like
Code:
/media/user/DATA/Old HDD's of old PC/
But more importantly, the double quotes problem only arose because of how teckk quoted the statements, I don't see it in the original script.

Last edited by shruggy; 10-09-2021 at 06:13 AM.
 
Old 10-10-2021, 04:17 AM   #10
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,687

Rep: Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274
Quote:
Originally Posted by shruggy View Post
But more importantly, the double quotes problem only arose because of how teckk quoted the statements, I don't see it in the original script.
I guess we have not seen it yet (at least the one which printed the inittial error message).
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Logging errors mx19 wayne1937 Linux - Newbie 2 05-23-2021 06:15 PM
Any way to speed up boot time on MX19? DaComboMan antiX / MX Linux 8 01-20-2021 08:31 AM
[SOLVED] MX19.2 cannot find wifi on Toshiba a665 series laptop GHM Linux - Newbie 3 07-25-2020 02:48 AM
XFce and Compiz : xfce doesn't manage the desktop naaman Linux - Desktop 0 07-16-2008 01:39 AM
'login' doesn't work, 'su' doesn't work, can't login as root antiqui.populi Linux - Security 3 10-20-2006 04:32 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > antiX / MX Linux

All times are GMT -5. The time now is 09:40 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration