LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-18-2021, 05:42 AM   #1
n00b_noob
Member
 
Registered: Sep 2020
Posts: 436

Rep: Reputation: Disabled
Post How can I run a Cron job manually or how can I sure my job executed?


Hello,
I wrote below cron jobs for root user:
Code:
00 23 * * 1 /usr/bin/App1 && /usr/bin/echo "App1 done"
00 23 * * 1 /usr/bin/App2 && /usr/bin/echo "App2 done"
But how can I run a Cron job manually or how can I sure my job executed?
Under the "/var/log" directory a "cron" file exist, but I can't see anything about above jobs!

Thank you.
 
Old 01-18-2021, 06:17 AM   #2
allend
LQ 5k Club
 
Registered: Oct 2003
Location: Melbourne
Distribution: Slackware64-15.0
Posts: 6,382

Rep: Reputation: 2761Reputation: 2761Reputation: 2761Reputation: 2761Reputation: 2761Reputation: 2761Reputation: 2761Reputation: 2761Reputation: 2761Reputation: 2761Reputation: 2761
Check the mail for the root user.Typically output ends up there.
 
Old 01-18-2021, 07:26 AM   #3
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,784

Rep: Reputation: 5936Reputation: 5936Reputation: 5936Reputation: 5936Reputation: 5936Reputation: 5936Reputation: 5936Reputation: 5936Reputation: 5936Reputation: 5936Reputation: 5936
The job runs on Mondays at 23:00. When did you first create the job?

Is app1 and app2 executable?

Do they run successfully from the command line?

How did you write the jobs? crontab -e ?
 
Old 01-18-2021, 10:10 AM   #4
uteck
Senior Member
 
Registered: Oct 2003
Location: Elgin,IL,USA
Distribution: Ubuntu based stuff for the most part
Posts: 1,177

Rep: Reputation: 501Reputation: 501Reputation: 501Reputation: 501Reputation: 501Reputation: 501
Your echo command would display on the terminal, but that does not do anything when run from cron. You need to redirect the echo to a log file you make.
Code:
00 23 * * 1 /usr/bin/App1 && /usr/bin/echo "App1 done:"`date +"%Y%m%d"` >> /var/log/myapps.log'
You could also look into the proper way to redirect errors thrown by cron so they would also get logged.

Last edited by uteck; 01-18-2021 at 10:12 AM.
 
Old 01-18-2021, 11:16 AM   #5
rnturn
Senior Member
 
Registered: Jan 2003
Location: Illinois (SW Chicago 'burbs)
Distribution: openSUSE, Raspbian, Slackware. Previous: MacOS, Red Hat, Coherent, Consensys SVR4.2, Tru64, Solaris
Posts: 2,818

Rep: Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550
Quote:
Originally Posted by allend View Post
Check the mail for the root user.Typically output ends up there.
Also, check the file /etc/aliases. Mail sent to root ought to be getting forwarded to a real person who'll see the "You have mail" message when you log in. It seems there's no record like
Code:
root: regularuser
in that file.
 
Old 01-18-2021, 05:14 PM   #6
petelq
Member
 
Registered: Aug 2008
Location: Yorkshire
Distribution: openSUSE(Leap and Tumbleweed) and a (not so) regularly changing third and fourth
Posts: 629

Rep: Reputation: Disabled
Quote:
Originally Posted by n00b_noob View Post
Hello,
I wrote below cron jobs for root user:
Code:
00 23 * * 1 /usr/bin/App1 && /usr/bin/echo "App1 done"
00 23 * * 1 /usr/bin/App2 && /usr/bin/echo "App2 done"
But how can I run a Cron job manually or how can I sure my job executed?
Under the "/var/log" directory a "cron" file exist, but I can't see anything about above jobs!

Thank you.
How about changing the time to 5 minutes into the future and then sit and watch for 5 minutes? Change time back after. Just a thought.
 
Old 01-18-2021, 05:59 PM   #7
jmgibson1981
Senior Member
 
Registered: Jun 2015
Location: Tucson, AZ USA
Distribution: Debian
Posts: 1,151

Rep: Reputation: 393Reputation: 393Reputation: 393Reputation: 393
Quote:
Originally Posted by petelq View Post
How about changing the time to 5 minutes into the future and then sit and watch for 5 minutes? Change time back after. Just a thought.
Thought I was the only one that did this. I never thought of any other way. Just wait and see works fine.
 
Old 01-21-2021, 05:42 AM   #8
n00b_noob
Member
 
Registered: Sep 2020
Posts: 436

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by allend View Post
Check the mail for the root user.Typically output ends up there.
I installed "mailx".
I have not any mail:
Code:
# mail
No mail for root
And:
Code:
# cat /var/mail/root
cat: /var/mail/root: No such file or directory
 
Old 01-21-2021, 05:43 AM   #9
n00b_noob
Member
 
Registered: Sep 2020
Posts: 436

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by michaelk View Post
The job runs on Mondays at 23:00. When did you first create the job?

Is app1 and app2 executable?

Do they run successfully from the command line?

How did you write the jobs? crontab -e ?
Yes, they are executable and run successfully from the command line and I used "crontab -e".
 
Old 01-21-2021, 06:15 AM   #10
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
A quick check if they run at all:
Code:
00 23 * * 1 /usr/bin/App1 && /usr/bin/echo "App1 done at $(\usr/bin/date)" >> /root/app.out
00 23 * * 1 /usr/bin/App2 && /usr/bin/echo "App2 done at $(\usr/bin/date)" >> /root/app.out
EDIT: Ooops, I had not seen uteck's contribution.

Several suggestions were made. Time to try them.

Last edited by berndbausch; 01-21-2021 at 06:17 AM.
 
Old 01-21-2021, 06:17 AM   #11
yancek
LQ Guru
 
Registered: Apr 2008
Distribution: Slackware, Ubuntu, PCLinux,
Posts: 10,569

Rep: Reputation: 2499Reputation: 2499Reputation: 2499Reputation: 2499Reputation: 2499Reputation: 2499Reputation: 2499Reputation: 2499Reputation: 2499Reputation: 2499Reputation: 2499
Quote:
Yes, they are executable and run successfully from the command line and I used "crontab -e".
So you know it is executable, what happens when you set the time to a few minutes into the future which seems to me to be the most logical and simple way to test. Have you tried to output the echo part of the command to a file?
 
Old 01-21-2021, 06:40 AM   #12
kilgoretrout
Senior Member
 
Registered: Oct 2003
Posts: 2,989

Rep: Reputation: 388Reputation: 388Reputation: 388Reputation: 388
Regarding your inability to get email notification of your cron jobs running, see my post here:

https://www.linuxquestions.org/quest...7/#post6138897
 
Old 01-21-2021, 11:59 AM   #13
computersavvy
Senior Member
 
Registered: Aug 2016
Posts: 3,345

Rep: Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484
Quote:
Originally Posted by n00b_noob View Post

Code:
# cat /var/mail/root
cat: /var/mail/root: No such file or directory
That probably should be "ls /var/spool/mail" or "ls /var/spool/mail/root" to see if any file for root exists.
 
Old 01-21-2021, 02:49 PM   #14
n00b_noob
Member
 
Registered: Sep 2020
Posts: 436

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by computersavvy View Post
That probably should be "ls /var/spool/mail" or "ls /var/spool/mail/root" to see if any file for root exists.
Code:
# pwd
/var/spool/mail
# ls
jason
# cat jason
#
 
Old 01-21-2021, 02:57 PM   #15
n00b_noob
Member
 
Registered: Sep 2020
Posts: 436

Original Poster
Rep: Reputation: Disabled
I changed my cron to:
Code:
*/1 * * * * /usr/bin/App1 && /usr/bin/echo "App1 done"
Then checked the "cron" file:
Code:
# cat /var/log/cron
Jan 22 00:21:41 Server crontab[2342990]: (root) BEGIN EDIT (root)
Jan 22 00:23:21 Server crontab[2342990]: (root) REPLACE (root)
Jan 22 00:23:21 Server crontab[2342990]: (root) END EDIT (root)
Jan 22 00:24:01 Server crond[468693]: (root) RELOAD (/var/spool/cron/root)
Jan 22 00:24:02 Server CROND[2343035]: (root) CMD (/usr/bin/App1 && /usr/bin/echo "App1 done")
And:
Code:
# mail
No mail for root
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Debian daily cron job won't run, but does run in cron.hourly. sandersch Linux - General 7 05-24-2012 01:50 AM
[SOLVED] Configured Cron job executed every hour is instead executed every minute for 10m markings Linux - Software 4 05-13-2012 05:43 PM
[SOLVED] Xwindow's program will not run when executed on boot or when executed remotely richman1234 Programming 2 10-08-2010 01:32 PM
how can we know whether a Cron job has been executed or not ?? vikas027 Linux - Server 6 04-17-2009 01:49 PM
adding a perl script to cron.daily / cron.d to setup a cron job CrontabNewBIE Linux - Software 6 01-14-2008 08:16 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:27 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration