What's new

Help with scripting

  • SNBForums Code of Conduct

    SNBForums is a community for everyone, no matter what their level of experience.

    Please be tolerant and patient of others, especially newcomers. We are all here to share and learn!

    The rules are simple: Be patient, be nice, be helpful or be gone!

Carlos M.

Regular Contributor
Hi,

I want write a script and put it into the services-star .

Just need to move files from one folder under a mnt resource to another folder and do it scheduled.

Please, could somebody post an example?

Thanks in advance
 
You can schedule a move of files each day like so:
Code:
# cru

Cron Utility
add:  cru a <unique id> <"min hour day month week command">
delete: cru d <unique id>
list:  cru l

# cru a MoveFiles "00 09 * * * mv /tmp/mnt/ASUS/test1/* /tmp/mnt/ASUS/test2"

# cru l
00 09 * * * mv /tmp/mnt/ASUS/test1/* /tmp/mnt/ASUS/test2 #MoveFiles#
This only works properly if there are no subdirectories in test1.
 
Last edited:
Thank you ColinTaylor, I'll modify the routes to my setup but... anything else to change? How can I set the min hour month etc...?
 
# cru

Cron Utility
add: cru a <unique id> <"min hour day month week command">
delete: cru d <unique id>
list: cru l

minute 0-59
hour 0-23
day of month 1-31
month 1-12
day of week 0-7

A field may contain an asterisk (*), which always stands for "first-last"
 
Then...
Code:
# cru

Cron Utility
add: cru a <unique id> <"0 12 * * *  command">
delete: cru d <unique id>
list: cru l

this must work for all days all months all weeks starting at 12pm?

Thanks... :(
 
Hi,

Just need to move files from one folder under a mnt resource to another folder and do it scheduled.

If you move files, it implies that they no longer exist at the source location under the mnt resource. So the next scheduled move will fail, unless the files are recreated in the meantime.

If this is not what you want, the copy command (cp) may work better.

In the Windows world, files which are moved keep their previous permissions when moved to a new location. But copied files automatically inherit the permissions of the directory to which they are copied. I don't know if it works the same way in Unix/Linux.
 
To be honest, the code looks like a joke. "It is now mid-day"?
I can't understand and If I can't... I don't learn... :(

I want move the content each day. If the folder is empty... is empty. What's the problem?
I'm not sure to understand, sorry. I just want avoid moving files from my windows over wifi between two folders in the same USB stick mounted into the router. I change some things and rename file files in the folder source and after, I want move them to the destination folber B. As a cronjob and unattended process.

Better? ;)
 
To be honest, the code looks like a joke. "It is now mid-day"?
I can't understand and If I can't... I don't learn... :(
OK I'll have one last attempt at explaining this.:rolleyes:

1. If you want to schedule a command to happen at a certain time you need to update the crontab. (https://en.wikipedia.org/wiki/Cron)

2. The cru utility provides an easy way to add or delete entries in the crontab from the command line or in a script (you said you wanted to do this from services-start).

3.
To list the current crontab type:
cru l

To add something to the crontab type:
cru a <unique id> "0 12 * * * command"

To delete something from the crontab type:
cru d <unique id>

4. So, for example, to run /tmp/myscript.sh every day at 15:30 you would use the following command to add it to the crontab:

cru a MyComment "30 15 * * * /tmp/myscript.sh"

5. To check that you have scheduled the job successfully, type "cru l":

admin@RT-N66U:/# cru l
30 15 * * * /tmp/myscript.sh #MyComment#


6. That's all.

I want move the content each day. If the folder is empty... is empty. What's the problem?
It is not a problem.
 
Last edited:

Latest threads

Support SNBForums w/ Amazon

If you'd like to support SNBForums, just use this link and buy anything on Amazon. Thanks!

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!
Top