The officially official Devuan Forum!

You are not logged in.

#1 2020-12-12 13:41:17

dice
Member
Registered: 2020-11-22
Posts: 559  
Website

at program

Im trying to figure out the at command without much luck.

at executes commands at a specified time.

https://packages.debian.org/bullseye/at

i have the atd daemon running in service

 ~ $ > service atd status
atd is running

Im not sure what im to expect but im pretty sure a terminal window should appear in 1 minute from executing the at command using these commands?

~ $ > at now + 1 minute -f /usr/local/bin/st
warning: commands will be executed using /bin/sh
job 21 at Sat Dec 12 23:37:00 2020

Nothing happens ??

Im want to integrate at into a script somehow but if it doesnt work on the commandline then its useless or im useless and dont know what im doing.

This is a chimaera/testing installation.

Last edited by dice (2020-12-12 13:46:00)

Offline

#2 2020-12-12 14:38:13

fsmithred
Administrator
Registered: 2016-11-25
Posts: 2,409  

Re: at program

It's not you, and it's not just chimaera. I tried it in beowulf, and I can't get it to work. When I tried 'at' around 10 years ago, it was simple to figure out and it worked as expected. I'm not sure what changed.

The man page states that HH:MM is the correct format for time, but apparently 09:21 or similar is not the correct time format. So I no longer know how to do HH:MM. I tried it around two dozen different ways. (Can you tell that I'm angry?)

Sorry I have nothing useful to offer. Oh wait, yes I do. Screw at, make a cron job. Last time I did that it worked as expected.

Offline

#3 2020-12-12 14:58:44

dice
Member
Registered: 2020-11-22
Posts: 559  
Website

Re: at program

yeah made me a bit angry as well.  I will have to try and incorporate cron into what im thinking of. I wanted to emulate gnome backgrounds adwaita morning noon night wallpapers somehow with feh.

Last edited by dice (2020-12-12 14:59:07)

Offline

#4 2020-12-12 15:41:16

Head_on_a_Stick
Member
From: London
Registered: 2019-03-24
Posts: 3,125  
Website

Re: at program

dice wrote:
~ $ > at now + 1 minute -f /usr/local/bin/st

The -f switch causes the command to be read from a file, which you have specified as /usr/local/bin/st.

Try this instead:

echo 'DISPLAY=:0 /usr/local/bin/st' > ~/test
at now + 1 minute -f ~/test

^ That works for me. Note that any environmental variables are not passed to the command so they must be specified explicitly.

fsmithred wrote:

The man page states that HH:MM is the correct format for time, but apparently 09:21 or similar is not the correct time format. So I no longer know how to do HH:MM.

Actually the man page says:

at(1) wrote:

-t time
    run the job at time, given in the format [[CC]YY]MMDDhhmm[.ss]

So try

at -t 12121600 -f ~/test

HTH

EDIT: that example runs the command on 2020-12-12 at 16:00.

Last edited by Head_on_a_Stick (2020-12-12 15:43:25)


Brianna Ghey — Rest In Power

Offline

#5 2020-12-12 16:09:31

dice
Member
Registered: 2020-11-22
Posts: 559  
Website

Re: at program

Thanks head on a stick.

I cant understand how the command is laid out though. very strange if you ask me.

This below worked for a feh command.

echo 'DISPLAY=:0 $HOME/bin/fehrand' > ~/test
at now + 1 minute -f ~/test

but this below would not work as a line not broken.

echo 'DISPLAY=:0 $HOME/bin/fehrand' > ~/test at now + 1 minute -f ~/test

home env variable added to the code quotes.

contents of fehrand

#!/bin/bash

feh --randomize --bg-scale /usr/share/backgrounds/*

Last edited by dice (2020-12-12 16:11:36)

Offline

#6 2020-12-12 16:25:02

dice
Member
Registered: 2020-11-22
Posts: 559  
Website

Re: at program

Think i have it, thanks head on a stick. Need to adjust times and add into a startup script, but this is what im after...

echo 'DISPLAY=:0 feh --bg-scale /usr/share/backgrounds/gnome/adwaita-morning.jpg' > ~/test
at now + 1 minute -f ~/test
echo 'DISPLAY=:0 feh --bg-scale /usr/share/backgrounds/gnome/adwaita-day.jpg' > ~/test
at now + 1 minute -f ~/test
echo 'DISPLAY=:0 feh --bg-scale /usr/share/backgrounds/gnome/adwaita-night.jpg' > ~/test
at now + 1 minute -f ~/test

Offline

#7 2020-12-12 16:25:35

Head_on_a_Stick
Member
From: London
Registered: 2019-03-24
Posts: 3,125  
Website

Re: at program

dice wrote:

but this below would not work as a line not broken.

echo 'DISPLAY=:0 $HOME/bin/fehrand' > ~/test
at now + 1 minute -f ~/test

I don't think $HOME will be understood unless you specify it (replace $user with the actual username):

echo 'DISPLAY=:0 HOME=/home/$user $HOME/bin/fehrand' > ~/test
at now + 1 minute -f ~/test

Or just call the full path to the script, which would be simpler.


Brianna Ghey — Rest In Power

Offline

#8 2020-12-12 16:30:39

dice
Member
Registered: 2020-11-22
Posts: 559  
Website

Re: at program

Head_on_a_Stick wrote:
dice wrote:

but this below would not work as a line not broken.

echo 'DISPLAY=:0 $HOME/bin/fehrand' > ~/test
at now + 1 minute -f ~/test

I don't think $HOME will be understood unless you specify it (replace $user with the actual username):

echo 'DISPLAY=:0 HOME=/home/$user $HOME/bin/fehrand' > ~/test
at now + 1 minute -f ~/test

Or just call the full path to the script, which would be simpler.

im just not using full paths publicly on the forum.

Offline

#9 2020-12-12 18:34:01

fsmithred
Administrator
Registered: 2016-11-25
Posts: 2,409  

Re: at program

HoaS: I was referring to this part of the man page:

At allows fairly complex time specifications, extending the POSIX.2 standard.  It accepts times
       of the form HH:MM to run a job at a specific time of day.

Your example worked. I was not putting the command inside a file. Isn't there a way to run the command from the command line?
This works:

at now + 1 minute -f testfile

This does not work:

at now + 1 minute echo "hello"

Offline

#10 2020-12-12 19:53:58

Head_on_a_Stick
Member
From: London
Registered: 2019-03-24
Posts: 3,125  
Website

Re: at program

fsmithred wrote:

I was referring to this part of the man page

Yes, it does seem to be somewhat contradictory, not sure why hmm

fsmithred wrote:

Isn't there a way to run the command from the command line?

If you run it without -f then it accepts input from STDIN:

$ at now + 1 minute        
warning: commands will be executed using /bin/sh
at> DISPLAY=:0 /usr/bin/x-terminal-emulator
at> <EOT>
job 11 at Sat Dec 12 19:52:00 2020
$

(<ctrl>+d exits the prompt.)

EDIT: or with a here string:

$ at now + 1 minute <<<'DISPLAY=:0 /usr/bin/x-terminal-emulator'
warning: commands will be executed using /bin/sh
job 13 at Sat Dec 12 19:58:00 2020
~$

A here document also works.

Last edited by Head_on_a_Stick (2020-12-12 19:59:34)


Brianna Ghey — Rest In Power

Offline

#11 2020-12-13 12:45:19

dice
Member
Registered: 2020-11-22
Posts: 559  
Website

Re: at program

Thanks for your help head on a stick, what do you think of below script? It works for me, sets the background in 1 minute increments x 3 using command functions in parallel. Im thinking if i put this in my autostart file (.xinitrc) with the correct time/date (today) it should suffice to emulate how the gnome backgrounds function for these wallpapers. The only issue i see is that the wallpapers wont load up if the "at" command is used in the past, it will fail and ill have a blank background. Ill have to figure out the time specifications better maybe.

#!/usr/bin/env bash

morning () {
        at now + 1 minute <<< 'DISPLAY=:0 feh --bg-scale /usr/share/backgrounds/gnome/adwaita-morning.jpg'
}

day () {
        at now + 2 minute <<< 'DISPLAY=:0 feh --bg-scale /usr/share/backgrounds/gnome/adwaita-day.jpg'
}

night () {
        at now + 3 minute <<< 'DISPLAY=:0 feh --bg-scale /usr/share/backgrounds/gnome/adwaita-night.jpg'
}

morning && day && night

Last edited by dice (2020-12-13 13:02:02)

Offline

#12 2020-12-14 19:16:11

Head_on_a_Stick
Member
From: London
Registered: 2019-03-24
Posts: 3,125  
Website

Re: at program

dice wrote:

what do you think of below script?

I don't think that will work because all three jobs will be run at the same time.

You could use a case statement to set the wallpaper according to the time and check every 10 minutes with a while loop:

#!/bin/sh

while true
do
   case $(date +%H) in
      [0-9]|1[0-1]) time=morning;;
      1[2-8]) time=day;;
      19|2[0-3]) time=night;;
   esac
   feh --bg-scale /usr/share/backgrounds/gnome/adwaita-$time.jpg
   sleep 600
done

No need for at at all big_smile

And to keep this post on topic I would recommend checking the POSIX specification for more details on the command:

https://pubs.opengroup.org/onlinepubs/9 … es/at.html

The "APPLICATION USAGE" section at the end is particularly useful.

EDIT: moved sleep inside the while loop so that the wallpaper is set immediately.

Last edited by Head_on_a_Stick (2020-12-15 16:31:41)


Brianna Ghey — Rest In Power

Offline

#13 2020-12-15 12:43:53

dice
Member
Registered: 2020-11-22
Posts: 559  
Website

Re: at program

Thats a good one head on a stick, no need for "at" at all indeed.

I tried to make something that wasnt in a while loop and have come up with the below, i would like to add in a 3rd command so it is 3 times of day (morn, day, night) but cant figure that out.

#!/usr/bin/env bash

DATE=$(date +%p)
DATE2=$(date +%p)
MORNING="AM"
NIGHT="PM"

if [[ "$DATE" == "$MORNING" ]] ; then
	feh --bg-scale /usr/share/backgrounds/gnome/adwaita-morning.jpg
elif [[ "$DATE2" == "$NIGHT" ]] ; then
        feh --bg-scale /usr/share/backgrounds/gnome/adwaita-night.jpg
fi

Last edited by dice (2020-12-15 12:50:41)

Offline

#14 2020-12-15 13:56:44

dice
Member
Registered: 2020-11-22
Posts: 559  
Website

Re: at program

Think i have figured it out without a while loop. This script should just set the background between the hours specified.

EDIT: oops no it wont. I could try and daemonize it but that would be similar to a while loop script i think?

#!/usr/bin/env bash
H=$(date +%H)
if (( 7 <= 10#$H && 10#$H < 13 )); then 
	feh --bg-scale /usr/share/backgrounds/gnome/adwaita-morning.jpg
    echo between 8AM and 1PM
elif (( 13 <= 10#$H && 10#$H < 19 )); then 
	feh --bg-scale /usr/share/backgrounds/gnome/adwaita-day.jpg
    echo between 1PM and 7PM
else
	feh --bg-scale /usr/share/backgrounds/gnome/adwaita-night.jpg
    echo night
fi

I give in, looks like a while loop is the way to go, below is a variant. Hoping this works...

#!/usr/bin/env bash

get_wall () {

H=$(date +%H)
if (( 7 <= 10#$H && 10#$H < 13 )); then 
	feh --bg-scale /usr/share/backgrounds/gnome/adwaita-morning.jpg
    echo between 8AM and 1PM
elif (( 13 <= 10#$H && 10#$H < 19 )); then 
	feh --bg-scale /usr/share/backgrounds/gnome/adwaita-day.jpg
    echo between 1PM and 7PM
else
	feh --bg-scale /usr/share/backgrounds/gnome/adwaita-night.jpg
    echo night
fi

}

while true; do
  get_wall;
  sleep 600;
done

Last edited by dice (2020-12-15 16:36:31)

Offline

#15 2020-12-15 16:34:48

Head_on_a_Stick
Member
From: London
Registered: 2019-03-24
Posts: 3,125  
Website

Re: at program

dice wrote:

I could try and daemonize it but that would be similar to a while loop script i think?

Not sure what you mean by "daemonize it" but as written the script only runs through once so it can't change the wallpaper unless it is run again at some point.

Why don't you like the while loop? It only runs three very simple shell commands & feh every ten minutes so it's not exactly resource heavy.


Brianna Ghey — Rest In Power

Offline

#16 2020-12-15 16:42:35

dice
Member
Registered: 2020-11-22
Posts: 559  
Website

Re: at program

Head_on_a_Stick wrote:
dice wrote:

I could try and daemonize it but that would be similar to a while loop script i think?

Not sure what you mean by "daemonize it" but as written the script only runs through once so it can't change the wallpaper unless it is run again at some point.

Why don't you like the while loop? It only runs three very simple shell commands & feh every ten minutes so it's not exactly resource heavy.

I was just trying to think outside the box, explore other ways if there are any.

By daemonize i mean create an init script. Start stop daemon if possible ?

Offline

#17 2020-12-15 16:44:56

Head_on_a_Stick
Member
From: London
Registered: 2019-03-24
Posts: 3,125  
Website

Re: at program

I don't think an init script would be appropriate for a per-user script running something in an X session. It is possible to run services just for one user and with the various permissions required for X with systemd but I don't know how to do that with other service managers.


Brianna Ghey — Rest In Power

Offline

#18 2020-12-15 16:53:04

dice
Member
Registered: 2020-11-22
Posts: 559  
Website

Re: at program

Head_on_a_Stick wrote:

I don't think an init script would be appropriate for a per-user script running something in an X session. It is possible to run services just for one user and with the various permissions required for X with systemd but I don't know how to do that with other service managers.

It is possible, i just need to figure it out.

https://unix.stackexchange.com/question … t-like-a-d

Offline

Board footer