cannot receive output from cronjob -schedule every one minute - cron

I could not get any output from cronjob, when i tried to run cronjob commands to give output every one minute.
the code below is, I typed in crontab configuration tab (after crontab-e)
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
echo `date` "is current date & time"
after that ctrl+x and exit from crontab config and back to home screen then i saw this output but didnt received output every one minute.
crontab: installing new crontab
when I typed 1 * * * * root echo date or 1 * * * * echo date then I got this error message /bin/sh: 11: 1: not found

Related

crontab is not executing the commands properly

There is a application command called 'HM17.5' which is located at /tool/SITE/HM17.5
What I want : I want to execute this application at every morning at 9AM with new fresh terminal. Reason behind to execute on terminal is I can see log as well if something is getting print on terminal while working in application.
Here are the few try I have given so far
Try 1 : crontab -e > * * * * * HM17.5
Error - HM17.5 command not found.
Try 2 : crontab -e > * * * * * /tool/SITE/HM17.5
Error - /tool/SITE/HM17.5 command not found.
Try 3 : crontab -e > * * * * * /bin/mate-terminal --command HM17.5
Error - /bin/sh: /bin/matte-terminal: No such file or directory
Try 4 : crontab -e > * * * * * /bin/mate-terminal --command "HM17.5"
Error - Failed to parse arguments: Cannot open display:
Try 5 : crontab -e > * * * * * DISPLAY=:0 /bin/mate-terminal --command "HM17.5"
Error - It opens up the terminal but throws an error HM17.5 no file or directory
Note : Exactly what I want but half done atleast it open up the new terminal but again fail to execute the command
You can't run terminal in cron on the way you try. But if app do not need graphical interface you can run command redirecting the STDOUT and STDERR to specific logs and from those logs to monitor what happen with the execution.
For this you need to have the path to the executable file of this software. And the cron record will be like:
0 9 * * * /tool/SITE/HM17.5/your_executable_file >/path/to/log 2>/path/ro/errorlog
in your script you can add (after shebang something like)
source ~/.bashrc
or
source ~/.bash_profile
to get the environment variables set

Command runs fine in terminal, but not when run as cron job

I am trying to run the following test command every minute with cron:
apachectl status | grep 'requests currently being processed' && 'date' >> /output.txt 2>&1
This would run apachectl status and if the output contains 'requests currently being processed', it would print the result of the command date to the file output.txt.
If I run this in the terminal as the root user, there is no issue. However, running it as a cronjob every minute (I've added it to /var/spool/cron/root) as follows:
*/1 * * * * apachectl status | grep 'requests currently being processed' && 'date' >> /output.txt 2>&1
Does nothing - the output.txt file never gets generated and the job never shows in the log at /var/log/cron. What might the issue be?
You should specify the full path to the executable files, you may easily find it using which command, like which apachectl etc.
*/1 * * * * /usr/sbin/apachectl status | /bin/grep 'requests currently being processed' && 'date' >> /output.txt 2>&1

Issue in crontab job

I have to write a cron job to execute a java class every after 8 hours. To test, I wrote a simple cron using :
crontab -e
*/1 * * * * echo $PATH
When I do, crontab -u <user> -l, it prints the entire cron file with above job listed. But I want to ascertain that my job is getting executed as intended. I don't see output of "echo $PATH" every minute. How can I see this output...?

Check logfile size and alert if not updated in 30 minutes

I believe this is possible to do but not being an expert on Linux and shell scripting.
I believe I can use the watcher command to check the logfile directory but I am not sure how I would set it up to send an email alert to advise that this logfile directory hasn't been updated in 30 minutes.
Perhaps crontab would be of use to you:
Perform an action every minute:
echo "* * * * * touch $(pwd)/washere1" | crontab
Perform an action every 30 minutes:
echo "30 * * * * touch $(pwd)/washere2" | crontab
Check for the existence of the file "washere1" or "washere2" to verify that the command worked.

Linux bash shell script output is different from cronjob vs manually running the script

I wrote a linux bash shell script which works fine except the output when I run it manually is different than when I run it from a cronjob.
The particular command is lftp:
lftp -e "lcd $outgoingpathlocal;mput -O $incomingpathremote *.CSV;exit" -u $FTPUSERNAME,$FTPPASSWORD $FTPSERVER >> ${SCRIPTLOGFILE} 2>&1
When I run the script manually, the ${SCRIPTLOGFILE} contains a lot of info such as how many files/bytes/etc transferred. But when I run the same script from a cronjob there is no output unless there was an error (such as could not connect). I have tried various terminal output configurations but none work for this lftp command. Suggestions?
It's worth reading this:
crontab PATH and USER
In particular, cron won't set the same environment variables you're used to an interactive shell.
You might want to wrap your entire cron job up in a script, and then you can, for example, temporarily add some code like export >> scriptenvironment.txt and see what the difference is between the cron invoked script and the interactively invoked script.
Try man 5 crontab for details.
Once you know what envrionment variables you need for your script to run, you can set them in the crontab as necessary, or source at the start of your own script.
EXAMPLE CRON FILE
# use /bin/sh to run commands, overriding the default set by cron
SHELL=/bin/sh
# mail any output to `paul', no matter whose crontab this is
MAILTO=paul
#
# run five minutes after midnight, every day
5 0 * * * $HOME/bin/daily.job >> $HOME/tmp/out 2>&1
# run at 2:15pm on the first of every month -- output mailed to paul
15 14 1 * * $HOME/bin/monthly
# run at 10 pm on weekdays, annoy Joe
0 22 * * 1-5 mail -s "It's 10pm" joe%Joe,%%Where are your kids?%
23 0-23/2 * * * echo "run 23 minutes after midn, 2am, 4am ..., everyday"
5 4 * * sun echo "run at 5 after 4 every sunday"

Resources