1

I have written a small PHP script to wrap the at command on Ubuntu. Now I need to get the same code running on a Redhat server. Of course the output when adding and listing jobs is of course different.

Ubuntu (at -V = 3.1.11): job 4 at Fri Nov 12 13:41:00 2010

Redhat (at -V = 3.1.8): job 14 at 2010-11-12 13:42

Is there some way I can modify the output of the at command to make it more uniform? I have read man at and I cannot see anything there but perhaps I have missed some sneaky shortcut.

I am using regex to "read" the output so I could update that to support the Redhat format, but then what happens if the same is run on a different distro.

Treffynnon
  • 249
  • 4
  • 12

3 Answers3

2

I can see that the strings differ in the date/time format. You can split the output into two substrings (job 4 at), and the date/time part. Then, you can parse the date using the function strtotime.

At the end, you can combine the first part with the parsed date/time. So, you get a uniform ouput. Also, you can convert the date/time part to the desired format.

Khaled
  • 35,688
  • 8
  • 69
  • 98
  • I can't up vote answers yet as I do not have enough rep on ServerFault but thank you for your answer. It has changed my thinking and I will approach the problem in two parts as you suggest. I was just using one big regex. – Treffynnon Nov 15 '10 at 10:14
2

You can normalize the dates using something like:

date -d "$date" --rfc-3339=seconds

I was going to suggest the following, but at seems to ignore locale environment variables:

LC_TIME=C at -v ...   # has no effect
Dennis Williamson
  • 60,515
  • 14
  • 113
  • 148
  • I can't up vote answers yet as I do not have enough rep on ServerFault but thank you for your answer. The locale environment variables is a nice tip and I will remember it for next time. Your reference to `date` works just great. – Treffynnon Nov 15 '10 at 10:17
0

I have discovered that using at with the -v flag gives the same date output format on both Ubuntu and Redhat. But the output looks like the following:

Ubuntu

Fri Nov 12 13:41:00 2010

warning: commands will be executed using /bin/sh
job 4 at Fri Nov 12 13:41:00 2010

Redhat

Fri Nov 12 13:42:00 2010

job 14 at 2010-11-12 13:42

This will allow me to get the date from the first line and then the job number from the last line.

Which is fine when adding jobs, but when listing jobs in the queue -v will not work and the date format there will still be different. Think it might be time for a different queue software.

Treffynnon
  • 249
  • 4
  • 12