File: basic-usage

package info (click to toggle)
at 3.2.5-2.2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 708 kB
  • sloc: sh: 3,139; ansic: 2,620; yacc: 578; makefile: 214; lex: 92; perl: 62
file content (61 lines) | stat: -rwxr-xr-x 1,504 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/bin/bash

#################################################
##                                             ##
## Basic usage of `at` to create a file and    ##
## also take in account the queue, using atq.  ##
##                                             ##
## Written by:                                 ##
## Utkarsh Gupta <utkarsh.gupta@canonical.com> ##
## License: GPL-2+                             ##
##                                             ##
#################################################

set -ex

TMPFILE=at.$RANDOM
WORKDIR=$(mktemp -d)
trap "rm -rf $WORKDIR" 0 INT QUIT ABRT PIPE TERM

JOBS_BEFORE=$(atq | wc -l)

# use at command to schedule a job.
echo "echo `date` > ${WORKDIR}/${TMPFILE}" | at now + 1 minute

sleep 2

# check if the file is created at the wrong
# time, that is, 58 seconds earlier.
if test -f "$TMPFILE"
then
  echo "$TMPFILE already exits but it really shouldn't."
  exit 1
else
  echo "OK, $TMPFILE doesn't exist yet; expected.."
fi

# check atq to see the queued jobs.
# there should be a one new job.
JOBS_AFTER=$(atq | wc -l)

if [[ $((JOBS_AFTER - JOBS_BEFORE)) -eq 1 ]]
then
  echo "OK, 1 new queued job exists.."
else
  echo "No new queued job found."
  exit 1
fi

sleep 60

# grep the content of the file to verify that
# everything is in order.
if grep -Fq "UTC" $WORKDIR/$TMPFILE
then
  echo "OK, $TMPFILE exists and everything looks in order.."
else
  echo "Either $TMPFILE doesn't exist or the content differs."
  exit 1
fi

echo "OK; PASS."