Web Hosting Talk







View Full Version : Bash script error (No such file or directory/find)


ZKuJoe
07-05-2009, 11:25 AM
Here's the code I'm using (was working on my old server before migrating to the new one:

#!/bin/bash
FINDBIN=/usr/bin/find
EGREPBIN=/bin/egrep
BADWORDS="warez|proxy|hacks"
echo " PHP SCAN STARTED"
echo "++++++++++++++++++++++++++++++++++++++++++++++++++++"
$FINDBIN /home/public_html/ -iname \*.php -type f -exec $EGREPBIN -i -H $BADWORDS {} \;
echo "++++++++++++++++++++++++++++++++++++++++++++++++++++"
echo " PHP SCAN ENDED"


Here is the output:

PHP SCAN STARTED
++++++++++++++++++++++++++++++++++++++++++++++++++++
: No such file or directory/find
++++++++++++++++++++++++++++++++++++++++++++++++++++
PHP SCAN ENDED


I've reinstalled findutils with no luck, I verified the location of find and it is correct.


# whereis find
find: /usr/bin/find /usr/share/man/man1p/find.1p.gz /usr/share/man/man1/find.1.gz


Any ideas why this would work on the old server and not the new one since they are pretty much identical in terms of both hardware and software?

zacharooni
07-05-2009, 11:32 AM
Paste output of:

/bin/bash -x yourscript.sh

ZKuJoe
07-05-2009, 11:35 AM
# /bin/bash -x ifscanphp.sh
+ FINDBIN=$'/usr/bin/find\r'
+ EGREPBIN=$'/bin/egrep\r'
' BADWORDS='warez|proxy|hacks
' echo ' PHP SCAN STARTED
PHP SCAN STARTED
+ echo $'++++++++++++++++++++++++++++++++++++++++++++++++++++\r'
++++++++++++++++++++++++++++++++++++++++++++++++++++
' '{}' ';bin/find\r' /home/*/public_html/ -iname '*.php' -type f -exec $'/bin/egrep\r' -i -H 'warez|proxy|hacks
: No such file or directorybin/find
+ echo $'++++++++++++++++++++++++++++++++++++++++++++++++++++\r'
++++++++++++++++++++++++++++++++++++++++++++++++++++
' echo ' PHP SCAN ENDED
PHP SCAN ENDED

beastserv
07-05-2009, 11:39 AM
first of all make sure your system had findutils
http://www.gnu.org/software/findutils/

type:
# which find

if you see a correct path -

you can put insted of this FINDBIN=/usr/bin/find
this: FINDBIN=`which find`

ZKuJoe
07-05-2009, 11:43 AM
I did that, but now I'm getting the following:

line 7: /home/<user>/public_html/: is a directory

zacharooni
07-05-2009, 11:48 AM
Try doing this, I noticed some \r's

# dos2unix ifscanphp.sh

ZKuJoe
07-05-2009, 12:39 PM
Looks like it worked. Thanks!