A PHP wrapper for the unix at command
A project I am working on at the moment requires time delayed job queues and having found nothing yet that can manage it properly so I decided to wrap up `at` into a PHP class. This gives you simple methods to add, list and remove jobs from the `at` queue using object oriented code.
The code is very simple and I have documented it reasonably well so along with the examples you should get on your way quickly. The class can, of course, be used from the command line as well so if you want to write batch scripts in PHP to handle adding a collection of predefined `at` jobs for example - it can make it easier.
I feel the important features of `at` have been added into the code, but if you want to wrap any of the other functions then please do fork my code and make a patch or post a pull request. For more information on what `at` can do please either run `man at` in your console or visit the Edinburgh University’s man at page.
You can get the code from my repository on GitHub: PHP-at-Job-Queue-Wrapper.
If you do have any trouble getting the `at` daemon (atd) going then my previous post may help you debug it - please see If you are having problems getting Ubuntu atd running for more on that.
Sometimes you will want to batch remove extensions from a load of files:
for i in $(ls *.png); do mv $i ${i%.png}; done
If you want to remove extensions from files with a .txt extension then you would replace the two instances of .png in the script above with .txt.
You can take the extension off of all files using the following:
for i in $(ls *.*); do mv $i ${i%.*}; done
I also extended it by using it for a batch change of extensions rather than just removing the extension:
for i in $(ls *.html); do mv $i ${i%.html}.htm; done
Note the extra .htm after the curly braces in the above command.
If you are having problems getting Ubuntu atd running
If you just cannot get atd to start running check the permissions on your /var/spool/cron/atjobs and /var/spool/cron/atspool directories. The should be `chmod 770` and then `chmod +t`. Also they should be owned by `daemon:daemon`.
I was getting this error when attempting to set new at jobs:
Can’t open /var/run/atd.pid to signal atd. No atd running?
If I tried to start the daemon through the service management I was getting:
sudo service atd start
start: Job is already running: atd
But running `ps -elf | grep ‘atd’` yielded no appropriate results.
When trying to start the atd daemon manually on the command line I was getting:
simon@forge:~$ sudo atd -d
Cannot change to /var/spool/cron/atjobs: Permission denied
Which finally gave me the clue!
A nice modern take on the original Stratos by Pininfarina set to be sent into production. Thankfully they preserved original rear end lights and lip spoiler. Not so sure about the headlights.
hotvvheels:
Stratos