My crontab does not work
I'm using CentOS 6 and I trying my first CRON.
I've this following file /etc/crontab :
It does not consider my script.sh wich i supposed be executed every hour in the 18th minute... ?
# For details see man 4 crontabs
# Example of job definition:
# .---------------- minute (0 - 59)
# | .------------- hour (0 - 23)
# | | .---------- day of month (1 - 31)
# | | | .------- month (1 - 12) OR jan,feb,mar,apr ...
# | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,$
# | | | | |
# * * * * * command to be executed
37 23 19 8 5 touch cokkkk.txt
18 * * * * /test/script.sh
What is the problem ?
Thank you !
User is missing.
And may I suggest to write systemwide cronjobs in separate files in /etc/cron.d/<TASK>.cron ?
Thanks for your quick reply Irithori !
Please slowly, I try to understand the first function :)
I've add root, so I've change my line for
and that doesn't change anything !
18 * * * * /test/script.sh root
Thank you :D
The user is before the command
About /etc/cron.d vs /etc/crontab:
18 * * * * root /test/script.sh
Crons are easier to manage, if you separate them by task and write files in /etc/cron.d/
Because then you can just delete and add files instead of parsing /etc/crontab to find the right lines.
Also it is easier to define different environments per cronjob.
So in your case:
Create a file /etc/cron.d/my_first_cron.cron
and place your line in there.
On an additional note:
There are tasks and cronjobs, that need to be done as root.
But the goal is to avoid that and use dedicated users for separation and security reasons.
OK that's rulz !
Just one thing, the upload of the script itself dosent' work in CRON MOD.
When I execute the script i'ts ok, script.sh is uploaded. But when the CRON execute the script, it cannot upload the script itself. Do I make myself clear?
Next, I'll try your cron.d.
What does the cronlog tell you? It is normally found in:
You can try redirecting your script output to a log for further trouble-shooting, e.g.:
18 * * * * root /test/script.sh > /tmp/cronjob.log 2>&1
In cronjob.log, I have :
test.sql and script.sh are in the same directory.
Domain=[WIN2003] OS=[Windows Server 2003 R2 3790 Service Pack 2] Server=[Window$
putting file test.sql as \test.sql (174.4 kb/s) (average 174.4 kb/s)
script.sh does not exist
Even though they are in the same directory, the shell running the cronjob probably cannot find them (b/c they are not in its PATH). Try using full path names to any files referenced in your script called by cron.
If you want more help, you can post your cron script, too.
The important part of my script.sh is :
THe line of my crontab is :
smbclient //192.168.1.xx/onlyuser -A /essais/cred -c "prompt;put test.sql;put script.sh;exit;"
script.sh and test.sql are in the folder :
*/1 * * * * root /essais/script.sh >> /logsmb.txt 2>&1
When I change "put script.sh" by "put /essais/script.sh" I have this error :
putting file test.sql as \test.sql (111.0 kb/s) (average 111.0 kb/s)
NT_STATUS_OBJECT_NAME_INVALID opening remote file \/essais/script.sh
Does script.sh already exist on the samba host? Is it open/in use on the samba host? Are the permissions of it such that it cannot be overwritten?
I can emulate your setup on my machine and run it perfectly, as far as I can tell.
Domain=[SAMBA_HOST] OS=[Windows 5.0] Server=[Windows 2000 LAN Manager]
putting file test.sql as \test.sql (0.0 kb/s) (average 0.0 kb/s)
putting file script.sh as \script.sh (49.3 kb/s) (average 24.7 kb/s)