Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

share|improve this question
add comment

3 Answers

up vote 2 down vote accepted

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.

share|improve this answer
    
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
1  
I think you can at least accept one answer. This will give you +2 rep :) –  Khaled Nov 15 '10 at 10:20
    
thanks I have now up voted. –  Treffynnon Nov 15 '10 at 10:21
add comment

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
share|improve this answer
    
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
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.