rlinuxat-job

Capture ID of At Command in R


Problem: I want to capture the id of the at command job

This is the normal code to execute the at command

> system(command="echo touch my_path/test_file.in | at 05:26 AM")

And this is the output

job 984 at 2015-12-11 05:26


Since I want to capture that id of the at command so I added the "intern" parameter of the system() function and save the id to a variable

> id<-system(command="echo touch my_path/test_file.in | at 05:26 AM", intern=TRUE)


Still the output was not captured so I tried the system2() function

> id<-system2(command="echo touch my_path/test_file.in | at 05:26 AM", stdout=TRUE, stderr=TRUE)


Still not working. Can someone help me with this?


Solution

  • system2() quotes the command so you probably want to use something like

    id <- system2(
          "sh",
          c("-c","echo touch my_path/test_file.in | at 05:26 AM"),
          stdout=TRUE, stderr=TRUE
         )
    

    Alternatively, you can stick to system() and re-direct stderr:

    id <- system("echo touch my_path/test_file.in | at 05:16 AM 2>&1", int=T)