Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
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.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
I am new to the linux environment, so bear with me. I am trying to setup crontab to move files from one directory to another automatically. These are files that are ftp to this server in a specific input directory. Once the file is run it is renamed and left there. What I want to do is have it move the file to another backup directory of my choosing. I have created a file call CSF Move File and the command I placed it in is:
I placed this file in the cron.hourly directory under the etc main directory. I made it also executable. I have waited two hours now and nothing had happened. Is there something else I need to do to make this happen? Any help would be appreciated.
Put in the full path for the "mv" command. That is to say instead of just "mv" put in "/bin/mv" so it knows where to find the "mv" command.
Cron isn't using the same environment you use when you login. Commands you do from the command line often don't work in Cron due to this. The most common part of the environment you have that cron doesn't is what is in your PATH variable.
You can see what is in your PATH variable by typing "echo $PATH" and hitting return.
Also to verify where the "mv" command is type "which mv".
Is the cron daemon running? What is the content of /etc/crontab? I've just tried on my Opensuse 10.3 and it works like a charm. What happen if you try to execute the script from the root crontab (that one created by crontab -e)?
OK, I added the /bin to the full path of the mv part of the command line. Is there a way to make this run automatically to see if it worked? I place the file in the cron hourly directory. The daemon wasn't running, but I figured out how to start it and it is running now. I tested the script and it worked great. Now that the file is in the cron hourly directory, what else do I need to do to make sure it runs each hour? Is there anything I need to add to the crontab file in the /etc directory?
Now that the file is in the cron hourly directory, what else do I need to do to make sure it runs each hour?
To be sure it runs each hour, you can add a date command and append output to a file. Also you can check the exit status of the mv command to see if it was successful, for example (immediately after the mv command) you can put
(echo -n "$? " && date) >> /root/log.hourly
after some time check if the log.hourly file contains the correct dates, like this
0 Fri Apr 18 19:00:01 CEST 2008
0 Fri Apr 18 20:00:00 CEST 2008
0 Fri Apr 18 21:00:00 CEST 2008
0 Fri Apr 18 22:00:01 CEST 2008
when you have verified that all works properly, you can remove that line from your script.
I will append the command line to the end of the mv command I already have in that file. Up until now it hasn't moved a file yet. I will let this run to see what happens with this command appended to the end of the current mv command. I will let you know what happens.
I assume when you say immediately after the mv command, put a space then the command you gave, correct? This is what I have now in the file:
No no... you don't separate commands with a single blank space! Press ENTER and start a new line or eventually put a separator specific to the language (in bash it is semi-colon). The line above may have unpredictable results. Anyway, you asserted that the script worked great. What is wrong with the move command now?
I mean when I run it manually. It doesn't do it automatically though. That is what I can't seem to figure our why it won't. I created a file and place that command in it. I then place the file on the cron.hourly directory. The daemon is now running, so I am not sure what else I need to do to make it work.
So you mean place the second command you gave me like this in the file?
Yes. You mean the file /root/log.hourly is not being created?
Can you try to add the command to a "user" crontab? For example, as root you can do
this will open an empty file in the vi editor. Assuming you have an executable copy of your script in /root/script.sh, you can simply add the following line:
0 * * * * /root/script.sh
save and exit. The crontab will be written in /var/spool/cron/tabs/root and will be added to the scheduled tasks at most one minute later. Please, try this and tell us if it works. For detail about the crontab format (if you are not experienced with that) look at
That file has not been created thus far. That is if the last example I gave with the format you told me is correct. What do you mean by this statement:
Assuming you have an executable copy of your script in /root/script.sh, you can simply add the following line:
Sorry, I am new to this and I didn't understand what you meant by this statement. Also, didn't understand the part about having an executable copy in the /root/script.sh.
Does the file I create with the move command and all have to have a certain type of extension on it? My understand of it was that I just create a file with the command in it and just place it in the cron.hourly directory and as long as the cron daemon is running it would work? Is that not right?
I apologize again for not having a better understand of what your asking.
Don't worry. I will explain better. Indeed, putting a file in cron.hourly should work provided it is executable. I was just asking to you to try another method.
Instead of using the cron.hourly, cron.daily, cron.weekly, cron.monthly system controlled by the /etc/crontab file, you can schedule jobs on a per-user basis. Each user on your system has the possibility to define and mantain his own crontab. The command to do this is
and the resulting crontab will be automatically written in the /var/spool/cron directory and will be called as the user name owning the crontab.
So if your script is /root/script.sh or /root/pippo or /path/to/your/script/name_of_the_script (that is regardless its name and extension) you can edit your crontab (I assume you're root for this test) and put the line
0 * * * * /root/pippo
this will execute the script /root/pippo at 0 minutes of each hour of each day of the year. If this doesn't work, we must investigate the problem further, otherwise there is some mis-configuration in the /etc/crontab system.
Ok, the files moved. What should I do now to troubleshoot why it won't work the other way of just placing the file in the cron.hourly directory? What is the difference in how I was doing to editing the crontab file and adding that line in it? Should I have done that before to show where the file is in the cron.hourly directory?
Oh, and when it ran, it did create a file by the root user name, but it was in the tab folder under the /var/spool/cron directory, if that makes any difference.