antiX / MX LinuxThis forum is for the discussion of antiX and MX Linux.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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.
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.
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.
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
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.