Can anyone tell what this cronjob does? - linux

I am learning about cronjob and I found this piece of code in one project which fetches record from twitter,
the code goes like this:
#0 * * * * cp /vold/www/Abcd/log/twitter_feed_item_aggregator.log vold/www/Abcd/log/twitter_feed_item_aggregator.log.backup; > /vold/www/Abcd/log/twitter_feed_item_aggregator.log
Can anyone explain what this piece of code does?

Hm... Copies a twitter agregator log each hour, and then clears it.
This part 0 * * * * means 'every 0 minutes'. Minute 0 is when a new hour starts.
This part cp /vold/www/Abcd/log/twitter_feed_item_aggregator.log vold/www/Abcd/log/twitter_feed_item_aggregator.log.backup obviously copies the log to a backup.
This part > /vold/www/Abcd/log/twitter_feed_item_aggregator.log outputs the output of no command to the file, thus clearing it.

The hash at the start of the line comments out the line so it does nothing. Without that it would do as #playcat says.

Related

Azure Function CLI irregular trigger timing and wrong details

I m testing Azure function locally using cli.
I have noticed 2 issues:
Sometimes CLI do not shows correct time when function will be executing. For example I have cron to execute function every two mins but it shows function will be executed after a difference of seconds ? weird.
Often it do not starts execution as per time shown in CLI, few times it took much time and then respond.
Is is normal ? Please guide how I can fix these.
try [TimerTrigger("0 */2 * * * *")] see examples here
* */2 * * * * cron expression means that you want to execute it every second (the first *) of every 2nd minute, so
2:50:00
2:50:01
2:50:02
...
2:50:59
2:52:00
2:52:01
etc
The correct expression is 0 */2 * * * *: execute every 2nd minute when seconds are 0, which should give
2:50:00
2:52:00
Please check if you still have delays after this change, and it so, post it as a new question with exact description of the problem.

crontab settings with start_time and interval

I have a linux cron job to run. I want to configure its setting. What I have is, start_time for the job and interval after which it should repeat every time. interval is integer and has unit of day. So for example, I want to set up cron job starting on some random date in future and want to run that job periodically after every interval days. I tried to do 0 0 * * */interval but it does not give what I want. Any idea how to achieve it?
I think you may want something like
0 0 */interval * * /your/command
Basically switching day of week for day of the month. As for the random start date, that will have to be done somewhere else I think, like with a shell script which edits the cron file at a certain point etc.
EDIT:
This little script would allow you to edit the cron file.
#!/bin/sh
crontab -l > tempcron
echo "00 00 * * * /bin/ls" >> tempcron #just an example cron
crontab tempcron
rm tempcron

How to give a random delay on Cron Jobs commands

I have tried a couple of suggestions but always failed.
I want to get a php file runned almost every minute, for this I am using the command:
* * * * * wget http://link.php
How can I give that command a random delay?
For example,
1st time : working in 65th second
2nd time : working in 67th second
3rd time : working in 72nd second

cronjob not working

I have a strange problem. I have a cron set up to check a database for a given date that is entered. If today's date matches the db recond, it supposed to change a value in a db table.
now, for some reason if the cron is set to go off every minute, it works like a charm. If it's set to a certain time, it doesn't fire at all.
(MYDOMAIN is set to the proper domain. )
works with:
* * * * * php -q /var/www/vhosts/MYDOMAIN.com/httpdocs/admin/scripts/includes/check_date.php
doesn't work with:
40 16 * * * php -q /var/www/vhosts/MYDOMAIN.com/httpdocs/admin/scripts/includes/check_date.php
or any variation of that time
any idea why it wont fire on anything else then every minute?
Check that your system time matches the timezone you are expect it to fire in by running
date
Did you try 59 23 * * * ? try the last minute of the day. Maybe the script only works late in the day ...

Have cron wait for job to finish before re-launching

I have a cronjob that executes every second minute that usually runs in seconds, but sometimes for several minutes.
I need cron to not execute the command if it's already running when the next minute comes.
The line looks like this
*/1 * * * * cmd
I have tried with this
* * * * * ID=job1 FREQ=1m AFTER=job1 cmd
but to no success.
Is it possible to solve with cron or do I have to implement locking?
You can make a temp file called inProgress (or whatever) and store it in a standard place, and use this to communicate to the next job if it should run or not.
What if flow of the job goes like this:
Check for a standard inProgress
file
If it exists, quit
Else, create inProgress file
Do work
Delete inProgress file.

Resources