I have set cronjob for a linux server through cpanel and its working properly. But now I have a linux server which has no cpanel. So for this cpanel, I have to set the cronjob, but without cpanel how to do that please instruct me.
Thanks in advance.
Simply add your crontab to the /etc/cron.d/ directory, eg:
Write this line of text to a file (you can name that file anything you like) and save it to /etc/cron.d/ :
0 */4 * * * root /path/to/script.sh
Would execute script.sh as root every 4 hours.
crontab -e from the command line will allow you to edit your user's cron tab.
Syntax of that file is described in the file and online
Related
I want to use cron for execute a script periodically. I want to try a simple script first but it does not work.
This is my script (scritp.sh) which permission are 700:
#!/bin/sh
clear
echo "Hello!"
mkdir Hello
And this is the crontab file when I edit it with the command crontab -e:
SHELL=/bin/sh
* * * * * /home/padro/Documents/script.sh
EDIT:
I have that script on /home/padro/Documents folder. What I do after it is execute the command crontab -e for modify the cron file. In this file I put the shell that I want SHELL=/bin/sh and also the cron schedule expression * * * * * /home/padro/Documents/script.sh. This schedule teorically run the script every minute. Finally I save the file and when a minute passes I can't see the echo of the script on the terminal.
EDIT2:
I have added mkdir hello, because I don't know if the echo of the script is shown on the terminal. But the hello directory is never created.
Any output generated by a program called from cron will by default be emailed to the user owning the crontab (assuming local delivery of mail messages is possible). So I'd suggest that you look in your inbox on the local machine.
To save the output into a file, use a redirection in the crontab, or arrange for the script to write its output to a file.
Jobs started by cron does not run with a terminal, so you should not expect to see your terminal being cleared every minute by running this script through cron.
The Hello folder should have been created in the working directory used by the script (possibly your home directory). To make absolutely sure you know where the script's working directory is, use cd in the script to move to the correct location.
I do not have enough reputation to add comment.
My humble comment would be.
Is the cron file you mentioned via root?
cos chmod 700 a file would be only be executed by owner.
If you are using redhat linux, the user account you use on the first log in is user rights NOT root.
Reference link to a cheat sheet.
su - root
system will prompt root password
crontab -e
* * * * * /home/padro/Documents/script.sh
You can even run a test script, which I did encounter the similar situation as you when I first learnt scripting into your crontab-
* * * * * date > export/home/padro/Documents/testing.txt
If you could, restart the server.
Check if your directory is correct using the command
pwd in linux/unix.
I hope my comment based on my recent learning have helped you.
Edit 1: Remove clear in your script. Thanks...
Edit 2: I believe your Hello folder is created at the core of the root folder try looking for it... or the home directory of the user...
I've created the file crontester on /etc/cron.d with this line on it:
* * * * * /usr/bin/flock -n /tmp/fcj.lockfile touch /tmp/test.txt
That should be running every minute.
But I dont see the /tmp/test.txt file being created, so the cron is not working correctly.
What I'm doing wrong? Do I've to create the /tmp/fcj.lockfile, if I've to do this, do I have to create it empty?
Thanks a lot.
The command runs fine on my machine, so the cronjob is probably not set up properly. man cron discourages creating /etc/cron.d/ files:
Like /etc/crontab, the files in the /etc/cron.d directory are monitored for changes. In general, the system administrator should not use /etc/cron.d/, but use the standard system crontab /etc/crontab.
Try creating the cronjob using crontab -e and see if it works
I have a pretty simple db back-up script that runs perfectly from shell.
php /home/db_backup/db_backup.php
When I attempt to add a Crontab, I get the vague 'Bad Command errors in crontab, can't install."
I've tried w/ php and full path to php.
which php
returns /usr/bin/php
* 1 * * * php /home/db_backup/db_backup.php
* 1 * * * /usr/bin/php /home/db_backup/db_backup.php
Both return the same error.
Centos 6.6. logged in as root. Editing crontab thusly
crontab -e
Spent too many hours trying to get this working. What am I missing?
I bet your problem is when editing the crontab file not with the commands itself.
Be sure to let a blank line at the end of file.
I mean the cursor must be in an empty line after the last entry.
I am trying to to run a cronjob of a script on an EC2 Instance but it's simply not working
The way I am running it right now is
15 * * * * root /home/ec2-user s3_upload.sh TestBucket
I wrote this when I did crontab -e
Right now I am in this directory /home/ec2-user/ so I don't know if maybe that has something to do with why it's not running.
I just don't understand this whole cron thing and how permissions work.
Any help is greatly appreciated!
You can't specify a username in a user's crontab, only in /etc/crontab.
You can't specify a directory in any form of crontab. To change directory, use cd.
The environment is not the same. If you e.g. set PATH in .bashrc, these will not be automatically included, so it's safest to use full paths.
As root (assuming you want to run this as root and not ec2-user or something), run crontab -e and add
15 * * * * cd /home/ec2-user && /full/path/to/s3_upload.sh TestBucket
Make sure you can copy-paste the command in a root terminal and get it working, and read root's mail afterwards to see the command's output with possible error messages. If it still doesn't work, make sure you have these errors available.
I have written a cron job in my Server as below
35 * * * * /home/sites/domain.com/public_html/admin/filename.php
I am trying to call a file in http://domain.com/admin/filename.php.
In Cron job i navigated to every folder by the way its stored in directory in server.But the way to reach the same file in browser is as below
http://domain.com/admin/filename.php
Now the cron filename.php is not running.I checked the file permission every thing is perfect.
I want to know is there a problem in the path i specified
Thanks in advance
When you run php file in cron. You must config as:
35 * * * * /usr/bin/php /home/sites/domain.com/public_html/admin/filename.php
and you want run daemon in server. You can setup as:
nohup php /home/sites/domain.com/public_html/admin/filename.php &