Rename/Move files and schedule the script

Hello,

I'm new in the forum and in UNIX scripting, what I need is to write a simple batch script that renames or move the files back & forth from one directory to another, and then schedule the script to run on the server when the scheduled down time is, which is on Thursdays at 8pm and during the weekends, then I guess another one to put the files back when the scheduled up time has come...

Any ideas would be greatly appreciated.
Thanks :smiley:

Use cron to schedule the job (see the man pages for cron(1), crontab(1) and crontab(5)).

Use mv to move files.

mv is the command to move or rename files.

Thanks for the quick response.
I don't know the syntax yet and don't know how it works, but would it be something like:

If cron (thursday 8 pm) then
mv [source dir][file] [dest dir]
Else
mv [dest dir][file] [source dir]

??

Or do like two separte scripts? one for moving/renaming the file if it's time to go down and another one to again moving/renaming the file when it's time to go up?

Thanks.

Two separate script files, but if you just have one command to execute at a certain time and another single command to execute later you can forgo the files and just put the single command in the crontab file.

crontab files contain entries like this:

00 19 * * 1-5 /root/ldap_slapcat_backup
00 18 * * * /usr/local/bin/divaliases 2>/var/log/divaliases.err
59 23 * * * /usr/bin/rcrepeater restart
0 18 * * * /bin/sh /srv/www/htdocs/set_perms.sh >/dev/null
0 5 * * * /usr/sbin/rcapache2 restart
0 3 * * * /usr/sbin/rcmysql restart
0 20 * * 1-5 /usr/local/bin/backup.sh
27 4,16 * * * /usr/local/f-prot/tools/check-updates.pl -cron -quiet

The first numbers and asterisks are codes to tell the system when to run the commands that follow. It goes something like this: minute hour dont_need_use* dont_need_use* day_of_week command...

in your case you can make (insert) two entries like this

01 18 * * 1-5 mv /path/to/somefile* /new/path/ 
01 19 * * 1-5 mv /new/path/somefile* /path/to/

that would copy files at 18:01, on monday(1) to friday(5)
and put them back at 19:01.

The command "crontab -e" wil open an editor (here it is vi) to allow editing of crontab entries. To just see them (if you already have some) use "crontab -l" . That will list them.

Thanks a lot!!

So, if I use the crontab -e and edit the entries according my needs and save it, just how do you run it? I think I need to make sure the script it's executable with chmod 755 first and then run it on the command line, is that correct? but when I type the crontab it automatically store it?

Sorry for all this simple questions but I'm a newbie as you can tell...

Thanks,