![]() |
![]() |
![]() |
||||
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. |
![]() ![]() |
|
Discuss what's fucking going on, and which programs are best and worst. One-time "program" announcements from "established" webmasters are allowed. |
|
Thread Tools |
![]() |
#1 |
Confirmed User
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? |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#2 |
Registered User
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.
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#3 |
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. |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#4 |
Confirmed User
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" * |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#5 | |
Macdaddy coder
Industry Role:
Join Date: Feb 2002
Location: MacDaddy pimp coder
Posts: 2,806
|
Quote:
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. |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#6 |
Confirmed User
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 ![]() |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#7 |
Confirmed User
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?
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#8 |
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 ;/ |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#9 | |
<&(©¿©)&>
Industry Role:
Join Date: Jul 2002
Location: Chicago
Posts: 47,882
|
Quote:
__________________
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 |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#10 | |
Macdaddy coder
Industry Role:
Join Date: Feb 2002
Location: MacDaddy pimp coder
Posts: 2,806
|
Quote:
__________________
MacDaddy Coder. |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#11 | |
Confirmed User
Industry Role:
Join Date: Dec 2003
Location: Wisconsin
Posts: 3,574
|
Quote:
|
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#12 |
Confirmed User
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? |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#13 |
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. |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#14 |
Confirmed User
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 ![]() |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#15 |
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>"; replace the bogus info ofcoz .. make sure you escape (\) the quotes within your texts like a href=\"http://
__________________
MacDaddy Coder. |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#16 |
Totally Borked
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 |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#17 | |
Totally Borked
Industry Role:
Join Date: Feb 2005
Posts: 6,284
|
Quote:
![]() ![]()
__________________
![]() 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 |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#18 | |
Confirmed User
Industry Role:
Join Date: Dec 2003
Location: Wisconsin
Posts: 3,574
|
Quote:
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! |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#19 | |
Confirmed User
Industry Role:
Join Date: Dec 2003
Location: Wisconsin
Posts: 3,574
|
Quote:
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"; Any ideas? |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#20 |
Confirmed User
Industry Role:
Join Date: Dec 2004
Location: Montreal, Canada
Posts: 3,271
|
Track it?
__________________
264 349 400 |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#21 |
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 |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#22 |
Confirmed User
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?
|
![]() |
![]() ![]() ![]() ![]() ![]() |