I'm running cron on my CentOS6.5 Docker container and when I do ps ef | grep cron it shows up so I know it's running.
I have below command after going into crontab -e
* * * * * /bin/touch /tmp/env.output
This however silently fails and I cannot see any /tmp/env.output
Crontab is running as root aswell and I can touch env.output with same user so it does not seem to be permission issue.
Is there anywhere else I need to check?
Related
I'm trying to set up automatic backup for postgre database. Postgre running in docker, so my script for backup is:
docker-compose exec postgres -U user database_name | gzip > "/var/server/my_service/data/backup-db/db_backup.sql.gz"
And its working fine, if I run it manually. I wrote the following job for the crontab (every 5 minutes just for testing):
*/5 * * * * cd /var/server/my_service && sh /var/server/my_service/data/backup/backup_script
This command also working great, if i run it manually it create valid DB backups that i can use.
But crontab just create empty archive, without any data. I just cant understand why.
My guess is that the output stream that catches the gzip is normally generated in manual mode, but completely empty when the crontab trying to run command
I thought there were problems with access rights and put the in the root crontab but it didn't help
UPD:
so... problem in backup_script, error in logs says the input device is not a TTY
I tried google it and add -T, but it didn't help as well
Update your /var/server/my_service/data/backup/backup_script with the following:
Prefix the first 3 line in your script:
#!/bin/bash
source ~/.bash_profile
cd /var/server/my_service
#
# rest of your script
#
Your crontab line should be (At 04:44 on every day-of-month):
44 4 */1 * * /var/server/my_service/data/backup/backup_script
I run docker-compose from a cronjob as follows:
05 16 * * * cd /home/apps; docker-compose run service1 sh ./update_all_all.sh /data >>/var/log/works.log
I'd like to capture the outputs from the run into works.log, it runs, but no works.log file, any idea how to make this works?
Thanks,
I have solved the problem of capturing the compose logs with the following shell script:
docker-compose up -d
docker-compose logs -t -f --no-color > compose.log &
# Maybe do something more before cleaning up...
docker-compose stop
I want to run a single command from a crontab. Rather than create a bash file for just one command, is it possible to run a crontab somehow like this:
# Everyday at 3 am, restart the server.
0 3 * * * 'sudo shutdown -r now'
Instead of:
0 3 * * * /usr/local/bin/restart.bash
Can something like that be done?
Yes, you can type the command in-line, but it must be typed the same as if you were on the command line. You do not type single quotes ' on the command line, so you should not type them in the crontab either.
Finally, a command which requires root access must be run in the root crontab. (i.e. edit using sudo crontab -e instead of plain crontab -e, or log in as root using su - before typing crontab -e)
So in your example, you should type this in the crontab:
# Everyday at 3 am, restart the server.
0 3 * * * shutdown -r now
(sudo has no effect, removed single quotes)
I want to restart my Raspberry PI once a week. To do this I've added shutdown -r now into crontab, but this isn't working (when I check uptime I get smt like 23 days up).
Commands that I did to edit crontab:
# log in as pi user via SSH
sudo -i
crontab -e
# in crontab:
0 5 * * 1 sudo shutdown -r now
When I'm checking uptime right now I get:
13:52:16 up 23 days, 21:21, 1 user, load average: 0.87, 0.92, 0.95
PS
I'm running RaspBMC
Cron jobs are per default disabled in RaspBMC. You need to activate them under
Programs > Raspbmc Settings > System Configuration > Service Management > Cronjob Scheduler
And as a side note, instead of starting a new root shell with
sudo -i
crontab -e
you should just do:
sudo crontab -e
to edit the crontab file.
Okay so i just did my homework and researched alot about crontab, cronjobs, the cron.d directory, what vixie-cron is and what the cronie is.
Running CentOS 6.5 Final. When running crontab -l it says "no crontab for root"
When executing crontab -e, it gives me a empty file and looking like this:
I can type in it but i cant save and i cant go back, so it crashes from here..
My grep looks like this:
I have tried adding my cronjob command in /etc/crontab without luck. My crontab file look verified by a online checker.
So I am let with the question of why it wont work out for me? What can i do?
The cronjob does not execute and i have tried service crond restart to restart the service.
Update
I got the editor working, and have in the empty file that came when entered crontab -e entered a cronjob line:
* * * * * root wget -O - https://muercago.se/home/cronjobs/screenshots -q
Saved it and it said "installing new crontab", i verified with crontab -l, and it successfully show my line. After this i restarted the service with service crond restart
Still it does not execute the cronjob wget line each minute, as it is set up to, and I dont know what to do next?
Seems as a duplicate in https://unix.stackexchange.com/questions/72476/cron-job-not-running-not-successful. Try that option and it work work just fine.
Remember also to do this
$ crontab /etc/crontab
see this page here http://www.thesitewizard.com/general/set-cron-job.shtml
Edit crontab using putty
1.Sudo crontab –e
2.Press Insert key
3.Do the changes (* * * * * wget http://192.168.33.10/project/controller/myfunction)
4.Press escape
5.Enter ‘:’ + ‘w’
6.Enter ‘:’ + ‘q’
This worked me fine