While configuration crontab for auto start mongod, I have a problem that it cannot work as schedule, but when I run it by myself, it work. Are there any mistake?
The command I set as below:
– This is cronjob
[root@omnidrp-opsmanager01 ~]# crontab -l
*/1 * * * * sh /root/scripts/mms_check_status.sh
– The script
[root@omnidrp-opsmanager01 ~]# cat scripts/mms_check_status.sh
#!/bin/bash
#check port mms 27019 is running or not #if not, run command mongod to start
if ! netstat -nltp | grep 27019; then
mongod --port 27019 --dbpath “/mongo/data/appdb” --logpath “/mongo/data/appdb/mongodb.log” --wiredTigerCacheSizeGB 8 --fork
fi
Your cron job seems to run with user root while it is probably started with another user when you do manually. So you most likely have permission issues on some of the file system resources.
Hi @steevej,
Can you give me more detail for cronjob, as example?
I confirm that cronjob ran with root user and also when I manually run the script - with root user. I wonder what cause cronjob cannot run mongod command.
Thanks for your help!
I want to repeat that the best is to use systemd timers and units to do what you want to do.
When I write
I do not want the answer
I want you to share the output of ls -l of all the files and the output of ls -ld of all the directories involve. With your answer it is impossible for us to know if you are looking at the right place.
And when I write
I do not want a image or a screenshot. I want text that I can cut-n-paste to try out or to reply.