kcraighead Posted July 18, 2009 Posted July 18, 2009 I have written a simple shell script which I plan to use to see if any directories have been created on my hosting account without my knowledge. I have been caught over the last few days by people putting fishing sites up and I want to know within an hour or 2 if this has happened so I can remove it before the hosting account is suspended and I have to contact support to sort it all out. An early warning system if you like. I have created 2 files send.sh: find /home/????/public_html -type f -mmin -240 > /home/????/public_html/change.txt cat /home/????/public_html/mail.txt /home/????/public_html/change.txt | /usr/sbin/sendmail -t mail.txt: Date: Wed Oct 29 10:41:54 2008 To: MY-EMAIL Subject: Hacking Alert From: EMAIL I have then created a cron job to run send.sh every 2 hours. The email is sent but the problem is that I get an error email which says: cat: /home/????/public_html/change.txt: No such file or directory When I use Filezilla to look at the directory the file change.txt is listed with a size. However when I try to copy, delete or move the file to my local PC I get an error which says "no such file or directory". Any ideas why this would be and how I can fix it? Thanks for the help guys I am totally confused! Quote
TCH-Dick Posted July 18, 2009 Posted July 18, 2009 It appears you created the script in Windows and copied it over to the server. Since Windows and Linux have different formats for carriage returns, the format will not work correctly until it is converted to the UNIX format. I have now converted your script and removed the carriage return from the file name. Your script should now work as intended and I have included a log of the changes I made. >[public_html]# cat -vt send.sh find /home/***/public_html -type f -mtime -1 > /home/***/public_html/change.txt^M cat /home/***/public_html/mail.txt /home/***/public_html/change.txt | /usr/sbin/sendmail -t [public_html]# dos2unix send.sh dos2unix: converting file send.sh to UNIX format ... [public_html]# cat -vt send.sh find /home/***/public_html -type f -mtime -1 > /home/***/public_html/change.txt cat /home/***/public_html/mail.txt /home/***/public_html/change.txt | /usr/sbin/sendmail -t [public_html]# mv change.txt^M change.txt Quote
kcraighead Posted July 18, 2009 Author Posted July 18, 2009 You are right it was created Windows. It now works perfectly! Thanks! Quote
kcraighead Posted July 28, 2009 Author Posted July 28, 2009 (edited) I have another weird problem with this script. I get an error which only occurs once a day at 7am UK time. It says: DBI connect('mailmon:localhost:3306','mailmon',...) failed: User mailmon already has more than 'max_user_connections' active connections at /usr/sbin/sendmail line 79 Unable to connect to MySQL database! I wouldn't expect that many connections at 7am so I am confused about this. I also get the following error on other hosting accounts that I run the script on: /bin/sh: /home/***/public_html/send2.sh: Permission denied find: /home/***/public_html/phpnuke/modules/WebMail: Permission denied Any ideas what could be causing these problems. I have setup all of the scripts in the same way on each hosting account so I am not sure why I get these particular errors! Edited July 28, 2009 by TCH-Thomas Please see follow up post. Quote
TCH-Thomas Posted July 28, 2009 Posted July 28, 2009 I have edited out your cpanel user name from your post. Please do not post user sensitive information in public. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.