Advertisement
Guest User

Untitled

a guest
Feb 9th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.99 KB | None | 0 0
  1. #!/bin/sh
  2. directory=/volume1/multimedia/Internet\ Radio\ Recordings/
  3. runtimeInSeconds=$((20*3))
  4. endSeconds=$((SECONDS + runtimeInSeconds))
  5.  
  6. echo "Beginning..."
  7.  
  8. while [ $SECONDS -lt $endSeconds ]; do
  9.     fileName="TEST-"$(date +"%m-%d-%Y-%H%M(%S)")
  10.     wget http://144.217.153.67/sj128.mp3 --timeout=1 --waitretry=0 --tries=1 -O "$directory$fileName.mp3" -q&
  11.     nWgetPID=$!
  12.  
  13.     echo "Filename "$fileName" created with process "$nWgetPID
  14.  
  15.     # “kill -0 "$nWgetPID"” returns a process ID until...
  16.     while kill -0 "$nWgetPID" >/dev/null 2>&1; do
  17.         if [ $SECONDS -gt $endSeconds ]
  18.         then
  19.             echo killing the PID
  20.             kill "$nWgetPID"
  21.         else #the purpose here is to make sure it restarts the file when the PID dies prematurely
  22.             if [ $SECONDS -gt 20 ]
  23.             then
  24.                 kill "$nWgetPID"
  25.             fi
  26.         fi
  27.         # runs every second
  28.         # while loop ends when PID is killed
  29.             #echo $SECONDS
  30.             #echo kill -0 "$nWgetPID"
  31.         sleep 5
  32.     done
  33. done
  34.  
  35. echo "Done. Reached "$endSeconds
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement