I have this error in logs file
CRON[3304]: (root) CMD ( /usr/bin/php /home/app/foxorders/scripts/restart_apache.php >/dev/null 2>/dev/null)
Whats mean please ?
This is not a error. It's just information about cron job which execute command:
/usr/bin/php /home/app/foxorders/scripts/restart_apache.php
and redirect STDOUT and STDERR to NULL device
Related
Linux script has the command exec > &LOGFILE 2>&1 to redirect output to a file, I am trying to amend the command to redirect output to a file and also to the console at the same time.
None of the below command works. It either redirects output to file or writes to the console but not both at the same time. Can somebody help?
exec > >(tee -a $LOGFILE) 2>&1
exec &> >(tee -a $LOGFILE) 2>&1
exec >> $LOGFILE 2>&1 && tail -f $LOGFILE
I'm facing this problem :
When I execute a CRON task from my Web Server with this command :
wget https://mon-url.com/file/cron.php >/dev/null 2>&1
It creates new files cron.php1, cron.php2, ... in my /root directory and It takes a lot of space. How can I prevent this ?
Thanks
You can use -O /dev/null what will write the output file to /dev/null
wget -O /dev/null https://mon-url.com/file/cron.php >/dev/null 2>&1
Or -O- which will output it to stdout.
wget -O- https://mon-url.com/file/cron.php >/dev/null 2>&1
This is the answer:
wget --delete-after
Why doesn't the output get redirected in this case. The user doesn't have permission to write in /proc hence the error but why the error isn't going to /dev/null?
$echo "core_%e.%p" > /proc/sys/kernel/core_pattern 2>&1 > /dev/null
-bash: /proc/sys/kernel/core_pattern: Permission denied
Try with:
echo "core_%e.%p" 2>/dev/null > /proc/sys/kernel/core_pattern 2>&1
that will send stdout and stderr to "core_pattern", if possible, if not, ends without message.
works too:
bash -c 'echo "core_%e.%p" > /proc/sys/kernel/core_pattern' > /dev/null 2>&1
I have wrote a small script to check if openvpn is running and start it if it's not.
Here is the script i'm running
#!/bin/bash **-x**
ps auxw | grep openvpn | grep -v grep > /dev/null
if [ $? != 0 ]
then
/etc/init.d/openvpn start > /dev/null
log="/root/ServerRestart.log"
echo "The Openvpn Server was restarted at\n" > $log
date >> $log
fi
here is the crontab:
* * * * * /root/vpnmonitor.sh
it shows in the syslog that it runs the script but it does not seem to actually execute, the script works fine when run from a terminal.
The openvpn service won't start whitout the rigth path.
Try to include on your "vpnmonitor.sh":
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
Like:
#!/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
logger "VPN restarted from cron"
/etc/init.d/openvpn restart vpn-servername
I made a new cronjob in /etc/crontab rather than using crontab -e and it works now, thanks everyone.
I'm trying to pipe stderr to logger with this code:
/usr/local/bin/Script.py >/dev/null 2>(/usr/bin/logger -t MyScript -p syslog.err)
This runs fine when run from a bash commandline but has no output in syslog when run from cron. This is my (root) crontab:
0-59/5 * * * * /usr/local/bin/Script.py >/dev/null 2>(/usr/bin/logger -t MyScript -p syslog.err)
Can anybody help and tell me What is going wrong here?
Thanks!
>/dev/null is redirecting both stdout/stderr to /dev/null before the 2> redirection can pick it up.
Instead, redirect stdout to /dev/null explicitly:
/usr/local/bin/Script.py 1>/dev/null 2>(/usr/bin/logger -t MyScript -p syslog.err)