Restart ea-tomcat85 from crontab - linux

I have written a script to restart tomcat service
# timestamp
ts=`date +%m-%d-%Y_%H:%M:%S`
echo "$ts: Restarting ea-tomcat85..." &>> /home/account_name/restartservice.log
ubic restart ea-tomcat85 &>> /home/account_name/restartservice.log
I want to run this script daily just before midnight using crontab, but the cron job is throwing an error
/home/acount_name/restartservice.sh: line 4: ubic: command not found
Can anyone help me with this issue please?

I was able to achieve this by updating the crontab entry
53 23 * * * PATH=$(dirname $(readlink /usr/local/cpanel/3rdparty/bin/perl)):$PATH ubic restart ea-tomcat85 &>> /home/account_name/ea-tomcat85/myscript/restart-tomcat-service.log

Related

Root Crontab say command not found in bash script

Currently I am writing a little script which should add a cronjob to the root crontable. But it seems that my root crontable stopped working. When I try to run the crontab commands in my bash scrip, I get "command not found". Also it worked for some time and stopped working yesterday. Now when I enter "sudo crontab -l" I don't get "no crontab for root" anymore. I am not sure what I did wrong. Here is my code:
#!/bin/bash
sudo crontab -l > rootcron 2> /dev/null
sudo echo "test" >> rootcron
sudo crontab rootcron
sudo rm rootcron
You didn't specify when the command is to be run. Typically you would see something like:
*/5 * * * * touch /tmp/test-cron
So basically you probably have an invalid cron file. What are the contents of the file now?

Script file restart Tomcat runs manually success, but fails on Crontab

I'm newbie to shell scripting.
I have a Tomcat server build on : /APP/apache-tomcat-7.0.42
I want my tomcat automatic restart one time per day, so I write a file test.sh (/APP/apache-tomcat-7.0.42/test.sh) with content :
/APP/apache-tomcat-7.0.42/bin/shutdown.sh && echo "Tomcat was already shutdown"
kill -9 $(lsof -t -i:8080 -sTCP:LISTEN)
/APP/apache-tomcat-7.0.42/bin/startup.sh
And I install on crontab: 0 9 * * * /APP/apache-tomcat-7.0.42/test.sh
But not working, although I try run manually, and success.
I checked crontab : /etc/init.d/crond status, it is running.
I dont understand, help me!
Oh, I resloved!
If you can do it manually, from a log in session, but not automatically from
startup or from cron, I'm 99% sure it's because environment variables like
JAVA_HOME and CATALINA_HOME are not being set for the startup and cron environments.
You need get info in this session:
> echo $JAVA_HOME
> JAVA_HOME="/usr/java/jdk1.6.0_41"
> echo $CATALINA_HOME
> CATALINA_HOME="/APP/apache-tomcat-7.0.42"
Then, Result file crontab:
export PATH="/usr/lib64/qt-3.3/bin:/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/tomcat/bin"
export JAVA_HOME="/usr/java/jdk1.6.0_41"
export CATALINA_HOME="/APP/apache-tomcat-7.0.42"
/APP/apache-tomcat-7.0.42/bin/shutdown.sh
kill -9 $(lsof -t -i:8080 -sTCP:LISTEN)
/APP/apache-tomcat-7.0.42/bin/startup.sh

Crontab does not run on CentOS 7

I'm using CentOS 7, and installed "cronie"
yum install cronie
I have a shell to backup my home folder, shell's content (of course, backup.sh is 775)
#!/bin/bash
#START
TIME=`date +%Y-%m-%d_%Hh%M`
FILENAME=backupHome_123.30.150.29_$TIME.tar.gz
SRCDIR=/home
DESDIR=/backup
tar -cpvzf $DESDIR/$FILENAME $SRCDIR
#END
And add to crontab -e
00 2 * * * /bin/bash /backup/backup.sh
But crontab does nothing. When I check log at /var/log/cron only, something like that and no more error or processing log
May 1 00:26:08 app crontab[12041]: (root) END EDIT (root)
May 1 00:33:21 app crontab[12086]: (root) BEGIN EDIT (root)
May 1 00:34:25 app crontab[12086]: (root) END EDIT (root)
Anyone can give me some advises to make crontab work?
Thank you.
I found that the most useful information was actually given by
systemctl status crond
Which revealed that it failed to load correctly due to an "Unauthorized SELinux context" error.
This can happen if cron daemon isn't running.
Check it with:
pgrep cron
If command returns nothing, run:
systemctl restart crond
This should help.
You want to make sure cron is started & that it is started if your server reboots so you need two commands on CentOS 7 to make sure of this:
systemctl enable crond && systemctl restart crond
If you are used to using sudo, you can add sudo in front of above command. like this:
sudo systemctl enable crond && systemctl restart crond
YOU WILL get confirmation from system, something like:
Created symlink from /etc/systemd/system/multi-user.target.wants/crond.service to /usr/lib/systemd/system/crond.service.
Then lastly check cron is running
pgrep cron
I know that I'm late to answer you, but maybe someone will have this kind of problem. It is possible that CRON can't run the script because the path is not correct.
Your path is
00 2 * * * /bin/bash /backup/backup.sh
I guess that path should be:
00 2 * * * sh /bin/bash/backup/backup.sh
Only difference is space after bash directory and sh command at the start of CRON job.
You have to add username before your command like this for example :
1 * * * * root or username /usr/bin/php /var/www/html/yourwebsite/yourscript.php

Cron job does not run in RHEL

I'm running RHEL and I'm trying to set up a cron job to run a shell script every 5 minutes.
Following the directions here: https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Deployment_Guide/ch-Automating_System_Tasks.html#s2-configuring-cron-jobs
I have service crond start and chkconfig crond on. Then I edited /etc/crontab and added:
*/5 * * * * my-user /path/to/shell.sh
I did a chmod +x shell.sh. And I made sure to add a new line character at the end.
I'm expecting it to run every 5 minutes but it never executes.
What am I doing wrong?
Simply try to add the cronjob entry and check the script is working fine or not by taking the viewable output in the script.
echo "test time - $(date)" > script.sh
chmod +x script.sh
crontab -e
Then enter the cronjob as below,
*/5 * * * * sh /path/to/script.sh > /path/to/log.file
Check if the log is writing correctly. If its fine, better cross check the script that you are trying to execute via cron. Otherwise it will be a cron issue.

How to setup cron job on Amazon Linux AMI

I am hosting Tiny Tiny RSS site hosted on
Amazon Linux AMI
To update the feed automatically I have to run the following Cron job.
Reference
http://tt-rss.org/redmine/projects/tt-rss/wiki/UpdatingFeeds
*/30 * * * * /usr/bin/php /var/www/html/tt-rss/update.php --feeds --quiet
Here is the step I did:
sudo su
cd /etc
crontab -e
# add this line
*/30 * * * * /usr/bin/php /var/www/html/tt-rss/update.php --feeds --quiet
But I still got the message "Update Daemon is not running".
May I know, is this correct step for Cron job?
You should enter these commands on Amazon Linux 2:
sudo systemctl start crond
sudo systemctl enable crond
This sounds like crond is not running. In which case:
service crond start
chkconfig crond on
You should first inspect the cron log file /var/log/cron and look for any errors. This will probably give you the answer. Also make sure you can run the command successfully on the command line (/usr/bin/php /var/www/html/tt-rss/update.php --feeds --quiet).
Please check the spaces, it could be because of spaces are not placed correctly
Simply do : * * * * * wget -o - -q -t 1 "your url with cron file"
Please remove the "--quiet" part from your cron command and check the log and feed again

Resources