0

I'm trying to create script to stop to my specified date and time. I'am making jumanji box and the vidéo must start at date and precise time and stop to specified date and time. Can you show me how to set correct format for mydate ?

    #!/bin/bash
NOW=$( date '+%F_%H:%M:%S' )
MYDATE=??
    while [ "$NOW" != "$MYDATE" ]
     do      
    bash -c "DISPLAY=:0 mpv --fs $vlcopts  /home/pi/Videos/Jumanji_intro.mp4"
    done

Can you please help me ? Thx

1 Answers1

0

You can check the format of the entered date by checking the return code of date formatted against the entered date string:

#!/bin/bash
err=1 # Initialize error code to 1
while [[ "$err" == "1" ]] # While error code is 1, loop
do
    read -p "Please enter a date in the format YYYY/MM/DD HH:MM:SS " MYDATE # Prompt for a date and time in a set format
    if date -d "$MYDATE" '+%F_%H:%M:%S' > /dev/null 2>&1# Check that date can format the entered string and redirect an errors to /dev/null
    then
        mdates=$(date -d "$MYDATE" '+%s') # Use epoch format (%s) of date to check against today's date
        tdates=$(date '+%s')
        if [[ "$mdates" -lt "$tdates" ]] # Compare entered epoch date to today's
        then
             echo "ERROR - Date/Time entered is in the past"
             err=1
        else
             err=0
        fi
    else
        err=1
    fi
done

    
Raman Sailopal
  • 12,320
  • 2
  • 11
  • 18