Highlighted
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

0 Kudos
4 Replies
Highlighted
Hot Shot
Hot Shot

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.

0 Kudos
Highlighted
Hot Shot
Hot Shot

0 Kudos
Highlighted
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

0 Kudos
Highlighted
Hot Shot
Hot Shot

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

0 Kudos