I was working in a data center, building out an Arista network, when I decided that I wanted to automate a command that should run every five minutes. Knowing that these super cool Arista switches run Linux, I dropped into bash and proceeded to muck around with cron. I couldn’t get it to work, got frustrated, and called my Arista sales engineer who asked, “Why not just use schedule?”
Schedule is a feature introduced in EOS 4.8 that allows the regular scheduling of commands. The cool part of this feature is that it’s completely configured from CLI. Let’s take a look at this powerful tool.
The schedule
command is the root of just about
everything we’re going to do in this chapter. It’s simple to use, and the
question mark along with tab completion will get you most of what you want
to know about its function:
Arista(config)#schedule ?
WORD Scheduled job name
To create a scheduled job, you must first specify a name for the job. Since I’m the writer, I’ll use the name GAD for my job:
Arista(config)#schedule GAD ?
interval Set interval for CLI command execution
The interval is the amount of time in minutes to wait between each iteration of the job. If you want the job to run every five minutes, the interval would be five. In version 4.9.3, acceptable values range from 1 to 1,440:
Arista(config)#schedule GAD interval ?
<1-1440> Interval in minutes for CLI command execution
The next thing I need to specify is the maximum number of
logfiles that will be retained. Every time my job runs, it will create
output. That output is saved to a logfile that we’ll see in a bit. If the
job runs every minute, for the next year, the job would produce a
half-million log entries. Chances are, I’d only want to see the last 100 or
so, so I’ll specify max-log-files 100
,
after which the switch will only save the last 100 log entries. The range of
acceptable values is inclusive from 1 to 10,000:
Arista(config)#schedule GAD interval 5 max-log-files ?
<1-10000> Number of logfiles to be stored
Finally, we must include the word command
, followed by the command to be run:
Arista(config)#schedule GAD interval 5 max-log-files 100 command
sho int e24
Arista(config)#
Note that the parser does not check the validity of the commands
entered with the schedule
command. The command schedule mistake int 1 max 10 command ILikeCake
will be accepted without complaint, but the job will never run, and you’ll
never see an error message, or get any cake. If you see No log
files are stored in flash when you show the job, check to see
if your command is entered correctly. There is no indication as to whether
the cake is a lie, so don’t bother asking.
With the job now entered, nothing obvious happens. That’s pretty
anticlimactic, but rest assured that good things are happening (assuming you
entered a valid command). To see what jobs have been scheduled on the
switch, use the show schedule summary
command. Note that the word summary must be spelled in its entirety, lest it
be confused with the name of a scheduled job:
Arista#sho schedule summary
Name Last Interval Max Log file location
time (mins) log
files
--------------- ------ ---------- ------- ----------------------------
gad 18:14 5 100 flash:/schedule/gad
tech-support 18:07 60 100 flash:/schedule/tech-support
Schedules may be entered with capital letters, but the parser will convert them to all lowercase. For a writer who expects to see his initials in all caps, this is frustrating, but generally harmless.
To see the specifics of a scheduled job, use the show schedule
job-name
command. This will show the command scheduled, the details of the schedule
limitations as configured, and information regarding the logfiles generated
as a result of this job. As we can see in this example, my job has run three
times:
Arista(config)#sho schedule gad
CLI command "sho int e24" is scheduled, interval is 5 minutes
Maximum of 100 log files will be stored
3 log files currently stored in flash:/schedule/gad
Start time Size Filename
----------------------- ----------------- --------------------------
May 16 2012 18:14 403.0 bytes gad_2012-05-16.1814.log.gz
May 16 2012 17:49 608.0 bytes gad_2012-05-16.1749.log.gz
May 16 2012 17:49 608.0 bytes gad_2012-05-16.1749.log.gz
Remember how I said that getting my initials converted to lowercase
was mostly harmless? Here’s why I used the word, “mostly.” If I decide to
delete my job, I would do so with the no
schedule
job-name
command; only, when I
use my initials in all caps, like I do by habit, the command is taken but
nothing happens:
Arista(config)#no schedule GAD
Arista(config)#
When I use show schedule summary
to make sure my job is
gone, it’s still there!
Arista(config)#sho schedule summary
Name Last Interval Max Log file location
time (mins) log
files
--------------- ------ ---------- ------- ----------------------------
gad 18:14 5 100 flash:/schedule/gad
tech-support 18:07 60 100 flash:/schedule/tech-support
I have to delete it using all lowercase letters. I hate having to conform, but I’ve chosen to let these types of battles go at the recommendation of my therapist:
Arista(config)#no schedule gad
Arista(config)# Arista(config)#sho schedule summary
Name Last Interval Max Log file location time (mins) log files --------------- ------ ---------- ------- ---------------------------- tech-support 18:07 60 100 flash:/schedule/tech-support
When you delete a scheduled job, the logfiles remain. Since these logfiles are on flash, they persist after a reboot.
By the way, if you’re the type who needs to try and create a job
entitled summary because summary
is a reserved word, let me save you the
trouble and show you what happens. First, I’ll create the job:
Arista(config)#schedule summary int 5 max 1 command sho int e1
The switch takes this command without complaint. The problem is, there
is no way for me to see the detail of my job! When I issue the show schedule summary
command, I get a summary
list of all jobs:
Arista(config)#sho schedule summary
Name Last Interval Max Log file location
time (mins) log
files
--------------- ------ ---------- ------- -------------------------
summary 18:17 5 100 flash:/schedule/summary
tech-support 18:07 60 100 flash:/schedule/tech-support
Luckily, I can delete it with ease.
Arista(config)#no schedule summary
You may have noticed that there is a job in each example named
tech-support. This job is installed by Arista, and runs
on all switches by default. Though it can be removed, there’s generally no
reason to do so. I’m sure you’re as curious as I was to see what this job is
doing, so let’s take a look, because it’s an excellent example of how
schedule
can be used.
First, let’s use the show schedule
tech-support
command:
Arista(config)#sho schedule tech-support
CLI command "show tech-support" is scheduled, interval is 60 minutes
Maximum of 100 log files will be stored
100 log files currently stored in flash:/schedule/tech-support
Start time Size Filename
----------------------- ---------- -----------------------------------
May 16 2012 18:07 17.9 KB tech-support_2012-05-16.1807.log.gz
May 16 2012 16:50 17.7 KB tech-support_2012-05-16.1650.log.gz
May 16 2012 15:50 17.7 KB tech-support_2012-05-16.1550.log.gz
May 16 2012 14:50 17.8 KB tech-support_2012-05-16.1450.log.gz
May 16 2012 13:50 17.7 KB tech-support_2012-05-16.1350.log.gz
[--- output truncated ---]
As we can see in the second line, this scheduled job performs a
show tech-support
command once every
hour. Take a look at the output of the third line down (in bold). It says
that there are 100 logfiles currently stored in
flash:/schedule/tech-support. It then goes on to list
them. So how can we see what’s in these logfiles? With bash
, of course.
To see the logfiles, drop into bash and change directories to the /mnt/flash/schedule directory:
Arista#bash
Arista Networks EOS shell [admin@Arista flash]$cd /mnt/flash/schedule
[admin@Arista schedule]$
Within this directory, you’ll find a directory for every schedule job that’s ever run:
[admin@Arista schedule]$ ls -al
total 36
drwxrwx--- 6 root eosadmin 4096 May 16 18:18 .
drwxrwx--- 6 root eosadmin 4096 Dec 31 1969 ..
drwxrwx--- 2 root eosadmin 4096 May 16 18:25 gad
drwxrwx--- 2 root eosadmin 4096 May 16 12:14 gad2
drwxrwx--- 2 root eosadmin 4096 May 16 18:28 summary
drwxrwx--- 2 root eosadmin 16384 May 16 18:07 tech-support
We can see that there’s a directory for my gad job, another for gad2, one for our summary test, and one for the tech-support job. Changing into the tech-support directory will let us see the logs for the tech-support job:
[admin@Arista tech-support]$ ls
tech-support_2012-05-12.1954.log.gz
tech-support_2012-05-14.1850.log.gz
tech-support_2012-05-12.2009.log.gz
tech-support_2012-05-14.1904.log.gz
tech-support_2012-05-12.2050.log.gz
tech-support_2012-05-14.1950.log.gz
tech-support_2012-05-12.2150.log.gz
tech-support_2012-05-14.2034.log.gz
tech-support_2012-05-12.2250.log.gz
tech-support_2012-05-14.2050.log.gz
tech-support_2012-05-12.2350.log.gz
[--- output truncated ---]
Since the tech-support job is configured to keep the last 100 log
entries, there are 100 files in this directory, each with the date and
timestamp in the filename. The files are all in the
gzip format. To view them, use the zcat
Linux command from bash. You can also use
gunzip
, but that will expand the file on
disk, which is a waste of space when we just want to look at the contents
for no other reason than to see what’s there:
[admin@Arista tech-support]$ zcat tech-support_2012-05-12.1954.log.gz
------------- show version detail -------------
Arista DCS-7124S-F
Hardware version: 06.02
Deviations: D0000213, D0000203
Serial number: JSH10170315
System MAC address: 001c.7308.80ae
Software image version: 4.8.1
Architecture: i386
Internal build version: 4.8.1-495947.2011eric481Showstopper
Internal build ID: b15379fb-13e9-4255-819f-e55dde3c3471
Uptime: 5 minutes
Total memory: 2043424 kB
Free memory: 896408 kB
Installed software packages:
[--- output truncated ---]
The switch has done a show tech-support
command
every hour since the switch booted.
There are 100 files in this directory, which represents the state of the
switch in hourly intervals for the past 100 hours. That’s 4.166 days for the
mathematically challenged. Had a problem yesterday and want to see the
status of the switch? It was saved in these files. Think that’s cool and
would like to see it save the last 1,000 hours? Just go in and resubmit the
tech-support job the way you’d like.
Schedule is cool and all, but what if you want to run more than one
command? Not only can the schedule
command run CLI
commands, but it can run bash commands through the use of the bash
CLI command. Here I’ve created a script in
/mnt/flash called GAD
. I used all
caps because it makes me feel like I’ve won my earlier battle and to show
that caps can be used as a reference in the command, even if they can’t be
used in the schedule job name.
The file looks like this:
[admin@Arista flash]$ cat GAD
#!/usr/bin/Cli
sho ver | grep version | email -s "Show Version" [email protected]
sho int e24 | email -s "Show int e24" [email protected]
See Chapter 19 for details on configuring and
using the email
command.
Next, back in EOS, I’ll create the schedule that calls this script:
Arista(config)#schedule dog int 1 max 10 command bash /mnt/flash/GAD
And now, every minute, I get two emails showing the requested output. Trust me when I say that this gets old quickly:
+ N 2665 May 16 7:16pm [email protected] (943) Show Version + N 2666 May 16 7:16pm [email protected] (2K) Show int e24 + N 2667 May 16 7:17pm [email protected] (943) Show Version + N 2668 May 16 7:17pm [email protected] (2K) Show int e24 + N 2669 May 16 7:18pm [email protected] (943) Show Version + N 2670 May 16 7:18pm [email protected] (2K) Show int e24
Imagine that you’re having a problem, and you’d like to see what the
running processes are on your switch every five minutes. Maybe you’re
convinced that you’ve got a runaway process on your switch and you want to see for yourself. The
Linux command ps-ef
r
will show the running processes:
[admin@Arista ~]$ ps -ef r
UID PID PPID C STIME TTY STAT TIME CMD
root 1454 1453 3 18:02 ? R 2:42 Sysdb
root 1827 1453 6 18:03 ? R 4:54 Mdio
admin 4058 3923 13 19:24 pts/2 R+ 0:00 ps -ef r
I can schedule a job to email me that information every five minutes.
The schedule
command I would use would
look like this:
Arista(config)#schedule proc interval 5 max-log-files 1 command bash
ps -ef r | email -s "Running Procs" [email protected]
There in my email, every five minutes, is a list of the running processes on my switch:
Date: Wed, 16 May 2012 19:27:35 From: [email protected] To: [email protected] Subject: Running Procs UID PID PPID C STIME TTY STAT TIME CMD root 4143 4142 14 19:27 ? R 0:00 ps -ef r root 4144 4142 15 19:27 ? R 0:00 python /usr/bin/ email -s Running Procs [email protected]
3.12.71.26