Welcome to the GoFuckYourself.com - Adult Webmaster Forum forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Post New Thread Reply

Register GFY Rules Calendar
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >
Discuss what's fucking going on, and which programs are best and worst. One-time "program" announcements from "established" webmasters are allowed.

 
Thread Tools
Old 09-16-2006, 01:26 PM   #1
Wolfy
Confirmed User
 
Wolfy's Avatar
 
Industry Role:
Join Date: Dec 2003
Location: Wisconsin
Posts: 3,574
ssh question - how do I search my server for a bit of text?

I need to search all the files on my entire domain for a bit of text.


I'm still sending traffic to an old sponsor (that doesn't pay) and I can't figure out where it's coming from

I know there's an ssh command I can run - anybody know how to do it?
Wolfy is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 09-16-2006, 01:27 PM   #2
Fizzgig
Registered User
 
Fizzgig's Avatar
 
Join Date: Feb 2004
Location: In Your Dreams
Posts: 9,649
I don't know but we keep our sites mirrored on a HD for just such an emergency.
__________________
---'-,-{@ Sassy Grrrl @}-'-,---

Fizzgig is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 09-16-2006, 01:30 PM   #3
boldy
Macdaddy coder
 
Industry Role:
Join Date: Feb 2002
Location: MacDaddy pimp coder
Posts: 2,806
cd <to the target directory>
grep -Ri "yourpiece of text here" *

__________________
MacDaddy Coder.
boldy is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 09-16-2006, 01:32 PM   #4
Wolfy
Confirmed User
 
Wolfy's Avatar
 
Industry Role:
Join Date: Dec 2003
Location: Wisconsin
Posts: 3,574
is there any way to recursively search all directories, say public_html and below?

oh, and say I want to search for foobar - do I use the quotes or no?

grep -Ri "foobar" *
Wolfy is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 09-16-2006, 01:35 PM   #5
boldy
Macdaddy coder
 
Industry Role:
Join Date: Feb 2002
Location: MacDaddy pimp coder
Posts: 2,806
Quote:
Originally Posted by Wolfy
is there any way to recursively search all directories, say public_html and below?

oh, and say I want to search for foobar - do I use the quotes or no?

grep -Ri "foobar" *
you first : change the directory to public_html

say : cd /web/sites/yourdomain.com/public_html

then

grep -Ri foobar *

if its a single word you can drop the quotes



*edit* the capital R is recursive .. the lowercase i is case insensitive ..
__________________
MacDaddy Coder.
boldy is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 09-16-2006, 01:43 PM   #6
Wolfy
Confirmed User
 
Wolfy's Avatar
 
Industry Role:
Join Date: Dec 2003
Location: Wisconsin
Posts: 3,574
so that will search public_html, public_html/directory1, public_html/dirctory1/subdirectory, and all the files in each?

I might be stretching here, but is it possible to do a find and replace with ssh? :D

Thanks for the help
Wolfy is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 09-16-2006, 01:44 PM   #7
Wolfy
Confirmed User
 
Wolfy's Avatar
 
Industry Role:
Join Date: Dec 2003
Location: Wisconsin
Posts: 3,574
oh, and will it find all instances of the text? Like if foobar is surronded with html, or other text - will it find 123foobar123?
Wolfy is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 09-16-2006, 01:47 PM   #8
bl4h
Confirmed User
 
Join Date: Jul 2006
Location: Philadelphia
Posts: 1,282
btw its not an ssh command. its a shell command. thats like calling "http://www.gfy.com" an IE command

remember that ;/
bl4h is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 09-16-2006, 02:11 PM   #9
woj
<&(©¿©)&>
 
woj's Avatar
 
Industry Role:
Join Date: Jul 2002
Location: Chicago
Posts: 47,882
Quote:
Originally Posted by bl4h
btw its not an ssh command. its a shell command. thats like calling "http://www.gfy.com" an IE command

remember that ;/
come on man, ssh=secure shell, close enough...
__________________
Custom Software Development, email: woj#at#wojfun#.#com to discuss details or skype: wojl2000 or gchat: wojfun or telegram: wojl2000
Affiliate program tools: Hosted Galleries Manager Banner Manager Video Manager
Wordpress Affiliate Plugin Pic/Movie of the Day Fansign Generator Zip Manager
woj is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 09-16-2006, 02:15 PM   #10
boldy
Macdaddy coder
 
Industry Role:
Join Date: Feb 2002
Location: MacDaddy pimp coder
Posts: 2,806
Quote:
Originally Posted by Wolfy
oh, and will it find all instances of the text? Like if foobar is surronded with html, or other text - will it find 123foobar123?
yes it will , search and replace is kind of tricky tho to do with a shell command ..
__________________
MacDaddy Coder.
boldy is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 09-16-2006, 02:17 PM   #11
Wolfy
Confirmed User
 
Wolfy's Avatar
 
Industry Role:
Join Date: Dec 2003
Location: Wisconsin
Posts: 3,574
Quote:
Originally Posted by bl4h
btw its not an ssh command. its a shell command. thats like calling "http://www.gfy.com" an IE command

remember that ;/
well then.. learn something new every day :D
Wolfy is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 09-16-2006, 02:21 PM   #12
Wolfy
Confirmed User
 
Wolfy's Avatar
 
Industry Role:
Join Date: Dec 2003
Location: Wisconsin
Posts: 3,574
ouch - that gave me a ton of results, all mixed up with html!

Can I narrow it down? Say, print a list of files that contain foobar and their locations?
Wolfy is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 09-16-2006, 02:34 PM   #13
boldy
Macdaddy coder
 
Industry Role:
Join Date: Feb 2002
Location: MacDaddy pimp coder
Posts: 2,806
I'm in a good mood today so i wrote this little perl script for you :
uploaded it and call it test.pl

then run it from the command shell:
(make sure you're into the public_html dir)


perl test.pl


Code:
#!/usr/bin/perl
# by boldy / EarlmillerCash.com
# Now promote Earlmillercash.com goddamnnit :) 

my $lSearch = "foobar";
my $lReplace = "whatever";

# this will search and replace the above words, and it will create
# filename.html.test files if it matches the action.
# if you think it workds set $lTest to "" instead of ".test"
#
# and it will overwrite the file.
# make sure you're in the right directory by cd ing itto it
# eg .
# cd /web/sites/yourdomain.com/public_html

# set $lTest to "" when you think this works
# to delete the *.test files run: find ./ -name *\.test -exec rm {} \;

my $lTest = ".test";
my @lFiles = split ("\n" , `find ./ -type f` );

foreach my $lFile (@lFiles) {
   print "Opening file " . $lFile . "\n";
   open (INFILE,"<" . $lFile);
   my @lLines =<INFILE>;
   close INFILE;

   my $lWrite = 0;
   foreach my $lLine (@lLines) {
      if ($lLine =~ m/$lSearch/) {
            $lWrite = 1; last;
      }
   }
   if ($lWrite) {
      open (OUTFILE , ">" . $lFile . $lTest );
      foreach my $lLine (@lLines) {
         $lLine =~ s/$lSearch/$lReplace/g;
         print OUTFILE $lLine;
      }
      close OUTFILE;
      print $lFile.$lTest  . " created \n";
   }
}
__________________
MacDaddy Coder.
boldy is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 09-16-2006, 02:44 PM   #14
Wolfy
Confirmed User
 
Wolfy's Avatar
 
Industry Role:
Join Date: Dec 2003
Location: Wisconsin
Posts: 3,574
will that work if I use any text for the replacement?

Here's the thing - I was promoting one sponsor for a long time, and they ended up burning me. To avoid this trouble in the future, I'm now using this instead of an actual hardlink:

<?php include('full/path/to/sponsor.php'); ?>

where sponsor.php is simply a file with one line in it - my current affiliiate link.

So I am effectively replacing this:

<a href="http:juicybucks.com/owesme3k/andwontpay.php">link text</a>

with this:

<a href="<?php include('full/path/to/sponsor.php'); ?>">link text</a>

I'm assuming it will work fine, but just to be sure and to get an extra dig into the deadbeat fucks that inspired this thread
Wolfy is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 09-16-2006, 02:53 PM   #15
boldy
Macdaddy coder
 
Industry Role:
Join Date: Feb 2002
Location: MacDaddy pimp coder
Posts: 2,806
Code:
my $lSearch = quotemeta ("<a href=\"http//:juicybucks.com/owesme3k/andwontpay.php\">link text</a>");
my $lReplace = "<a href=\"<?php include('full/path/to/sponsor.php'); ?>\">link text</a>";
Thank should work

replace the bogus info ofcoz ..

make sure you escape (\) the quotes within your texts like a href=\"http://
__________________
MacDaddy Coder.
boldy is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 09-16-2006, 02:55 PM   #16
borked
Totally Borked
 
borked's Avatar
 
Industry Role:
Join Date: Feb 2005
Posts: 6,284
find / -name 'whatyouwanttosearchfor' -print

replace / with whatever directory you want to search.

---edit
oops sorry, this will only find filenames - didn't read that you wanted to search files for text.

ehm, transfer your server files to a mac and use spotlight?
__________________

For coding work - hit me up on andy // borkedcoder // com
(consider figuring out the email as test #1)



All models are wrong, but some are useful. George E.P. Box. p202

Last edited by borked; 09-16-2006 at 02:57 PM..
borked is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 09-16-2006, 03:00 PM   #17
borked
Totally Borked
 
borked's Avatar
 
Industry Role:
Join Date: Feb 2005
Posts: 6,284
Quote:
Originally Posted by boldy
I'm in a good mood today so i wrote this little perl script for you :
uploaded it and call it test.pl

then run it from the command shell:
(make sure you're into the public_html dir)


perl test.pl


Code:
#!/usr/bin/perl
# by boldy / EarlmillerCash.com
# Now promote Earlmillercash.com goddamnnit :) 

my $lSearch = "foobar";
my $lReplace = "whatever";

# this will search and replace the above words, and it will create
# filename.html.test files if it matches the action.
# if you think it workds set $lTest to "" instead of ".test"
#
# and it will overwrite the file.
# make sure you're in the right directory by cd ing itto it
# eg .
# cd /web/sites/yourdomain.com/public_html

# set $lTest to "" when you think this works
# to delete the *.test files run: find ./ -name *\.test -exec rm {} \;

my $lTest = ".test";
my @lFiles = split ("\n" , `find ./ -type f` );

foreach my $lFile (@lFiles) {
   print "Opening file " . $lFile . "\n";
   open (INFILE,"<" . $lFile);
   my @lLines =<INFILE>;
   close INFILE;

   my $lWrite = 0;
   foreach my $lLine (@lLines) {
      if ($lLine =~ m/$lSearch/) {
            $lWrite = 1; last;
      }
   }
   if ($lWrite) {
      open (OUTFILE , ">" . $lFile . $lTest );
      foreach my $lLine (@lLines) {
         $lLine =~ s/$lSearch/$lReplace/g;
         print OUTFILE $lLine;
      }
      close OUTFILE;
      print $lFile.$lTest  . " created \n";
   }
}
__________________

For coding work - hit me up on andy // borkedcoder // com
(consider figuring out the email as test #1)



All models are wrong, but some are useful. George E.P. Box. p202
borked is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 09-16-2006, 03:11 PM   #18
Wolfy
Confirmed User
 
Wolfy's Avatar
 
Industry Role:
Join Date: Dec 2003
Location: Wisconsin
Posts: 3,574
Quote:
Originally Posted by boldy

make sure you escape (\) the quotes within your texts like a href=\"http://

That's the bit I was looking for. Thanks man - and I'll look forward to collecting a few checks from you if you have something I can use. The join page to your program looks nice, I'll put some effort into it.


Cheers man!
Wolfy is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 09-16-2006, 05:19 PM   #19
Wolfy
Confirmed User
 
Wolfy's Avatar
 
Industry Role:
Join Date: Dec 2003
Location: Wisconsin
Posts: 3,574
Quote:
Originally Posted by boldy
I'm in a good mood today so i wrote this little perl script for you :
uploaded it and call it test.pl

then run it from the command shell:
(make sure you're into the public_html dir)


perl test.pl

Hey boldy, I gave it a shot, and it didn't seem to work. It listed every file on my server, but nothing was changed. I followed up a second time with a test - I created your test.pl, with the replacement text as follows:

Code:
my $lReplace = "testtesttest";
Then I ran the command: grep -Ri testtesttest * and the only file I found was the test.pl file.

Any ideas?
Wolfy is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 09-16-2006, 05:27 PM   #20
the alchemist
Confirmed User
 
the alchemist's Avatar
 
Industry Role:
Join Date: Dec 2004
Location: Montreal, Canada
Posts: 3,271
Track it?
__________________
264 349 400
the alchemist is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 09-16-2006, 05:37 PM   #21
fatdicksimon
Confirmed User
 
Join Date: Feb 2006
Posts: 226
you can use sed to do a search and replace as well if that perl script isn't working. syntax is as follows:

sed 's|oldtext|newtext|g' -i filename

that will search filename for oldtext and replace it with newtext. make sure to escape any single quotes within the containing single quotes as well.

for multiple files, as far as i know, you must specify a file extension, but you can use the * symbol to search and replace a bunch.

so you will probably want to navigate to the containing directory, then do as follows:

sed 's|oldtext|newtext|g' -i *.php

of course you can do

sed 's|oldtext|newtext|g' -i /otherdirectory/*.php

if you want to find and replace a file in another directory.

when you first mess around with it, you may only want to check one file and make a backup of it to check the results.

sed runs quickly and is very useful. do a 'man sed' command for more info.

hope that helps!
__________________
icq: 199791893
holler at me
fatdicksimon is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 09-16-2006, 06:23 PM   #22
Wolfy
Confirmed User
 
Wolfy's Avatar
 
Industry Role:
Join Date: Dec 2003
Location: Wisconsin
Posts: 3,574
is there a command similar to "grep -iR text *" that will find the files and then create a text file so I know which files they are, and their location? Or perhaps a command that will find the files containing that text but then only list the filenames, rather than the file + the code/text I searched for?
Wolfy is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Post New Thread Reply
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >

Bookmarks



Advertising inquiries - marketing at gfy dot com

Contact Admin - Advertise - GFY Rules - Top

©2000-, AI Media Network Inc



Powered by vBulletin
Copyright © 2000- Jelsoft Enterprises Limited.