LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-21-2011, 12:26 PM   #1
lonesoac0
Member
 
Registered: Jan 2010
Distribution: Ubuntu
Posts: 95

Rep: Reputation: 4
Directory size changes


hello all,

I currently have a Feh script that points to a folder that is shared via Windows (Samba) share. I currently have the capability to drag and drop images from windows to my Debian shared folder and they show up in the Feh slide show. My issue is that I would like for Feh to restart when ever changes are made (IE: images are added) to the directory. Anyone know how to do this?
 
Old 10-21-2011, 08:58 PM   #2
countach74
Member
 
Registered: Feb 2011
Distribution: Ubuntu 10.04, Debian Squeeze
Posts: 46

Rep: Reputation: 8
I'm not familiar with Feh, but you could simply create a script that checks the modified time of the folder and restarts Feh if it has changed and place the script into Cron, running once every couple minutes. It won't update it immediately, but that's probably a good thing. It would be a simple script to write: if you are not familiar with scripts or cron, I can help if you would like.
 
Old 10-21-2011, 09:18 PM   #3
countach74
Member
 
Registered: Feb 2011
Distribution: Ubuntu 10.04, Debian Squeeze
Posts: 46

Rep: Reputation: 8
OK, I was bored, so I wrote up a quick script anyways. I'm not exactly a programmer, so be nice.

Code:
#!/bin/bash

# If no temporary file storing last modified date/time exists, create it.
if [[ ! -f /tmp/lastmodified ]]; then
  date -r /home/countach74/testdir +%s > /tmp/lastmodified 2>/dev/null

# Temp file must already exist, so let's scan it and see if the timestamp
# stored in it matches the timestamp of the Feh directory.
else
  prevmodified=`cat /tmp/lastmodified`
  lastmodified=`date -r /home/countach74/testdir +%s 2>/dev/null`

  # If the the timestamp stored in /tmp is different than the current
  # timestamp, update the file in tmp and restart Feh.
  if [[ $prevmodified -ne $lastmodified ]]; then
    echo $lastmodified > /tmp/lastmodified 2>/dev/null
    # Do other things here, such as restart Feh
  fi
fi

exit 0
Now make the script executable and add it to cron and run it every minute.

Code:
chmod +x /path/to/script.sh
crontab -e
Add an entry like this:

Code:
* * * * * /path/to/script.sh >/dev/null 2>&1

Last edited by countach74; 10-21-2011 at 09:20 PM. Reason: Whoops, used [quote] instead of [code]
 
Old 10-22-2011, 10:56 AM   #4
lonesoac0
Member
 
Registered: Jan 2010
Distribution: Ubuntu
Posts: 95

Original Poster
Rep: Reputation: 4
Thank you! I have been playing with bourne shell scripts myself and sometimes it aint easy to program what you want. I will have to give your script a try. Additionally, I found an application called incron in the Debian Squeeze repository. It is very simular to the crontab file but instead of watching for time it watches for changes in directories and executes commands. The main issue that I have is that when I write multiple files to the watched directory by incron , incron launches several instances of Feh (slide show app). The really interesting thing is that I am executing a script called slide_show with incron. The script by itself works perfectly by first checking for any instance of Feh or mplayer and then launching Feh if no instance(s) are found. But with incron the only thing that seems to be executed properly is the part that launches Feh with all of the parameters.
Attached Files
File Type: txt slide_show.txt (154 Bytes, 6 views)
 
Old 10-22-2011, 10:58 AM   #5
lonesoac0
Member
 
Registered: Jan 2010
Distribution: Ubuntu
Posts: 95

Original Poster
Rep: Reputation: 4
by the way, I took a closer look at your script and you read my mind. I was thinking of the same concept of script.
 
Old 10-22-2011, 11:12 AM   #6
countach74
Member
 
Registered: Feb 2011
Distribution: Ubuntu 10.04, Debian Squeeze
Posts: 46

Rep: Reputation: 8
Doesn't the slideshow script need to terminate any existing Feh instances if they're found? Oh, by the way, one issue with my script is that it will not detect if an image changes--only if one is added or removed. If you wanted to test for modifications, it wouldn't be very hard, actually. I was thinking about it more and probably the easiest way to do that would be to do an ls -l of your image directory and hash it with something like md5sum. Store that instead of the UNIX time of the last modification. It would look something like:

Code:
#!/bin/bash

# If no temporary file storing last modified date/time exists, create it.
if [[ ! -f /tmp/lastmodified ]]; then
  ls -l /home/countach74/testdir | md5sum - | awk '{print $1}' > /tmp/lastmodified 2>/dev/null

# Temp file must already exist, so let's scan it and see if the timestamp
# stored in it matches the timestamp of the Feh directory.
else
  prevmodified=`cat /tmp/lastmodified`
  lastmodified=`ls -l /home/countach74/testdir | md5sum - | awk '{print $1}'`

  # If the the timestamp stored in /tmp is different than the current
  # timestamp, update the file in tmp and restart Feh.
  if [[ $prevmodified != $lastmodified ]]; then
    echo $lastmodified > /tmp/lastmodified 2>/dev/null
    # Do other things here, such as restart Feh
  fi
fi

exit 0

Last edited by countach74; 10-22-2011 at 11:23 AM.
 
Old 10-22-2011, 03:47 PM   #7
lonesoac0
Member
 
Registered: Jan 2010
Distribution: Ubuntu
Posts: 95

Original Poster
Rep: Reputation: 4
Quote:
"Doesn't the slideshow script need to terminate any existing Feh instances if they're found?"
That is a very good question. I originally did not have the idea for scanning for changes in my images directory, I simply did not want more than one instance of either mplayer or feh to be running at the same time, because I have the options set for full screen on both applications. The applications would run but only the top most app would be seen.

as for your original script, I tried it out and it works great for only the root directory that it is monitoring. I placed another folder inside of the root dir and then removed a few files from the directory inside of the root dir. the application did not start as anticipated.
 
Old 10-22-2011, 09:56 PM   #8
countach74
Member
 
Registered: Feb 2011
Distribution: Ubuntu 10.04, Debian Squeeze
Posts: 46

Rep: Reputation: 8
Yeah, that would be anticipated. If you wanted to scan all the directories, change both instances of the ls -l command to ls -lR in the most recent script that I posted (the one that uses hashing rather than date).
 
1 members found this post helpful.
Old 10-24-2011, 10:12 AM   #9
lonesoac0
Member
 
Registered: Jan 2010
Distribution: Ubuntu
Posts: 95

Original Poster
Rep: Reputation: 4
I have had mixed results with impletmenting the second script. When I use the new script, my slide show takes FOREVER! I suspect that since hashing is taking place it may take my application longer to launch. The more photos/movies I have the longer it will take. I may end up going with the first script.
 
Old 10-24-2011, 12:37 PM   #10
countach74
Member
 
Registered: Feb 2011
Distribution: Ubuntu 10.04, Debian Squeeze
Posts: 46

Rep: Reputation: 8
That is odd. Md5 hashing even a very long directory tree should still take less than a second.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
directory size includes size of .. leostar_10 Linux - Newbie 4 12-03-2007 05:12 PM
Directory Size carlosinfl Linux - General 3 01-09-2007 09:06 PM
directory size adenardo Linux - General 1 10-23-2001 02:34 PM
Directory size Steave Linux - General 4 09-03-2001 05:13 AM
Directory Size Helixx Linux - General 1 04-27-2001 09:49 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:07 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration