0

I have a script that when executed generates a temp file that i want deleted 10 minutes after the script completes.

I have looked at the "at" command which does what I need, but it requires interactive input. Is there any way to do this non-interactively?

Karim
  • 3

2 Answers2

2

From man at:

at and batch read commands from standard input or a specified file which are to be executed at a later time, using /bin/sh.

So just send the command you would type in interactively to at as input:

echo 'rm that.file' | at now+10min
manatwork
  • 31,277
  • that will work, don't know why I didn't think of piping to at. – Karim Apr 05 '13 at 11:32
  • I just remembered a similar problem I had with ftp some years ago which had a solution I could reuse, this also seems to work:

    at now + 10 min <<'EOF' rm $file EOF

    – Karim Apr 05 '13 at 11:40
0

An alternative is using the command sleep. For example 'sleep 600 && rm that.file' will delete that.file after 600 seconds ('man sleep' shows a more detailed example).

superuser0
  • 1,710