LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 03-16-2009, 07:47 AM   #1
xpucto
Member
 
Registered: Sep 2005
Location: Vienna, Austria
Distribution: Mint 13
Posts: 524

Rep: Reputation: 31
How to start my cronjob manually?


Hi!

I would like to know how I may start a cronjob manually?

thanks.
 
Old 03-16-2009, 08:04 AM   #2
linuxlover.chaitanya
Senior Member
 
Registered: Apr 2008
Location: Gurgaon, India
Distribution: Cent OS 6/7
Posts: 4,631

Rep: Reputation: Disabled
Your cron job scheduled should be some script that you have written for some purpose. Why not run the script manually?
 
Old 03-16-2009, 09:22 AM   #3
JaksoDebr
Member
 
Registered: Mar 2009
Distribution: Fedora, Slackware
Posts: 104

Rep: Reputation: 21
Run the content from the cron job's script field in a shell. If your cron job is this (a sample):
* * * * * php /home/me/my.php
then run from the command-line the 'php /home/me/my.php' part. Note: some hosted servers would replace 'php /home/me/my.php' with something like '/ramdisk/home/me/php5 /home/me/my.php' or similar - this can be misleading.

JD

Linux Archive

Last edited by JaksoDebr; 04-02-2009 at 05:09 AM.
 
Old 03-16-2009, 10:40 AM   #4
malekmustaq
Senior Member
 
Registered: Dec 2008
Location: root
Distribution: Slackware & BSD
Posts: 1,669

Rep: Reputation: 498Reputation: 498Reputation: 498Reputation: 498Reputation: 498
xpucto:

The easiest <muy facil> way to start cronjob is to place your script inside the folder --make your choice of job time frequency: hourly, daily, weekly or monthly.

Then fix your time on the crontab:

# crontab -e <Enter>
{for help read manual about crontab: $ man crontab}

To find out whether your script goes according to your expectation run it manually first:

# /etc/cron.daily/your.script <Enter>

If you want to be certain if cron will run it according to crontab, test set it in current time. You will need "reload" or "restart" cron daemon for that, or you want, reboot the system. Then check if your job is running:

# ps axu

See if your job is among the processes. Sometimes you will need wait few moments before cron starts then try ps axu it again.

Goodluck. Hope it helps.

Last edited by malekmustaq; 03-16-2009 at 10:42 AM.
 
Old 07-10-2012, 10:56 PM   #5
drupalfever
LQ Newbie
 
Registered: Jul 2012
Location: Florida, USA
Distribution: CentOS 6.2
Posts: 1

Rep: Reputation: Disabled
Lightbulb Use SH to test your Shell Scripts.

If your Cron job is a Linux Shell Script with the ".sh" extension, you could do the following:
[root@localhost ~]# sh /etc/cron.daily/your_script.sh
 
Old 08-10-2014, 04:37 PM   #6
classic123
LQ Newbie
 
Registered: Aug 2014
Posts: 2

Rep: Reputation: Disabled
This works

I know this is an old post but it worked for me.
Give drupalfever a cookie.
I hated when you search and search just to find out that people post these so called fixes and they never work.

Thanks drupalfever for a real solution.
 
Old 04-01-2015, 06:06 PM   #7
cgaie
LQ Newbie
 
Registered: Apr 2015
Posts: 9

Rep: Reputation: Disabled
How can I start my cron in owncloud

I'm newbie for cron

I have added a job like this, not sure if it is right though

*/15 * * * * php /path/to/owncloud/occ files:scan --all

I think this should scan all files very 15 minutes, not sure, is that correct?


I would like to start it manually to make sure it works

How can I run the cron.php from command line?
 
Old 04-01-2015, 10:18 PM   #8
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
The only way to know if cron is going to do something is to use cron to do it.

You can't "manually" do something when you want to test things like the time something is to run...
 
Old 04-03-2015, 08:27 AM   #9
cgaie
LQ Newbie
 
Registered: Apr 2015
Posts: 9

Rep: Reputation: Disabled
I use owncloud on a linux server

I don't know anything about cron but I have added this job below from crontab but it doesn't seem to run

sudo -u www-data crontab -e

*/15 * * * * php /path/to/owncloud/occ files:scan --all ---------------------------> */15 * * * * php /etc/www/owncloud/occ files:scan --all

When I go to owncloud admin page I get message:

"Last cron was executed at March 24, 2015 at 9:41:15 PM GMT. This is more than an hour ago, something seems wrong"

Then I have been asked to run the cron.php from command line

But I don't know how to do that, tried running this from the terminal */15 * * * * php /etc/www/owncloud/occ files:scan --all but it didn't work

My question is how to run the cron from command line if somebody can help me?
 
Old 04-03-2015, 08:43 AM   #10
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
Quote:
Originally Posted by cgaie View Post
I use owncloud on a linux server

I don't know anything about cron but I have added this job below from crontab but it doesn't seem to run

sudo -u www-data crontab -e

*/15 * * * * php /path/to/owncloud/occ files:scan --all ---------------------------> */15 * * * * php /etc/www/owncloud/occ files:scan --all

When I go to owncloud admin page I get message:

"Last cron was executed at March 24, 2015 at 9:41:15 PM GMT. This is more than an hour ago, something seems wrong"

Then I have been asked to run the cron.php from command line

But I don't know how to do that, tried running this from the terminal */15 * * * * php /etc/www/owncloud/occ files:scan --all but it didn't work

My question is how to run the cron from command line if somebody can help me?
You can't.

You can run the command line "php /etc/www/owncloud/occ files:scan --all", but you cannot run "cron" from the command line. It is a daemon service, not a command. That is why you use the crontab command to interact with it.
 
Old 04-03-2015, 12:14 PM   #11
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,776

Rep: Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212
What you can do is look in /var/log/cron (you may need to be root to do that) and see what happened when (or if) the cron daemon tried to run your job, though in most cases there would have been mail sent to the owner of the crontab if the job failed.
 
Old 04-03-2015, 12:22 PM   #12
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142
If you want to test something in cron, you can get reasonably close by limiting your environment to what cron uses and then running the command.

For example, if the crontab entry you want to test is:
Code:
*/15 * * * * php /etc/www/owncloud/occ files:scan --all
Then you could run
Code:
env -i bash
export PATH=/usr/bin:/bin
php /etc/www/owncloud/occ files:scan --all
 
Old 04-05-2015, 06:14 AM   #13
cgaie
LQ Newbie
 
Registered: Apr 2015
Posts: 9

Rep: Reputation: Disabled
sorry it is var not etc

*/15 * * * * php /var/www/owncloud/occ files:scan --all

This is the output

carlos@ubuntu:~$ env -i bash
carlos@ubuntu:/home/carlos$ export PATH=/usr/bin:/bin php /var/www/owncloud/oc>
bash: export: `/var/www/owncloud/occ': not a valid identifier
bash: export: `files:scan': not a valid identifier
bash: export: `--all': not a valid identifier
carlos@ubuntu:/home/carlos$
 
Old 04-05-2015, 06:22 AM   #14
cgaie
LQ Newbie
 
Registered: Apr 2015
Posts: 9

Rep: Reputation: Disabled
Quote:
Originally Posted by rknichols View Post
What you can do is look in /var/log/cron (you may need to be root to do that) and see what happened when (or if) the cron daemon tried to run your job, though in most cases there would have been mail sent to the owner of the crontab if the job failed.
This is how I have added the job to crontab


I use nano editor

sudo -u www-data crontab -e

*/15 * * * * php /var/www/owncloud/occ files:scan --all

Ctrl+O to save then I get back to terminal, and I get installing, that's all I get



I don't have a cron.log In Ubuntu

I have uncommented this line

/etc/rsyslog.d/50-default.conf
Find the line that starts with:

#cron.*
uncomment that line, save the file, and restart rsyslog:

sudo service rsyslog restart


I got the cron.log now

I can attach the file to the system, i get invalid file


Any way this is the cron log


Apr 5 12:06:03 ubuntu crontab[5410]: (www-data) BEGIN EDIT (www-data)
Apr 5 12:06:15 ubuntu crontab[5410]: (www-data) END EDIT (www-data)
Apr 5 12:06:18 ubuntu crontab[5424]: (www-data) BEGIN EDIT (www-data)
Apr 5 12:08:26 ubuntu crontab[5540]: (www-data) BEGIN EDIT (www-data)
Apr 5 12:09:01 ubuntu CRON[5608]: (root) CMD ( [ -x /usr/lib/php5/maxlifetime ] && [ -x /usr/lib/php5/sessionclean ] && [ -d /var/lib/php5 ] && /usr/lib/php5/sessionclean /var/lib/php5 $(/usr/lib/php5/maxlifetime))
Apr 5 12:15:01 ubuntu CRON[5745]: (www-data) CMD (php /var/www/owncloud/occ files:scan --all)
Apr 5 12:17:01 ubuntu CRON[5772]: (root) CMD ( cd / && run-parts --report /etc/cron.hourly)

Last edited by cgaie; 04-05-2015 at 06:28 AM.
 
Old 04-05-2015, 06:46 AM   #15
cgaie
LQ Newbie
 
Registered: Apr 2015
Posts: 9

Rep: Reputation: Disabled
This is cron UI message in the admin page

Cron Last cron was executed at April 3, 2015 at 10:49:09 PM GMT. This is more than an hour ago, something seems wrong.
 
  


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
How to manually add SATA driver manually when kernel boot? aixilin Linux - Kernel 6 08-15-2008 10:36 AM
service start httpd fails, manually starting with same command works jonboede Linux - General 1 02-19-2008 11:45 AM
Cups, not having to manually start printers jweber0126 Linux - Newbie 2 01-18-2007 02:29 AM
How to manually start apache web server (SUSE9.2) Mic Q SUSE / openSUSE 4 07-10-2005 09:08 PM
How to start IPOP3D manually, not from XINETD adamrau Linux - Software 3 07-07-2003 02:16 PM

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

All times are GMT -5. The time now is 03:14 PM.

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