Script to isolate unused images in website


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script to isolate unused images in website
# 1  
Old 05-08-2015
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?

Code:
#!/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

Last edited by rbatte1; 05-08-2015 at 11:55 AM..
# 2  
Old 05-08-2015
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
# 3  
Old 05-08-2015
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:

Code:
 
#!/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


Last edited by qim; 05-08-2015 at 10:45 AM..
# 4  
Old 05-08-2015
Code:
#!/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:
Code:
$ chmod +x remover.sh

And run:
Code:
$ ./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
# 5  
Old 05-08-2015
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!
# 6  
Old 05-08-2015
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:
Code:
$ ./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:
Code:
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
# 7  
Old 05-08-2015
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

Last edited by qim; 05-08-2015 at 11:36 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Script monitor website wth default tomcat script

Hi all, on our application server we have the following script that monitor the status of the website, my problem here is that i have edite the retries from 3 to 5, and the timewait to 120 second, so the script should check 5 times every 2 minutes, and if the fifth check fails it must restart... (0 Replies)
Discussion started by: charli1
0 Replies

2. Shell Programming and Scripting

Creating a script to download images from multiple cameras using ghoto2

I should start by saying that I am totally new to linux... I am trying to create a script that downloads images from multiple cameras into a specific folder on my machine. Ideally renaming the images as they are downloaded. I have installed gphoto2 which as a command line interface that... (0 Replies)
Discussion started by: benpems
0 Replies

3. Shell Programming and Scripting

Bash Script to find/sort/move images/duplicate images from USB drive

Ultimately, I'm looking to create a script that allows me to plug in a usb drive with lots of jpegs on it & copy them over to a folder on my hard drive. So in the process of copying I am looking to hash check them, record dupes to a file, copy only 1 of the identical files (if it doesn't exsist... (1 Reply)
Discussion started by: JonaQuinn
1 Replies

4. Shell Programming and Scripting

Need to add Birthday images inside shell script

Hi All- I have written a shell script to send birthday wish mail to all my colleagues. I need help from you all in two things, 1. I need to add some 17 birthday images as my team size is 17 i want to send different images for everyone. (I dont know how to do it) 2. I need to send mail... (4 Replies)
Discussion started by: ChandruBala73
4 Replies

5. Shell Programming and Scripting

Script to alert about a slow link on the website

Hello all, Currently I am using a script with "curl" to get the an alert if 200 ok would not be grepped.and the link is down. is it possible to get an alert mail if a particular link on a website is not completely down but SLOW?? (0 Replies)
Discussion started by: chirag991
0 Replies

6. Shell Programming and Scripting

Script to run php script on multiple website domains

Good Day, I have multiple websites on a domain. I am looking for a loop structure that can run each site script. egdomain1/test.php domainx/test.php so on, currently I copy and paste a list of commands but that skips certain commands. Some help would be greatly appreciated. Sergio (3 Replies)
Discussion started by: SergioP
3 Replies

7. Shell Programming and Scripting

Shell Script for Logging into the Website

Hi ALL, Is there any way, to login into a website using Shell/Perl command/script? I am struggling on this from quite sometime but with no luck. Can you guys help, please? My sole purpose is to login a website (Which requires Username and Password) and then extract some information from... (3 Replies)
Discussion started by: parshant_bvcoe
3 Replies

8. Shell Programming and Scripting

How do I check using shell-script if a website is available / responding?

Hi, Could someone please help. How do I verify using a shell script whether a website URL is available? It's roughly the URL equivalent of ping <servername> or tnsping <Oracle database name>? I hope this is enough information - please let me know if it's not. Many thanks, Neil (3 Replies)
Discussion started by: Neil_mw
3 Replies

9. Solaris

need script for locked and unused user accounts in /export/home directory

Hi all, i have to need one script: 1. it will capture the unused user accounts in /export/home directory. 2. it will capture the locked user accounts in /export/home directory. Note: locked accounts will show in /etc/passwd like /bin/false --> (instead of ksh it will show false) the... (1 Reply)
Discussion started by: krishna176
1 Replies

10. Shell Programming and Scripting

Please help me to write a Script to find out whether website is up!!!!!!!

Hello friends I have to write a script in linux to find out the website is up or down..... Please help me in this thank you Jay (1 Reply)
Discussion started by: jai143
1 Replies
Login or Register to Ask a Question