Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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?

share|improve this question

2 Answers 2

up vote 2 down vote accepted

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
share|improve this answer
    
that will work, don't know why I didn't think of piping to at. –  David Berkan Apr 5 '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 –  David Berkan Apr 5 '13 at 11:40

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).

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.