I've got three SAS programs to run in the background over a weekend. The three programs output information into files of the same names, so I'll need to remove these output files after the first program finishes and before the second program starts, as well as after the second program finishes and before the third program starts. Obviously the simplest way to get around this issue is to alter each of the programs in such a way that the output filenames are different, but that wouldn't help me learn how to use Unix. So this is what I've got so far:# Begin by running the first SAS program in the background.sas program1.sas & | at 5:00 PM JAN 11# I'd like to wait until the first program finishes to remove# the output files and run the second program.wait ???rm file1.sas7bdat file2.sas7bdat file3.sas7bdat file4.sas7bdat file5.sas7bdatsas program2.sas & | at 5:00 PM JAN 12# And now I repeat.wait ???rm file1.sas7bdat file2.sas7bdat file3.sas7bdat file4.sas7bdat file5.sas7bdatsas program3.sas & | at 5:00 PM JAN 13I set each program to run at the same time on consecutive days for two reasons: (1) I know the previous program will finish within 24 hours, and (2) I am assuming the load on the server will be similar at the same time on consecutive days. Ideally I could somehow grab the process ID for the first program and pass it to the first wait command, and similarly for the second program and wait command. Any ideas?EDITI am more interested in a general solution for determining a process ID and passing it to the wait command than this specific situation.
scheduling background tasks in succession
scheduling
The problem is you're using at for something its not supposed to be used for, really. You also have two conflicting goals: run program 2 after program 1 and run program 2 at 5pm jan 12.One part of your problem is simple to solve: at allows multiple commands. So, instead of just using at to schedule the sas script, you can put the rm in the job as well.at 5:00 PM JAN 11 <<EOJsas program1.sasrm file1.sas7bdat file2.sas7bdat file3.sas7bdat file4.sas7bdat file5.sas7bdatEOJThere is no reason for the & in the sas line; at always runs jobs in the background. Next, you must figure how you want to solve the conflict mentioned earlier. In particular, if the Jan. 11 job hasn't finished 24 hours later (by 5pm Jan. 12). There are a couple of ways to go about it:It isn't really the Jan 12 job. It should run as soon as program1.sas finishes. In which case, just make it part of the first job above, just like the rm.This will never happen. If it does, you'll fix it manually. In which case, just schedule it like the one above.It needs to wait. In which case, you could either schedule it at the end of the first at job, or use a lock file, or calculate the appropriate amount of time to sleep (or use sleepenh, if available, to avoid doing the calculation yourself).