suppress some warnings in cron job - cron

I am running a backup script as a cron job. I am getting the error: Warning: Using a password on the command line interface can be insecure.
I am aware of how my scripts are set up and I am not in a shared environment, so this is not a warning I want to continually get. I tried the following command (found elsewhere on stack overflow), but it does not work.
45 5 * * * /home/username/scripts/automysqlbackup-2.5.1-01.sh 2>&1 | grep -v 'Warning: Using a password on the command line interface can be insecure.'
The problem is that I am still getting the warning and it seems that all warnings are changed to this text. Can someone give me the proper syntax? I searched Google for a long time and this doesn't seem to be a common question.
Thank you!

Related

Show the results of jobs scheduled with cron in the terminal

I've sucessfully configured a script that scans my system using cron in a scheduled hour of a day. However, I would like to see the results that it might have generated with its execution. Ex: rkhunter -c leaves logs in /var/log/rkhunter.log that I manually would have to check after it performed the task.
How can I configure cron to show a terminal with its results for example?
I've seen a similar case to mine, but it didn't work:
minute hour * * * DISPLAY=:0 xterm -e /dir_to_my_script/script.sh
But it gave the following error that I've not been able to solve so far:
Warning: This program is an suid-root program or is being run by the root user.
The full text of the error or warning message cannot be safely formatted
in this environment. You may get a more descriptive message by running the
program as a non-root user or by removing the suid bit on the executable.
xterm: Xt error: Can't open display: %s
Is there a way to accomplish it using cron as root? Thanks

How to print the output of running program started by crontab job to a file on daily basis

A script start.sh is registered in crontab to run on daily basis
But I'd like to save the output of the program to a file, like cronlog-yyyyMMdd.log
I tried the following but failed:
16 10 * * 1-5 ~/start.sh >> ~/cronlog/$(date+"\%F")-cron.log 2>&1
Anyone help me?
Using fully-qualified paths to all programs and files that are mentioned eliminate a whole class of errors from debugging issues with crontab entries. In this particular case, doing so would have only proved there were no problems with PATH issues in your crontab entry.
Your issue is that you need a space char between the date cmd and it's formatting argument string, instead of
$(date+"\%F")
#0 ^v
$(date +"\%F")
I commend you for your good crontab debug etiquette; capturing std-err and std-out to a file gives you 1. proof that your command ran when you expected it to (or if you have an error in your time specification, it will show you when the cmd did run). 2. you avoid having your localhost email box filling up with msgs from the cron daemon. 3 Any std-err msgs that were generated are also captured and are in generally in sync and time order with std-out messages.
IHTH.
16 10 * * 1-5 ~/start.sh >> ~/cronlog/$(date +"\%F")-cron.log
Edit: as explained in comments, this answers the question by correcting a typo in the asker's attempted entry

Cron Logging Issue

I cannot find documentation on how to set up Cron commands for some reason. Here's my current Cron command using GoDaddy's cron job manager tool. It runs twice an hour.
/web/cgi-bin/php5 "$HOME/~path-to-file~/my-function.php" > "$HOME/~path-to-file~/my-function.log"
What I'd like to do is get a thorough log of each time the Cron runs - output, timestamp, etc. I'm trying to debug this script and I'm stuck without some kind of error logging.
Thanks all!
You are directing Standard Output to the specified file by >, but Standard Error gets sent into oblivion. Add 2>&1 to the end of the command to append any errors to the same file.
/web/cgi-bin/php5 /path/to/php > /path/to/logfile.log 2>&1

Cron job mysteriously stopped running?

I have a cron job on an Ubuntu 10.4 server that stopped running for no apparent reason. (The job ran for months and has not been changed.) I am not a *nix guru so I plead ignorance if this is a simple problem. I can't find any reason or indication why this job would have stopped. I've restarted the server without success. Here's the job:
# m h dom mon dow command
0 * * * * java -jar /home/mydir/myjar.jar >>/home/mydir/crontaboutput.txt
The last line in the output file shows that the program ran on 8/29/2012. Nothing after that.
Any ideas where to look?
There should be something in your system log when the job was run. The other thing you could >try is to add 2>&1 to the job to see any errors in your text file. – Lars Kotthoff yesterday
This proved to be the key piece of information - adding 2>&1 allowed me to capture an error that wasn't getting reported anywhere else. The completed command line then looked like:
java -jar /home/mydir/myjar.jar 2>&1 >>/home/mydir/crontaboutput.txt
Perhaps your cron daemon has stopped, or changed configuration (i.e. /etc/cron.deny). I suggest to make a shell script, and running it from crontab. I also suggest to run thru your crontab some other program (just for testing) at some other time. You can use the logger command in your shell script for syslog. Look into system log files.
Accepted answer is correct, (i.e, check the error logs) which pointed out the error in my case. Besides check for the following issues
include('../my_dir/my_file.php) may work from url but it will not work when cron job is run, will spit out error.
$_SERVER variables does not work inside cron os if you are using $_SERVER['DOCUMENT_ROOT'], it will not be recognized and you will have an error in the cron job.
Make sure to test the cron and have it run, send an email etc to make sure it is run.

Why does crontab throw error: "illegal action"

I entered some cron jobs, everything saved correctly (jobs added)
I then went back and typed crontab -e to adjust something and I got a message: "illegal action" I also get this when typing crontab --help or crontab
Wow...now when I open my terminal, I get:
Could not open a new pseudo-tty.
crontab -e tries to use the editor specified in your environment variable named VISUAL (or missing that in the one named EDITOR). What do you have in those variables? It's impossible for us to guess, but maybe it's some weird value causing the "illegal action" message and/or something that consumes all pseudo-ttys, causing the rest of the problems you report.
crontab --help, to me, says "illegal option" (not "illegal action"!), but that's on my Darwin machine -- you don't deign to mention what version of Unix-oid system you're using and, again, it's impossible to guess from your scant input!-)
Thanks for your input :). I restarted my computer and everything is working again. Go fig...

Resources