Debian Codegraph @

debian/tests/basic-usage

raw
1 #!/bin/bash
2
3 #################################################
4 ## ##
5 ## Basic usage of `at` to create a file and ##
6 ## also take in account the queue, using atq. ##
7 ## ##
8 ## Written by: ##
9 ## Utkarsh Gupta <[email protected]> ##
10 ## License: GPL-2+ ##
11 ## ##
12 #################################################
13
14 set -ex
15
16 TMPFILE=at.$RANDOM
17 WORKDIR=$(mktemp -d)
18 trap "rm -rf $WORKDIR" 0 INT QUIT ABRT PIPE TERM
19
20 JOBS_BEFORE=$(atq | wc -l)
21
22 # use at command to schedule a job.
23 echo "echo `date` > ${WORKDIR}/${TMPFILE}" | at now + 1 minute
24
25 sleep 2
26
27 # check if the file is created at the wrong
28 # time, that is, 58 seconds earlier.
29 if test -f "$TMPFILE"
30 then
31 echo "$TMPFILE already exits but it really shouldn't."
32 exit 1
33 else
34 echo "OK, $TMPFILE doesn't exist yet; expected.."
35 fi
36
37 # check atq to see the queued jobs.
38 # there should be a one new job.
39 JOBS_AFTER=$(atq | wc -l)
40
41 if [[ $((JOBS_AFTER - JOBS_BEFORE)) -eq 1 ]]
42 then
43 echo "OK, 1 new queued job exists.."
44 else
45 echo "No new queued job found."
46 exit 1
47 fi
48
49 sleep 60
50
51 # grep the content of the file to verify that
52 # everything is in order.
53 if grep -Fq "UTC" $WORKDIR/$TMPFILE
54 then
55 echo "OK, $TMPFILE exists and everything looks in order.."
56 else
57 echo "Either $TMPFILE doesn't exist or the content differs."
58 exit 1
59 fi
60
61 echo "OK; PASS."