MLUG Bash Scripting Workshop 25/04/08
Prev Index Next

Testing for at jobs

I use an autogenerated script on the server for timeshifting digital televison and at for running the script at the correct time. The autogenerated script is overwritten each time another show is scheduled. I could schedule any number of shows in one sitting because these scripts are copied into /var/spool/atjobs and remain there until they have run.

I can use an if statement to test if there are any files in /var/spool/atjobs and then assign a variable just like I did with ping, if and IP numbers on the previous page.


if [ -e /var/spool/atjobs/* ] ; then
  TEST3=2
else
  TEST3=1
fi          

This snippet illustrates a different way to do a conditional test. The if statement in this snippet actually implies that it is testing a condition so test is not really required. When we were discussing the previous example and contovob we used test in order to get a variable ($?) which could again be "tested" in an if statement.

In this condition statement [ -e /var/spool/atjobs/* ] the -e stands for file exists and of course the regexp " * " means we are looking for any file. So if there is at least one file in /var/spool/atjobs, the variable TEST3 will equal 2, if there are no files then TEST3's value is 1.

As you can see test and if are rather handy to have around.


Top