echo $(date +%I:%M:%S_%D) >> /tmp/systemd_suspend_test_err.txt
exec 2>> /tmp/systemd_suspend_test_err.txt
if [ "${1}" = "pre" ]; then
# Do the thing you want before suspend here
echo "we are suspending $(date +%I:%M:%S_%D)."
elif [ "${1}" = "post" ]; then
# Do the thing you want after resume here
echo "and we are back from being suspended $(date +%I:%M:%S_%D)"
# gxmessage works IF xhost + is run first.
gxmessage -timeout 5 -fg red -display :0 'Back from being suspended.'
#ffplay /usr/share/sounds/My_Sounds/Relax_6_Seconds.mp3
mplayer /usr/share/sounds/My_Sounds/Relax_6_Seconds.mp3
fi
>> opens a file append (open file, move file pointer to the very end of the file), if the file does not exist it tries to create the file and opens it for write at position zero. Any of these steps can give the error you got.
What do you get? Note: Are you creating new file?? ... you need write privilege to the directory, otherwise just write privilege to the file itself and a minimum of execute on the path.
>> uses an existing file if one is available, it does not clear out old data in the file like > does.
If the dates are precisely the same down to the second then I do not see why. If you rerun your code then the first, older, timestamp should be at least a few seconds in the past.
Open the file with > and previous contents is overwritten.
BTW if you permanently open it with exec then you can do this
exec 2> /tmp/systemd_suspend_test_err.txt
date "+%I:%M:%S_%D" >&2
Note that the exec opens the file, either open-truncate with > or open-append with >>, and associates descriptor 2=stderr with it.
Subsequent writes to stderr go to the stream i.e. append.