Schedule task at cron| DISPLAY=:0 | tty | /dev/pts/#| why can't I see the output of my command

## Schedule Tasks Using "at" and "crontab"

Here is the problem, you schedule a task with a task scheduler such as "at" or "cron", say want to run your browser at a particular time, you write appropriate command and when the time comes nothing seems to happen... Why is it?
To use "at" command (in Debian) we need to install the "at" package
 # apt install at
To find out the tty (terminal type) number of our shell session we run
$tty In my case I got the following output /dev/pts/6 So, to direct the output of "at" command's to my shell, I need to send them to my pts (pseudo terminal slave) 6. For example, If I want my terminal to display: "Good Afternoon" at 13:30 am (assuming that I am in the morning of the same day), then I can run the "at" command first $ at 13:30 
in the "at" prompt I can write
at> echo "Good Afternoon" >/dev/pts/6
To run a web-browser such as firefox I need to find the value of DISPLAY (environment variable)
$echo$DISPLAY
In my case it is
 :0 
and then I can run "at"
$at 13:30  and in the "at" prompt I can write at> export DISPLAY=:0 && firefox  To view "at" tasks we may run $ atq 
To delete a particular scheduled job, say job number 1, we may run:
$atrm 1 More on "at" command option can be found in "at" manual $ man at
The Cron process scheduling daemon was developed for chronically repeated tasks. To install cron run:
 # apt install cron
Now to schedule a task run:
crontab -e
Crontab will open a file with commented on how to schedule a task.

# Edit this file to introduce tasks to be run by cron.
#
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task
#
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').#
# Notice that tasks will be started based on the cron's system
# daemon's notion of time and timezones.
#
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
#
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
#
# For more information see the manual pages of crontab(5) and cron(8)
#
# m h  dom mon dow   command

# dom = day of month
# mon = month
# day of the week 0-6

  To schedule a command (or script) execution we simply edit this file, just go to the end of the file and insert any command or script as shown in the commented instructions. As in the case of "at" the output of the command won't appear in the terminal. So if we want to schedule a virus scan every Sunday at 3:00 am and we want to display the output in terminal, say /dev/pts/5 (pseudo terminal slave number 5), then we need to to append the following line:
0 3 * * 0 clamscan -r \$HOME > /dev/pts/5 
To run firefox every day at 8:00 am I append
0 8 * * * export DISPLAY=:0 &&  firefox  

Disclaimer Privacy