[solved] "at" command

Forum rules
Before you post please read how to get help
Post Reply
User avatar
lewtwo
Level 3
Level 3
Posts: 159
Joined: Wed Oct 29, 2014 8:33 pm

[solved] "at" command

Post by lewtwo » Mon Jun 24, 2019 2:20 pm

OK ... this is going to be a really dumb question about the at command. When I search for linux and schedule all I find are references to cron. I need to schedule a command or script to run at a specific time on a specific date and cron is less than ideal for that purpose. I have tried searching on line but just try searching for the word "at" .....? Documentation is sparse at best.

The last time I ran into this problem I wound up writing my own scheduler (I needed one second granularity anyway).
I would rather not reinvent the wheel again.

First off "at" is not installed by default ... it has to added (I got that part):

Code: Select all

 $ sudo apt-get install at
Some documentation I found (but not for Linux Mint) indicated that there was also a daemon that had to be enabled and added to start up ... ????

Where are the "at" files are stored?
.... I can find nothing under /var/spool/ that relates to the "at" command.

If one can find said files then can new entries be added programmatically or must one use a subprocess to open up a shell and execute the "at" command line?

If the "-f" option is used is that shell file read at the time the "at" command is run or is it run at the time the scheduled command is executed.

Does the scheduled command open up a terminal window or can the scheduled command be run as a background process ?
Last edited by lewtwo on Tue Jun 25, 2019 1:16 am, edited 3 times in total.
"Engineering is the art of planning and forethought."
http://www.keywild.com

deepakdeshp
Level 15
Level 15
Posts: 5667
Joined: Sun Aug 09, 2015 10:00 am

Re: "at" command

Post by deepakdeshp » Mon Jun 24, 2019 5:25 pm

If I have helped you solve a problem, please add [SOLVED] to your first post title, it helps other users looking for help, and keeps the forum clean.
Regards,
Deepak

I am using Mint 19.2 Cinnamon 64 bit with AMD A8/7410 processor . Memory 8GB

User avatar
lewtwo
Level 3
Level 3
Posts: 159
Joined: Wed Oct 29, 2014 8:33 pm

Re: "at" command

Post by lewtwo » Tue Jun 25, 2019 12:36 am

Thank thee :-)

For posterity, I will answer some of my own questions:
Q: is there a daemon that has to be enabled and added to start up?
A: No .... or at least on Linux Mint "sudo apt-get install at" seems to get the job done

Q: Does the scheduled command open up a terminal window?
A: No the command is run as a background process.

Q: Can I schedule the execution down to the second?
A: No, but you insert a delay in the shell script using the 'sleep' command.

Q: If the "-f" option is used is that shell file read at the time the "at" command is run?
A: "at" checks to see if the files exists and copies it.
.... If the file is deleted prior to execution time then execution fails (verified twice).

.... If the file is 'modified' prior to the execution time then a 'copy' of the 'old' file is run (verified twice).
A copy of the 'environment' and the 'shell file' is stored in the directory "/var/spool/cron/atjobs"
That file is deleted after execution. It is a binary file. I would not attempt to modify it.

Code: Select all

#!/bin/bash
# ~/testdir/testone.sh
#
# Instructions:
# install the "at" command with: sudo apt-get install at
# make a test directory with: mkdir $HOME/testdir
# place this file in that directory
#
# open a terminal window and invoke the "at" command with:
# at now+2 minutes -M -f "$HOME/testdir/testone.sh"
# the -M option suppresses emails

cd $HOME/testdir
# sleep 15s
cp testone.sh testone$(date +%T).txt
typical command output:

Code: Select all

$ at now+2 minutes -M -f "$HOME/testdir/testone.sh"
warning: commands will be executed using /bin/sh
job 6 at Mon Jun 24 23:19:00 2019
"Engineering is the art of planning and forethought."
http://www.keywild.com

Post Reply

Return to “Scripts & Bash”