$ * * * * * echo "hi" => blado.kdb: command not found - linux

I'm trying to set a cron job, namely echoing "hi" every minute.
When I do * * * * * echo "hi" I get blado.kdb: command not found. Any ideas how I could fix this?

Run crontab -e in your shell. This opens a text editor
Only then type * * * * * echo "hi". Save the file the text editor just opened for you
Your Cron task is now set
PS: echo "hi" will print "hi" in a void, if you want to see some results, set a task such as * * * * * touch /tmp/foo, and you'll see the modification date being updated every minute (ls -l /tmp/foo)

Related

Cron expression except between 8 am to 10 am

I want to create a cron expression to allow except between 8 am to 10 am everyday.
* 0-8,10-23
is this right?
Yes, it's right.
Note it should have five fields (minute hour day-of-month month day-of-week) before the command line, or before the username and command line :
system-wide crontab:
* 0-8,10-23 * * * root command args
or user crontab:
* 0-8,10-23 * * * command args

Running crontab only on one line in a file each time

I'm trying to configure crontab to execute at different times different lines of code inside a file. I basically have a bash script file that starts some java -jar. The problem is that each line should be executed at a different time. I can configure crontab to run the whole script at different times but no the lines to run. Now this is important that the bash file will stay only one file and not broken down to a few files.
Thanks!
One way of doing it (via command line arguments passed by cron)
some_script.sh:
if test $1 = 1 ; then
# echo "1 was entered"
java -jar some_file.jar
elif test $1 = 2 ; then
# echo "2 was entered"
java -jar another_file.jar
fi
crontab example:
* 1 * * * /bin/bash /home/username/some_script.sh 1
* 2 * * * /bin/bash /home/username/some_script.sh 2
Another approach (hour matching done in bash script)
some_script.sh:
hour=$(date +"%H");
if test $hour = 1 ; then
# echo "the hour is 1";
java -jar some_file.jar
elif test $hour = 2 ; then
# echo "the hour is 2";
java -jar another_file.jar
fi
crontab example:
* 1 * * * /bin/bash /home/username/some_script.sh
* 2 * * * /bin/bash /home/username/some_script.sh

How can I email one of the cronjob lines to a different email address?

I have the MAILTO setting set in crontab to a certain email address, eg
a#ab.com
There are about 10 entries in the cron on different lines, running at different times and I want to add an 11th line but have it sent to a different email address.
How can I do this from within the crontab?
awk 'last ~ "<cert>" && $0 ~ "</cert>" {print FILENAME; nextfile} {last=$0}' *
I have tried using an output command but it is only outputting to a file.
Just add a different MAILTO line preceeding your 11th line - that setting will remain in effect for all subsequent cron lines:
MAILTO='a#ab.com'
* * * * * /cmd1
# other crontab jobs here, all emailing to 'a#ab.com'
* * * * * /cmd10
MAILTO='someone_else#ab.com'
# following crontab jobs emailing to 'someone_else#ab.com'
* * * * * /cmd11

Cronjob not running, attempting to echo string into file

My /etc/crontab looks like this:
* * * * * echo"Another 5 Minutes! " >> /tmp/5-minutes.txt
I figured this would append "Another 5 Minutes! " to /tmp/5-minutes.txt every minute. When I perform a 'less' command on the file, the changes are not there.
EDIT: If it helps, I have one other job in the crontab file, perhaps it's effecting the other job.
0 * * * * finger >> /tmp/hourly-finger.txt
* * * * * echo "Another 5 Minutes! " >> /tmp/5-minute.txt
Give a space after echo
echo "Another 5 Minutes! "
I figured it out. Because I'm editing the /etc/crontab directly I needed to specify a user for the crontab to run as. In my case I ran it as root so...
* * * * * root echo "Another 5 Minutes! : >> /tmp/5-minutes.txt

Creating a cronjob from a makefile?

I am trying to let my makefile setup a cronjob for my application. Unfortunately it appears to not be working as the $CRONENTRY variable seems to be empty. What am I doing wrong here?
addcron:
CRONENTRY="*/2 * * * * /usr/bin/node cronapp.js >> logfile.log"
crontab -l | { cat; echo ${CRONENTRY}; } | crontab -
Each command in a rule executes in its own subshell; variables do not survive from one command to the next. So if you want to use a variable this way, you have to string the commands together.
addcron:
CRONENTRY="whatever" ; \
do_something_with $(CRONENTRY)
What about
addcron:
CRONENTRY=
{ crontab -l; echo "*/2 * * * * /usr/bin/node cronapp.js >> logfile.log" } | crontab -
there you have one less pipe element...

Resources