Script to isolate unused images in website

Hi

I am sorry if I am in the wrong place!
I have been looking for a way to isolate and FTP out of the server hundreds of images which are no longer doing anything there, that is, that are not linked to any page.

The only thing I found (free) was the following script. If I am useless at html/css , then this script is Chinese to me!

Could you tell me if it would work, what I have to change, and where to place it, please?

#!/bin/bash http://pintotours.net=$1 find "http://pintotours.net" -name *.jpg -exec basename {} \; > /tmp/patterns find "http://pintotours.net" -name *.png -exec basename {} \; >> /tmp/patterns find "http://pintotours.net" -name *.gif -exec basename {} \; >> /tmp/patterns for p in $(cat /tmp/patterns); do grep -R $p"$http://pintotours.net" > /dev/null || echo$p; $ chmod +x remover.sh and run: $ ./remover.sh /path/to/clear done

Thank you

Hi, welcome to the forums.

Please use CODE tags, not ICODE.
Please convert the output(file) from Windows to linux format, the current output is invalid, as its missing linebreaks.
You could use Notepad++ or any other TEXT editor (= NOT ms Word!) that lets you save/convert files to linux with utf8 w/o bom , then copy-paste again.

Thank you

Hi

Many thanks

Maybe I should have mentioned that my machine is Windows based...and the server Apache

As for conversion, I used Notepad++ but could only see "save as Unix"
which I am now attaching.

Sorry for my total ignorance...

LATER

is this any better:

 
#!/bin/bash
http://pintotours.net=$1
find "http://pintotours.net" -name *.jpg -exec basename {} \; > /tmp/patterns
find "http://pintotours.net" -name *.png -exec basename {} \; >> /tmp/patterns
find "http://pintotours.net" -name *.gif -exec basename {} \; >> /tmp/patterns
for p in $(cat /tmp/patterns); do
    grep -R $p "$http://pintotours.net" > /dev/null || echo $p;
$ chmod +x remover.sh
and run:
$ ./remover.sh /path/to/clear
done
#!/bin/bash
SRC_PATH="$1"
URL="$2"
[ $# -lt 2 ] && echo "Usage: ${0##*/} LOCALPATH \"BASEURL\"" && exit 1

cd "$SRC_PATH"
find "$URL" -name *.jpg -exec basename {} \; > /tmp/patterns
find "$URL" -name *.png -exec basename {} \; >> /tmp/patterns
find "$URL" -name *.gif -exec basename {} \; >> /tmp/patterns

for p in $(cat /tmp/patterns); do
    grep -R $p "$URL" > /dev/null || echo "$p";
done

I didnt check for functionality, but it should work.

Make it executable:

$ chmod +x remover.sh

And run:

$ ./remover.sh /path/to/clear "http://pintotours.net" > files_to_remove.txt 

If you have a bash environment in windows, i'd put the script in $HOME/bin or /bin.
Then you could just type: remover.sh in the shell and pass the values, otherwise, you'd need to change to the dir and type ./remover.sh , or just type the /full/path/to/remover.sh .

/path/to/clear, represents the full path to the local files, has to be quoted if it contains spaces
BASEURL, should be a quoted url, like "http://www.pintotours.com"

Hope this helps

Hi

The eimages are in the server not in my computer. The important thing to start with is to separate the images, i.e. the one not being used could be put in another folder.

After that I could FTP them to my computer. So, I suppose we can forget about my Windpws machine, unless you are telling me that the commands have to come from here.

I'm sorry but I really don't understand this code

Does the script need altering in any way' i just added bits and pieces without knowing what I was doing!

The new requirement in combination of a bashscript with a windows machine and an unkown ftp server is above my handling skill via the forum, sorry.

Other than that, the (new) script should not need altering (other than from other forum members).
The example:

$ ./remover.sh /path/to/clear "http://pintotours.net" > files_to_remove.txt

Should save a new file called files_to_remove.txt with a list of all unused images.

I highly recomend to first get such a list before (re-)moving anything.
Expecting that the list either contains only the filename, and that are images are in a single folder, you could then try something like:

put files_to_remove.txt
mkdir /bkp_imgs
cd www/pintotours/images
while read img ; do mv $img /bkp_imgs ; done</files_to_remove.txt

Hope this helps

Thanks

If I may add:

The files (images) are in a server run on Apache. All I need really is to separate the images there from where they are (doing nothing as they are no linked to any htl or php file) and placing them in anew file IN THE SERVER called, say, files_to_remove.txt, as you said.

Then, the question fo dealing with them, is not a problem to me and I do not need any scripts.

So will this script do the job in the server and how would I start? I take it that I would have to upload it and then soemhow get it to do the job

There is a 'thanks' button for that :slight_smile:
You're welcome.