Skip to main content
added 4 characters in body
Source Link
MJiller
  • 391
  • 5
  • 15

I'm trying to adapt the script below (taken from https://superuser.com/questions/181517/how-to-execute-a-command-whenever-a-file-changes) to cause my system to record a video stream whenever a particular file changes on the system:

#!/bin/bash

# Set initial time of file
LTIME=`stat -c %Z /path/to/monitored/file`

while true    
do
   ATIME=`stat -c %Z /path/to/monitored/file`

   if [[ "$ATIME" != "$LTIME" ]]
   then    
       echo "RUN COMMAND"
       LTIME=$ATIME
   fi
   sleep 5
done

As is evident, the script polls the time stamp of the monitored file every 5 seconds to see whether it has changed and, if it has, echoes something to the terminal. It will also be clear that the echo command is just a sort of proof-of-concept and that just about any other command could take its place in the script.

Here's what I've got so far that almost works as desired for my purposes (recordingscript.sh uses mplayer -dumpstream -dumpfile mystream URL to record a stream for 70 minutes):

#!/bin/bash

# Set initial time of file
LTIME=`stat -c %Z /path/to/monitored/file`

while true    
do
   ATIME=`stat -c %Z /path/to/monitored/file`

   if [[ "$ATIME" != "$LTIME" ]]; then
      /path/to/my/recordingscript.sh
        break
      LTIME=$ATIME
   fi
   sleep 5
done

The problem that remains is that I would like for this script to run as a cron job each dayweekday within, say, a 5 hour time frame. If no change is made to the monitored file within that time frame, I'd simply like for the script to abort/exit until the next time cron starts it. How can I modify my adapted script so that it will only run for about 5 hours, then exit? I realize I could probably do this by invoking the script with timeout 300m but I thought there might be other, possibly better, solutions for doing this

I'm trying to adapt the script below (taken from https://superuser.com/questions/181517/how-to-execute-a-command-whenever-a-file-changes) to cause my system to record a video stream whenever a particular file changes on the system:

#!/bin/bash

# Set initial time of file
LTIME=`stat -c %Z /path/to/monitored/file`

while true    
do
   ATIME=`stat -c %Z /path/to/monitored/file`

   if [[ "$ATIME" != "$LTIME" ]]
   then    
       echo "RUN COMMAND"
       LTIME=$ATIME
   fi
   sleep 5
done

As is evident, the script polls the time stamp of the monitored file every 5 seconds to see whether it has changed and, if it has, echoes something to the terminal. It will also be clear that the echo command is just a sort of proof-of-concept and that just about any other command could take its place in the script.

Here's what I've got so far that almost works as desired for my purposes (recordingscript.sh uses mplayer -dumpstream -dumpfile mystream URL to record a stream for 70 minutes):

#!/bin/bash

# Set initial time of file
LTIME=`stat -c %Z /path/to/monitored/file`

while true    
do
   ATIME=`stat -c %Z /path/to/monitored/file`

   if [[ "$ATIME" != "$LTIME" ]]; then
      /path/to/my/recordingscript.sh
        break
      LTIME=$ATIME
   fi
   sleep 5
done

The problem that remains is that I would like for this script to run as a cron job each day within, say, a 5 hour time frame. If no change is made to the monitored file within that time frame, I'd simply like for the script to abort/exit until the next time cron starts it. How can I modify my adapted script so that it will only run for about 5 hours, then exit? I realize I could probably do this by invoking the script with timeout 300m but I thought there might be other, possibly better, solutions for doing this

I'm trying to adapt the script below (taken from https://superuser.com/questions/181517/how-to-execute-a-command-whenever-a-file-changes) to cause my system to record a video stream whenever a particular file changes on the system:

#!/bin/bash

# Set initial time of file
LTIME=`stat -c %Z /path/to/monitored/file`

while true    
do
   ATIME=`stat -c %Z /path/to/monitored/file`

   if [[ "$ATIME" != "$LTIME" ]]
   then    
       echo "RUN COMMAND"
       LTIME=$ATIME
   fi
   sleep 5
done

As is evident, the script polls the time stamp of the monitored file every 5 seconds to see whether it has changed and, if it has, echoes something to the terminal. It will also be clear that the echo command is just a sort of proof-of-concept and that just about any other command could take its place in the script.

Here's what I've got so far that almost works as desired for my purposes (recordingscript.sh uses mplayer -dumpstream -dumpfile mystream URL to record a stream for 70 minutes):

#!/bin/bash

# Set initial time of file
LTIME=`stat -c %Z /path/to/monitored/file`

while true    
do
   ATIME=`stat -c %Z /path/to/monitored/file`

   if [[ "$ATIME" != "$LTIME" ]]; then
      /path/to/my/recordingscript.sh
        break
      LTIME=$ATIME
   fi
   sleep 5
done

The problem that remains is that I would like for this script to run as a cron job each weekday within, say, a 5 hour time frame. If no change is made to the monitored file within that time frame, I'd simply like for the script to abort/exit until the next time cron starts it. How can I modify my adapted script so that it will only run for about 5 hours, then exit? I realize I could probably do this by invoking the script with timeout 300m but I thought there might be other, possibly better, solutions for doing this

added 2 characters in body
Source Link
MJiller
  • 391
  • 5
  • 15

I'm trying to adapt the script below (taken from https://superuser.com/questions/181517/how-to-execute-a-command-whenever-a-file-changes) to cause my system to record a video stream whenever a particular file changes on the system:

#!/bin/bash

# Set initial time of file
LTIME=`stat -c %Z /path/to/monitored/file`

while true    
do
   ATIME=`stat -c %Z /path/to/monitored/file`

   if [[ "$ATIME" != "$LTIME" ]]
   then    
       echo "RUN COMMAND"
       LTIME=$ATIME
   fi
   sleep 5
done

As is evident, the script polls the time stamp of the monitored file every 5 seconds to see whether it has changed and, if it has, echoes something to the terminal. It will also be clear that the echo command is just a sort of proof-of-concept and that just about any other command could take its place in the script.

Here's what I've got so far that almost works as desired for my purposes (recordingscript.sh uses mplayer -dumpstream -dumpfile mystream URL to record a stream for 70 minutes):

#!/bin/bash

# Set initial time of file
LTIME=`stat -c %Z /path/to/monitored/file`

while true    
do
   ATIME=`stat -c %Z /path/to/monitored/file`

   if [[ "$ATIME" != "$LTIME" ]]; then
      /path/to/my/recordingscript.sh
        break
      LTIME=$ATIME
   fi
   sleep 5
done

The problem that remains is that I would like for this script to run as a cron job each day within, say, a 5 hour time frame. If no change is made to the monitored file within that time frame, I'd simply like for the script to abort/exit until the next time cron starts it. How can I modify my adapted script so that it will only run for about 5 hours, then exit? I realize I could probably do this by invoking the script with timeout 300mtimeout 300m but I thought there might be other, possibly better, solutions for doing this

I'm trying to adapt the script below (taken from https://superuser.com/questions/181517/how-to-execute-a-command-whenever-a-file-changes) to cause my system to record a video stream whenever a particular file changes on the system:

#!/bin/bash

# Set initial time of file
LTIME=`stat -c %Z /path/to/monitored/file`

while true    
do
   ATIME=`stat -c %Z /path/to/monitored/file`

   if [[ "$ATIME" != "$LTIME" ]]
   then    
       echo "RUN COMMAND"
       LTIME=$ATIME
   fi
   sleep 5
done

As is evident, the script polls the time stamp of the monitored file every 5 seconds to see whether it has changed and, if it has, echoes something to the terminal. It will also be clear that the echo command is just a sort of proof-of-concept and that just about any other command could take its place in the script.

Here's what I've got so far that almost works as desired for my purposes (recordingscript.sh uses mplayer -dumpstream -dumpfile mystream URL to record a stream for 70 minutes):

#!/bin/bash

# Set initial time of file
LTIME=`stat -c %Z /path/to/monitored/file`

while true    
do
   ATIME=`stat -c %Z /path/to/monitored/file`

   if [[ "$ATIME" != "$LTIME" ]]; then
      /path/to/my/recordingscript.sh
        break
      LTIME=$ATIME
   fi
   sleep 5
done

The problem that remains is that I would like for this script to run as a cron job each day within, say, a 5 hour time frame. If no change is made to the monitored file within that time frame, I'd simply like for the script to abort/exit until the next time cron starts it. How can I modify my adapted script so that it will only run for about 5 hours, then exit? I realize I could probably do this by invoking the script with timeout 300m but I thought there might be other, possibly better, solutions for doing this

I'm trying to adapt the script below (taken from https://superuser.com/questions/181517/how-to-execute-a-command-whenever-a-file-changes) to cause my system to record a video stream whenever a particular file changes on the system:

#!/bin/bash

# Set initial time of file
LTIME=`stat -c %Z /path/to/monitored/file`

while true    
do
   ATIME=`stat -c %Z /path/to/monitored/file`

   if [[ "$ATIME" != "$LTIME" ]]
   then    
       echo "RUN COMMAND"
       LTIME=$ATIME
   fi
   sleep 5
done

As is evident, the script polls the time stamp of the monitored file every 5 seconds to see whether it has changed and, if it has, echoes something to the terminal. It will also be clear that the echo command is just a sort of proof-of-concept and that just about any other command could take its place in the script.

Here's what I've got so far that almost works as desired for my purposes (recordingscript.sh uses mplayer -dumpstream -dumpfile mystream URL to record a stream for 70 minutes):

#!/bin/bash

# Set initial time of file
LTIME=`stat -c %Z /path/to/monitored/file`

while true    
do
   ATIME=`stat -c %Z /path/to/monitored/file`

   if [[ "$ATIME" != "$LTIME" ]]; then
      /path/to/my/recordingscript.sh
        break
      LTIME=$ATIME
   fi
   sleep 5
done

The problem that remains is that I would like for this script to run as a cron job each day within, say, a 5 hour time frame. If no change is made to the monitored file within that time frame, I'd simply like for the script to abort/exit until the next time cron starts it. How can I modify my adapted script so that it will only run for about 5 hours, then exit? I realize I could probably do this by invoking the script with timeout 300m but I thought there might be other, possibly better, solutions for doing this

added 154 characters in body
Source Link
MJiller
  • 391
  • 5
  • 15

I'm trying to adapt the script below (taken from https://superuser.com/questions/181517/how-to-execute-a-command-whenever-a-file-changes) to cause my system to record a video stream whenever a particular file changes on mythe system:

#!/bin/bash

# Set initial time of file
LTIME=`stat -c %Z /path/to/monitored/file`

while true    
do
   ATIME=`stat -c %Z /path/to/monitored/file`

   if [[ "$ATIME" != "$LTIME" ]]
   then    
       echo "RUN COMMAND"
       LTIME=$ATIME
   fi
   sleep 5
done

As is evident, the script polls the time stamp of the monitored file every 5 seconds to see whether it has changed and, if it has, echoes something to the terminal. It will also be clear that the echo command is just a sort of proof-of-concept and that just about any other command could take its place in the script.

Here's what I've got so far that almost works as I want it todesired for my purposes (recordingscript.sh uses mplayer -dumpstream -dumpfile mystream URL to record a stream for 70 minutes):

#!/bin/bash

# Set initial time of file
LTIME=`stat -c %Z /path/to/monitored/file`

while true    
do
   ATIME=`stat -c %Z /path/to/monitored/file`

   if [[ "$ATIME" != "$LTIME" ]]; then
      /path/to/my/recordingscript,.sh
        break
      LTIME=$ATIME
   fi
   sleep 5
done

The problem that remains is that I would like for this script to run as a cron job each day within, say, a 5 hour time frame. If no change is made to the monitored file within that time frame, I'd simply like for the script to abort/exit until the next time cron starts it. How can I modify my adapted script so that it will only run for about 5 hours, then exit? I realize I could probably do this by invoking the script with timeout 300m but I thought there might be other, possibly better, solutions for doing this

I'm trying to adapt the script below (taken from https://superuser.com/questions/181517/how-to-execute-a-command-whenever-a-file-changes) to cause my system to record a video stream whenever a particular file changes on my system:

#!/bin/bash

# Set initial time of file
LTIME=`stat -c %Z /path/to/monitored/file`

while true    
do
   ATIME=`stat -c %Z /path/to/monitored/file`

   if [[ "$ATIME" != "$LTIME" ]]
   then    
       echo "RUN COMMAND"
       LTIME=$ATIME
   fi
   sleep 5
done

As is evident, the script polls the time stamp of the monitored file every 5 seconds to see whether it has changed and, if it has, echoes something to the terminal.

Here's what I've got so far that almost works as I want it to for my purposes (recordingscript.sh uses mplayer -dumpstream -dumpfile mystream URL to record a stream for 70 minutes):

#!/bin/bash

# Set initial time of file
LTIME=`stat -c %Z /path/to/monitored/file`

while true    
do
   ATIME=`stat -c %Z /path/to/monitored/file`

   if [[ "$ATIME" != "$LTIME" ]]; then
      /path/to/my/recordingscript,sh
        break
      LTIME=$ATIME
   fi
   sleep 5
done

The problem that remains is that I would like for this script to run as a cron job each day within, say, a 5 hour time frame. If no change is made to the monitored file within that time frame, I'd simply like for the script to abort/exit until the next time cron starts it. How can I modify my adapted script so that it will only run for about 5 hours, then exit? I realize I could probably do this by invoking the script with timeout 300m but I thought there might be other, possibly better, solutions for doing this

I'm trying to adapt the script below (taken from https://superuser.com/questions/181517/how-to-execute-a-command-whenever-a-file-changes) to cause my system to record a video stream whenever a particular file changes on the system:

#!/bin/bash

# Set initial time of file
LTIME=`stat -c %Z /path/to/monitored/file`

while true    
do
   ATIME=`stat -c %Z /path/to/monitored/file`

   if [[ "$ATIME" != "$LTIME" ]]
   then    
       echo "RUN COMMAND"
       LTIME=$ATIME
   fi
   sleep 5
done

As is evident, the script polls the time stamp of the monitored file every 5 seconds to see whether it has changed and, if it has, echoes something to the terminal. It will also be clear that the echo command is just a sort of proof-of-concept and that just about any other command could take its place in the script.

Here's what I've got so far that almost works as desired for my purposes (recordingscript.sh uses mplayer -dumpstream -dumpfile mystream URL to record a stream for 70 minutes):

#!/bin/bash

# Set initial time of file
LTIME=`stat -c %Z /path/to/monitored/file`

while true    
do
   ATIME=`stat -c %Z /path/to/monitored/file`

   if [[ "$ATIME" != "$LTIME" ]]; then
      /path/to/my/recordingscript.sh
        break
      LTIME=$ATIME
   fi
   sleep 5
done

The problem that remains is that I would like for this script to run as a cron job each day within, say, a 5 hour time frame. If no change is made to the monitored file within that time frame, I'd simply like for the script to abort/exit until the next time cron starts it. How can I modify my adapted script so that it will only run for about 5 hours, then exit? I realize I could probably do this by invoking the script with timeout 300m but I thought there might be other, possibly better, solutions for doing this

Source Link
MJiller
  • 391
  • 5
  • 15
Loading