crontab doesnt want to execute full script
Under Ubuntu 12.04 LTS Server I wrote very simple script to backup datastore - backup.sh
It looks like that: Code:
#!/bin/bash However, if I use crontab to execute this, then first command service mysql stop will NOT be executed. Any ideas why ? |
Are you running the script from root's crontab?
Are there any indicators in the log files about this? Have you tried adding the full path to the command (/usr/sbin/service instead of a plain service)? |
Hi, yes:
- I use root crontab - I have tried with full path of service - /usr/sbin/service - no luck - I have added file descriptor >> /tmp/backup.log to each line. The "stop" never appears there. I forgot to mention that "start" works perfectly. |
I wasn't talking about a self generated log but messages in /var/log.
Using this cron entry: Code:
*/1 * * * * /root/blaat.sh >> /tmp/backup.log Code:
#!/bin/bash Code:
<time stamp> plains /USR/SBIN/CRON[16149]: (root) CMD (/root/blaat.sh >> /tmp/backup.log ) Code:
Subject: Cron <root@plains> /root/blaat.sh >> /tmp/backup.log (failed) Code:
#!/bin/bash |
Hi Druuna,
I think you had different problem than I am having. As I wrote - this script works perfectly for me if I execute it manually. It fails to execute command "/usr/sbin/service mysql stop" if I run it from crontab. NOTE - it is only this one command and mind that "/usr/sbin/service mysql start" is executed correctly with no error. I see no details in syslog and any other log file. It looks like this one is completely omitted... but why ??? |
Quote:
Quote:
- Change the script to: Code:
#!/bin/bash Code:
*/1 * * * * /root/backup.sh >/root/backup.log 2>&1 |
Hi, thanks for reply.
I did like you said and here is result of the log file: Code:
# cat /root/backup.log |
Only things that comes to mind:
- Your environment isn't set at all when using cron. - The mysql script in /etc/init.d/ isn't up to par. The best solution would be to give root's cron a minimal environment. For now you could try adding this to your backup script (the bold part): Code:
#!/bin/bash |
I looked for Ubuntu's cron set up and came across this: Further Considerations
|
Ya, good point. Environmental variables seems not to be set for cron.
I have added PATH to script and it flies now :) Thnaks! By the way, do you know what is the proper way to set up PATH globally for corn (Ubuntu), so I dont need to mind about that in every other script ? EDIT: Your last post answers my last question. |
All times are GMT -5. The time now is 08:21 AM. |