Script to copy files?

New to Puppy and have questions? Start here

Moderator: Forum moderators

Post Reply
User avatar
theroar84
Posts: 93
Joined: Sat May 08, 2021 4:21 pm
Location: US
Has thanked: 45 times
Been thanked: 20 times
Contact:

Script to copy files?

Post by theroar84 »

First, thanks for all the tips! Slowly but surlely things are making sense. =)

Running Fossa64 on the hard drive. I had been manually copying a pair of files whenever I updated them... Dawned on my instead of launching the folders, which you all helped with, I should be able to have a script just do the copying.

I built this after a bit of searching... No joy when I run the script though. Do those commands need to be in the terminal instead of a script? Thanks again for the tips.

#!/bin/bash
cp ./mnt/home/clickawake.sh ./root/my-applications/bin/
cp ./mnt/home/root ./var/spool/cron/crontabs/

I do want the new files to replace files that are likely already in the folder.

Tested from a terminal and it appears I am not calling the folders properly.

cp: cannot stat './mnt/home/clickawake.sh': No such file or directory
cp: cannot stat './mnt/home/root': No such file or directory

Running Fossa64 9.5 Multiple PC's Frugal Installs on EXT4 hard drives. Multiple Frugals per PC too.

HerrBert
Posts: 358
Joined: Mon Jul 13, 2020 6:14 pm
Location: Germany, NRW
Has thanked: 18 times
Been thanked: 126 times

Re: Script to copy files?

Post by HerrBert »

@theroar84

#!/bin/bash
cp ./mnt/home/clickawake.sh ./root/my-applications/bin/
cp ./mnt/home/root ./var/spool/cron/crontabs/

The leading dots don't work here, because rox interpretes them as relative path to where it starts from.
Also i wonder, why you want to copy /mnt/home/root to /var/spool/cron/crontabs/
IIRC, /var/spool will not be saved when you shut down your session and save it...

To less information at all...

What are you trying to do?

User avatar
theroar84
Posts: 93
Joined: Sat May 08, 2021 4:21 pm
Location: US
Has thanked: 45 times
Been thanked: 20 times
Contact:

Re: Script to copy files?

Post by theroar84 »

the root file is the list of chronjobs I have. I have a set of PC's I run the same jobs with and this lets me move the jobs by simply copying that file.

The click awake is a script of xdotool commands that keep a browser window alive for me.

Interesting that the var spool does not stick. I have been working off your note last week. Maybe I did not understand this correctly.

"So /var/local/cron is a symbolic link to ../../var/spool/cron created by pschedule."

I guess if I had the script run automatically when I started puppy it would at least get my updated root file in there.

lol... just had to google what iirc stands for... I was just about to ask. 👍

Running Fossa64 9.5 Multiple PC's Frugal Installs on EXT4 hard drives. Multiple Frugals per PC too.

User avatar
theroar84
Posts: 93
Joined: Sat May 08, 2021 4:21 pm
Location: US
Has thanked: 45 times
Been thanked: 20 times
Contact:

Re: Script to copy files?

Post by theroar84 »

Thanks tons! Ripped out the dots and it copies fine. So slick. Do I need to change anything to force it to replace a existing copy?

Running Fossa64 9.5 Multiple PC's Frugal Installs on EXT4 hard drives. Multiple Frugals per PC too.

User avatar
amethyst
Posts: 2421
Joined: Tue Dec 22, 2020 6:35 am
Has thanked: 57 times
Been thanked: 506 times

Re: Script to copy files?

Post by amethyst »

theroar84 wrote: Sat Nov 18, 2023 7:44 pm

Thanks tons! Ripped out the dots and it copies fine. So slick. Do I need to change anything to force it to replace a existing copy?

in terminal do: cp --help to see all the options for the cp command. Default is overwrite existing files. cp -a is most often used.

HerrBert
Posts: 358
Joined: Mon Jul 13, 2020 6:14 pm
Location: Germany, NRW
Has thanked: 18 times
Been thanked: 126 times

Re: Script to copy files?

Post by HerrBert »

If you want to update your copied files you can use cp -f [SOURCE] [DESTINATION] to overwrite existing file or cp -u [SOURCE] [DESTINATION] to update existing file only if the source file is newer.

User avatar
theroar84
Posts: 93
Joined: Sat May 08, 2021 4:21 pm
Location: US
Has thanked: 45 times
Been thanked: 20 times
Contact:

Re: Script to copy files?

Post by theroar84 »

Thank you both! I had seen a nice list of the options for a command earlier but did not connect the dots using terminal and the --help. 👍

Running Fossa64 9.5 Multiple PC's Frugal Installs on EXT4 hard drives. Multiple Frugals per PC too.

fernan
Posts: 143
Joined: Sat Sep 19, 2020 3:35 am
Has thanked: 54 times
Been thanked: 24 times

Re: Script to copy files?

Post by fernan »

Also, if you need to keep synchronized some files and/or folders on several computers, take a look at "syncthing" app (no affiliation).

It's a very useful tool I use to keep sync between 4 computers at different locations. Useful to backup data too. Since I do some work on different computers, that syncthing daemon keeps all the computers synchronized to the latest version of the files, and has a backup option, keeping old versions of the files in a hidden folder for a time lapse you can set (in case you delete or override some file by mistake).

User avatar
wiak
Posts: 4091
Joined: Tue Dec 03, 2019 6:10 am
Location: Packing - big job
Has thanked: 65 times
Been thanked: 1212 times
Contact:

Re: Script to copy files?

Post by wiak »

theroar84 wrote: Sat Nov 18, 2023 5:40 pm

First, thanks for all the tips! Slowly but surlely things are making sense. =)

Running Fossa64 on the hard drive. I had been manually copying a pair of files whenever I updated them... Dawned on my instead of launching the folders, which you all helped with, I should be able to have a script just do the copying.

I built this after a bit of searching... No joy when I run the script though. Do those commands need to be in the terminal instead of a script? Thanks again for the tips.

#!/bin/bash
cp ./mnt/home/clickawake.sh ./root/my-applications/bin/

I was curious about the discussion in this thread, but can't make sense of it. What tips??? What is clickawake.sh??? The first post of the thread seems to be referring to earlier posts - but they don't exist - no earlier posts to the thread???

https://www.tinylinux.info/
DOWNLOAD wd_multi for hundreds of 'distros' at your fingertips: viewtopic.php?p=99154#p99154
Αξίζει να μεταφραστεί;

User avatar
theroar84
Posts: 93
Joined: Sat May 08, 2021 4:21 pm
Location: US
Has thanked: 45 times
Been thanked: 20 times
Contact:

Re: Script to copy files?

Post by theroar84 »

Thanks for shairng syncthing. That would have been so much smarter than my current gig. 🤦‍♂️ That said, I have this down to a science. A usb stick with a folder labeled up... whenever I need to pass updated scripts to the machine I copy the new ones to up... at each pc I click a script sdb and it copies off the usb to the home folder. As everyone noted the naming is differet for the usb drives at some pc's... so I just duplicated the script and changed to sdc or whatever.

As far as clickawake... I was working to make a script that will make my browser appear to be active even if I am off doing something else. The script simple clicks the top of browser A, waits a second or two, then moves to B with the xdotool and clicks again.

I named that script clickawake.sh

It looks like this now, but I keep fiddling with it. The key 3 will make a YouTube video skip ahead a tiny bit. The distance I move correspond with specific sizes I open the browsers at. That way no matter which PC I am fiddling with, desipite the motnior size, the script "fits".

xdotool mousemove 55 2
xdotool click --delay 2000 2
xdotool mousemove 1050 2
xdotool click --delay 2000 1
xdotool mousemove 50 2
xdotool click --delay 2000 1
xdotool key l
xdotool click --delay 2000 2
xdotool mousemove 1100 2
xdotool click --delay 2000 1
xdotool key l

This is a sample of the "launch" for the browsers.When it opens home I have access to all my scripts and I can just launch them at will as I fiddle. The experiment keeps growing.... but I doubt it has any practial uses.

xdotool search "Mozilla Firefox" windowminimize
xdotool search "Chromium" windowminimize
xdotool mousemove 30 980
xdotool click --delay 900 1
xdotool mousemove 300 2
xdotool search "/mnt/home" windowactivate windowsize %@ 200 1210 windowmove 1010 300
xdotool mousemove 300 2
xdotool search "Mozilla Firefox" windowactivate windowsize %@ 1010 1010 windowmove 0 0
xdotool mousemove 50 2 --delay 1000
xdotool click --delay 900 1
xdotool mousemove 640 712
xdotool click --delay 900 1
xdotool search "Chromium" windowactivate windowsize %@ 1010 1010 windowmove 300 0
xdotool search "/mnt/home" windowactivate windowsize %@ 200 1210 windowmove 1010 300

Last edited by theroar84 on Sat Dec 02, 2023 6:17 pm, edited 1 time in total.

Running Fossa64 9.5 Multiple PC's Frugal Installs on EXT4 hard drives. Multiple Frugals per PC too.

fernan
Posts: 143
Joined: Sat Sep 19, 2020 3:35 am
Has thanked: 54 times
Been thanked: 24 times

Re: Script to copy files?

Post by fernan »

theroar84 wrote: Fri Dec 01, 2023 12:05 pm

Thanks for shairng syncthing. That would have been so much smarter than my current gig. 🤦‍♂️ That said I have this down to a science. A usb stick with a folder labeled up... whenever I need to pass updated scripts to the machine I copy the new ones to up... at each pc I click a script sdb and it copies off the usb to the home folder. As everyone noted the naming is differet for the usb drives at some pc's... so I just duplicated the script and changed to sdc or whatever.

Yes, Syncthing would be a better solution to keep the same file or folder synchronized between computers. But, they synchronize only when the computers are running, of course. So, you need to make sure that every time you modify a file, some of the other computers (or better some server running 24/7) is running to update the files, or, you need to keep the computer you are using powered until another computer is powered, to start the sync process. Setting it the 1st time can be a bit confusing, but once you set everything up, it's totally transparent. I suggest you to share just the default folder at first, until you understand how it works.

User avatar
Jafadmin
Posts: 385
Joined: Tue Aug 04, 2020 4:51 pm
Has thanked: 68 times
Been thanked: 85 times

Re: Script to copy files?

Post by Jafadmin »

I universally us 'rsync' for these tasks. It only updates changed/new files. Mind the positioning of the forward-slash.
sync-dirs.sh:

Code: Select all

#! /bin/bash

From="/path/to/source/directory"
To="/path/to/destination/directory"

# Sync directories:     
rsync -avu --delete $From $To/
sync
Post Reply

Return to “Beginners Help”