VMware Modern Apps Community
INSASBGDSIN
Contributor
Contributor

schedule command execution (once)

Hi,

I was not able to find the "at" command in PhotonOS.

Is there another similar tool available or is it located in a specific repository ?

Regards

Reply
0 Kudos
6 Replies
DCasota
Expert
Expert

To schedule a bash file to automatically run once eg. after a reboot, you could use this, see https://vmware.github.io/photon/assets/files/html/3.0/photon_admin/creating-a-startup-service.html.

Generally, you must create a service file in which you declare what has to be done as "at" one. In the following sample it is simply a bash file which is configured to run once.

# --- 1) create a bash file with content as preparation for the service (see 2). The last part in the bash file direclty disables and unlinks the service.

BASHFILE="/root/mysample.sh"

cat > $BASHFILE <<'EOF'

#!/bin/sh

# INSERT YOUR CODE

systemctl disable mysample.service

rm /lib/systemd/system/multi-user.target.wants/mysample.service

unlink /lib/systemd/system/mysample.service

EOF

# --- 2) make the bash file executable and create the service file. The type of [Service] is configured to 'oneshot'. The Unit dependencies 'after' and 'wants' - in this case- it has a environment dependency to a service called waagent.service. This is optional.

chmod a+x $BASHFILE

cat << EOF1 >> /lib/systemd/system/mysample.service

[Unit]

Description=Run a bash file

After=waagent.service

Wants=waagent.service

[Service]

ExecStart=$BASHFILE

Type=oneshot

[Install]

WantedBy=multi-user.target

EOF1

cd /lib/systemd/system/multi-user.target.wants/

ln -s ../mysample.service mysample.service

# --- 3) 'ln -s' together with the service file allows to simply use the created service within systemctl.

Hope this helps.

Reply
0 Kudos
DCasota
Expert
Expert

Reply
0 Kudos
INSASBGDSIN
Contributor
Contributor

Thanks for your answer.

It is not a convenient solution, as I would like to be able to run a background task without any shell at a desired time and on demand. So no need to configure a cron and forget to unset it for a single-shot maintenance script which must be run in a middle of the night to solve a problem (my typical recurring need).

If the "at" command is definitely unavailable in Photon OS, I am quite surprised as it is very common in the Linux world and not fancy !

Regards

Reply
0 Kudos
DCasota
Expert
Expert

@INSASBGDSIN Photon supports several flavors generic, linux-esx, aws,.You could place your question on Issues · vmware/photon · GitHub why the scheduling algorithm of at_irq.c (?) didn't made it to be kept as one of the affordable scheduling methods. cron is a supported old fallback within systemd though.

Reply
0 Kudos
freslona
VMware Employee
VMware Employee

I use "at" in photonOS to schedule a task to send emails, "at" isn't in photon's repo and so I had to compile it myself, you might want to do the same ... be sure to create a service file as well !

Reply
0 Kudos
JonasMR
Enthusiast
Enthusiast

Hi @INSASBGDSIN 

 

you can install at command, on photon OS 3.0:

yum install wget
wget http://rpmfind.net/linux/mageia/distrib/6/x86_64/media/core/release/at-3.1.20-1.mga6.x86_64.rpm
rpm -ivh --nodeps at-3.1.20-1.mga6.x86_64.rpm
systemctl enable atd
systemctl start atd

best regards

 

Reply
0 Kudos