deleting pictures when suspending laptop on lid close / How?

Here you can exchange scripts that you created or have permission to share with other users.
Message
Author
User avatar
GDixon
Posts: 51
Joined: Fri Nov 02, 2007 4:39 pm

deleting pictures when suspending laptop on lid close / How?

#1 Post by GDixon »

I can place this simple script into my home shutdown folder and it functions at shutdown deleting all the *.png pictures.

#!/bin/bash
# used to remove both large and normal thumbnails in /home/user/.thumbnails
# make sure it is executable and place script in /home/user/.kde/shutdown to run at shutdown

rm /home/user/.thumbnails/large/*.png; rm /home/user/.thumbnails/normal/*.png
exit 1 <----- SHOULD BE EXIT 0
fi <----- MISTAKE IN COPY PASTE, REMOVE fi
done <----- NOT NEEDED BAD COPY PASTE AND THE LACK OF ATTENTION

I would like to do the deletion on suspend (to ram , i don't use hibernate ) also but have not had any luck in finding the proper place to either add the script or insert the commands to do the deletion.

Does anyone have any ideas on where to do this?
I've tried placing it in /etc/pm/config.d but it doesn't run and suspend fails.
Is there another place to try?
Last edited by GDixon on Sat Jul 12, 2014 6:26 pm, edited 2 times in total.

User avatar
joany
Posts: 235
Joined: Mon Feb 12, 2007 1:45 pm

Re: deleting pictures when suspending laptop on lid close /

#2 Post by joany »

Just make a symbolic link that points the ~/.thumbnails folder to /dev/nullfile. Then you won't have to run any scripts on shutdown or hibernate because the system won't be able to write any thumbnails for you to delete. :wink:
MX-14; 3.12-0.bpo.1-686-pae kernel using 4GB RAM
2.4GHz AMD Athlon 4600+
NVidia GeForce 6150 LE; 304.121 Display Driver
You didn't slow down because you're old; you're old because you slowed down.

User avatar
BitJam
Developer
Posts: 2283
Joined: Sat Aug 22, 2009 11:36 pm

Re: deleting pictures when suspending laptop on lid close /

#3 Post by BitJam »

GDixon wrote:I've tried placing it in /etc/pm/config.d but it doesn't run and suspend fails.
Is there another place to try?
Suspend failing when you add your script indicates that is the right place but there is something wrong with your script. In fact, there are two obvious problems with the script you posted. I copied it to "bad-script" and then ran "bash -n bad-script":

Code: Select all

bash -n bad-script 
bad-script: line 7: syntax error near unexpected token `fi'
bad-script: line 7: `fi'
BTW: take a look at this example of a /etc/mp/sleep.d/ script.

User avatar
GDixon
Posts: 51
Joined: Fri Nov 02, 2007 4:39 pm

Re: deleting pictures when suspending laptop on lid close /

#4 Post by GDixon »

Good way to do it Joany but there are times i need to go through the thumbnails, very rare but it has happened.

fixed the thumbnails.sh by removing the fi (oops, should be more careful on copy and paste from my file of script goodies i use.

thumbnails.sh runs great from terminal or shutdown in .kde

Wrote a quick thumbs.sh to place in different places but the same thing happens , suspend starts, locks the screen and resumes right away.

#!/bin/bash
case "$1" in
suspend)
/user/local/bin/thumbnails.sh <------MISTAKE USER SHOULD BE USR
;;
*)
;;
esac
exit $?

above has been placed in /etc/pm/config.d and also tried sleep.d

still fails in the same way but i did catch it in the log when i tried it in /usr/lib/pm-utils/sleep.d


Heres the important part of the log

Running hook /usr/lib/pm-utils/sleep.d/thumbs.sh suspend suspend:

/usr/lib/pm-utils/sleep.d/thumbs.sh: line 4: /user/local/bin/thumbnails.sh: No such file or directory

/usr/lib/pm-utils/sleep.d/thumbs.sh suspend suspend: Returned exit code 127.

Sat Jul 12 15:43:30 EDT 2014: Inhibit found, will not perform suspend

Sat Jul 12 15:43:30 EDT 2014: Running hooks for resume
____________________________

it seems it is telling me it can not locate the thumbnails.sh script so it can run it? Maybe I don't have the line 4 command correct yet?
Any ideas why it can't find it when it is pointed right at it? thumbnails is readable and executable by everyone and only root can write.
Last edited by GDixon on Sat Jul 12, 2014 6:23 pm, edited 2 times in total.

User avatar
GDixon
Posts: 51
Joined: Fri Nov 02, 2007 4:39 pm

Re: deleting pictures when suspending laptop on lid close /

#5 Post by GDixon »

Hmmmm could my hard drive be getting shutdown before the scripts can be run?

User avatar
BitJam
Developer
Posts: 2283
Joined: Sat Aug 22, 2009 11:36 pm

Re: deleting pictures when suspending laptop on lid close /

#6 Post by BitJam »

/user/local/bin/thumbnails.sh --> /usr/local/bin/thumbnails.sh

I suggest you debug the script by running it from the command line.

There was also a "done" in the original script that needs to be removed.

User avatar
GDixon
Posts: 51
Joined: Fri Nov 02, 2007 4:39 pm

Re: deleting pictures when suspending laptop on lid close /

#7 Post by GDixon »

a fresh set of eyes helps. the usr was correct it was a mistake and the exit 1 on the thumbnails.sh script
needs to be exit 0

I made it exit 0 and placed the thumbs.sh in /usr/lib/pm-utils/sleep.d and reran everything after testing it in a terminal.

Thanks for the fresh set of eyes it helped and now works as expected.
Last edited by GDixon on Sat Jul 12, 2014 6:29 pm, edited 1 time in total.

User avatar
GDixon
Posts: 51
Joined: Fri Nov 02, 2007 4:39 pm

Re: deleting pictures when suspending laptop on lid close /

#8 Post by GDixon »

#!/bin/bash
case "$1" in
suspend)
/usr/local/bin/thumbnails.sh
;;
*)
;;
esac
exit $?

place above in /usr/lib/pm-utils/sleep.d and no need to number it like the other scripts in there.

--------------------------------------------------------------------------------------

it calls thumbnails.sh below and make both read, execute for all and write for root only

#!/bin/bash
rm /home/username/.thumbnails/large/*.png; rm /home/username/.thumbnails/normal/*.png
exit 0

User avatar
GDixon
Posts: 51
Joined: Fri Nov 02, 2007 4:39 pm

Re: deleting pictures when suspending laptop on lid close /

#9 Post by GDixon »

What is and where can you get "bad-script" ?

I use -x for testing and it is lacking.

User avatar
GDixon
Posts: 51
Joined: Fri Nov 02, 2007 4:39 pm

Re: deleting pictures when suspending laptop on lid close /

#10 Post by GDixon »

Will a moderator please put this in the scripts forum/area.

Thank you

Post Reply

Return to “Scripts”