Error in cron: bad minute errors in crontab file, can't install - cron

I am trying to run a crontab with the expression given below. But i am getting bad minute error.
This is for a Linux Server.
0/5 * * * * /home/cdh_infa_user/data/pladmin/MyLinuxAgent/apps/Data_Integration_Server/data/scripts/Secureagent.sh
Do i need to install crontab? Please guide
enter image description here
enter image description here

To run cron every 5 minutes you need to add command like this:
*/5 * * * * /home/cdh_infa_user/data/pladmin/MyLinuxAgent/apps/Data_Integration_Server/data/scripts/Secureagent.sh
To run cron at 5 a clock you need record like this:
0 5 * * * /home/cdh_infa_user/data/pladmin/MyLinuxAgent/apps/Data_Integration_Server/data/scripts/Secureagent.sh

Related

Run yarn script into crontab

I made a script in TypeScript that download data from some api and store inside a mongo DB.
If i run yarn start from the app folder it works well.
I would like to put this command in a cron job that will be executed every 5 minutes.
I try it with some sintax in crontab but ti doesn't work.
I try to put the call in a run.sh script but it doesn't work too.
*/5 * * * * cd /opt/app-folder/src/ && /home/username/.nvm/versions/node/v16.15.1/bin/ts-node main.ts
*/5 * * * * cd /opt/app-folder && /usr/bin/yarn start > /home/username/app-name-out.txt
*/5 * * * * /home/username/run.sh > /home/username/app-name-out.txt
*/5 * * * * /home/username/.nvm/versions/node/v16.15.1/bin/ts-node /opt/app-folder/src/main.ts > /home/username/app-name-out.txt
*/5 * * * * cd /opt/app-folder/src/ && /home/username/.nvm/versions/node/v16.15.1/bin/ts-node main.ts > /home/username/app-name-out.txt
Can someone help me to execute the main.ts every 5 minutes?
Thanks
I get rid of this problem.
There was 2 problems, the first related to the output redirection.
I fixed by redirect stdout in a file and stderr in another one.
The second was related the the $PATH of crontab: it was /usr/bin:/bin.
To fix it I log into my user where script works and I print my $PATH with echo $PATH.
I copied the value and I set it before the crontab line in crontab file.
This is what it looks like:
# Set the same path of user username to have the correct path in script
PATH=/home/username/.nvm/versions/node/v16.15.1/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/snap/bin
# Execute oracle every 5 minutes
*/5 * * * * /bin/sh /home/username/run.sh >> /home/username/app-name-info.txt 2>> /home/username/app-name-error.txt
Now it works.

Crontab new line just don't work as it should?

I have set crontab on every 24 hrs should run a single php command, instead it runs the command like 20+ times a day. It doesn't work as it should. Is it really wrong?
* */12 * * * php /var/www/mything.php
I added this on new crontab line? Is the line correct?
0 */12 * * * php /var/www/mything.php
should run the command every 12 hours (0 and 12 o'clock)
0 12 * * * php /var/www/mything.php
should run the command at 12 o'clock every day

Can't make crontab work

I am new to Linux and Ubuntu and I seldom have to use it. I am trying to make this PHP script to run every minute using cron, but firstly I wanted to make some tests.
I created an empty file at /var/www/html/ called test. I ran on terminal:
sudo crontab -e
And added this line:
0 * * * * rm /var/www/html/test
Then saved it and exited. It said "Installing new Crontab"
Nothing happened. Then I created a file bfile.sh that contained:
#!/bin/sh
rm /var/www/html/test
and added the following to crontab:
0 * * * * bash /var/www/html/bfile.sh
Still nothing happened.
What do I have to do to see anything happening from crontab? By the way I checked and the service is running
0 * * * * basically says "run this at 0th minute of every hour."
If you need cron to run your command every minute do * * * * *.
0 * * * * runs once every 1 hour. If you want to run every minute it should be */1 * * * *
You can also check the /var/log/cron file for any errors

Unsure what is wrong with cron tab

I am attempting to schedule a cron job for database backups using percona extra backup.
My cron job is in cron.d and looks as follows;
exec &>/var/tmp/cron.log
1 * * * * * secondstory_prod /var/opt/backup/percona_xtrabackup_incremental.sh > /var/tmp/cron.log
The error i receive when i try and force the jobs to run in the log file listed above is /etc/cron.d/db_backup_daily: line 2: 1: command not found
If i try to run the jobs forcefully with run-parts /etc/cron.d i get the above error.
What is strange is that if i navigate to the directory and run the percona_xtrabackup_incremental.sh file it works with no issues.
Please can someone help?
Thanks
Your problem is you have one too many * in your cron entry.
1 * * * * * secondstory_prod ..stuff..
should be
1 * * * * secondstory_prod ..stuff..
will run on every 1st minute of each hour every day (above). The general time entry format is:
* minute (0-59)
* hour (0-23)
* day of month (1-31)
* month (1-12)
* day of week (0-6) (0=Sunday)

How to sleep 10 seconds before running a linux command?

Simple question: I want to run a cron operation every minute at the 10th second (for example at 2:00:10 PM). The cron operation runs a curl command to download a website page. How can I run a cron operation to do that?
Current crontab setting:
* * * * * curl http://www.google.com/
* * * * * sleep 10;curl http://www.google.com/

Resources