Discussion:
[rancid] Issues running rancid from cron on Ubuntu..
Howard Leadmon
2016-06-16 17:33:00 UTC
Permalink
Maybe this will be an easy one for someone to answer, I can hope. I had
rancid for years running on FBSD, but recently moved over on to a current
Ubuntu server. I moved my configs across, and have it so if from a shell
prompt I perform a rancid-run life is good, it's seeing all the gear, and
saving cofigs, and emailing updates to me.



The problem is when I toss rancid-run into cron, it spits errors and will
not read the configs. So it's for sure an issue of this being kicked into
cron, but using google-fu I am finding nothing. I even tried not calling
the symlink but calling the main executable directly, but still no
difference.



Here is the error I see in the rancid.log file if I let this execute from
cron:





starting: Thu Jun 16 12:31:02 EDT 2016



Trying to get all of the configs.

no such variable

(read trace on "env(USER)")

invoked from within

"add user * $env(USER)"

("eval" body line 1)

invoked from within

"eval $line"

(procedure "source_password_file" line 21)

invoked from within

"source_password_file $password_file"

(file "/usr/lib/rancid/bin/clogin" line 853)no such variable

(read trace on "env(USER)")

invoked from within

"add user * $env(USER)"

("eval" body line 1)

invoked from within

"eval $line"

(procedure "source_password_file" line 21)

invoked from within

"source_password_file $password_file"

(file "/usr/lib/rancid/bin/clogin" line 853)



switch-1: missed cmd(s): all commands

switch-1: End of run not found

!





This ONLY happens when I execute from cron, if done locally in a shell, all
works perfectly.



In crontab, I simply have the time and path to rancid-run.



Any ideas?





---

Howard Leadmon
Alan McKinnon
2016-06-16 17:48:13 UTC
Permalink
Post by Howard Leadmon
Maybe this will be an easy one for someone to answer, I can hope. I
had rancid for years running on FBSD, but recently moved over on to a
current Ubuntu server. I moved my configs across, and have it so if
from a shell prompt I perform a rancid-run life is good, it’s seeing all
the gear, and saving cofigs, and emailing updates to me.
The problem is when I toss rancid-run into cron, it spits errors and
will not read the configs. So it’s for sure an issue of this being
kicked into cron, but using google-fu I am finding nothing. I even
tried not calling the symlink but calling the main executable directly,
but still no difference.
Here is the error I see in the rancid.log file if I let this execute
starting: Thu Jun 16 12:31:02 EDT 2016
Trying to get all of the configs.
no such variable
(read trace on "env(USER)")
invoked from within
"add user * $env(USER)"
("eval" body line 1)
invoked from within
"eval $line"
(procedure "source_password_file" line 21)
invoked from within
"source_password_file $password_file"
(file "/usr/lib/rancid/bin/clogin" line 853)no such variable
(read trace on "env(USER)")
invoked from within
"add user * $env(USER)"
("eval" body line 1)
invoked from within
"eval $line"
(procedure "source_password_file" line 21)
invoked from within
"source_password_file $password_file"
(file "/usr/lib/rancid/bin/clogin" line 853)
switch-1: missed cmd(s): all commands
switch-1: End of run not found
!
This ONLY happens when I execute from cron, if done locally in a shell,
all works perfectly.
In crontab, I simply have the time and path to rancid-run.
Any ideas?
There's usually only one thing that every causes this - the shell
environment. A login shell comes with all manner of convenient envvars
like PATH that make a human's life easier.

cron usually runs in a bare-bones shell with very little in the way of
an environment (by design) meaning you can't rely on user shortcuts like
PATH.

Or it could be as simple as cron doesn't use the same shell you do.

You'll have to examine your system with this in mind and see where
things differ. It's difficult to get more specific than that at this
stage given the information available.

Alan
Howard Leadmon
2016-06-16 19:14:13 UTC
Permalink
FYI, I did get it sorted out, but strange more haven't run into this unless
my environment is screwy for some reason.

I had to set the USER name in the environment. I looked at the
environment, and saw LOGNAME=rancid, but that I didn't see USER= rancid.
So in the crontab I set USER=rancid, and off everything went..


---
Howard Leadmon
heasley
2016-06-16 21:36:11 UTC
Permalink
Post by Howard Leadmon
FYI, I did get it sorted out, but strange more haven't run into this unless
my environment is screwy for some reason.
I had to set the USER name in the environment. I looked at the
environment, and saw LOGNAME=rancid, but that I didn't see USER= rancid.
So in the crontab I set USER=rancid, and off everything went..
grumble. double middle finger to ubuntu. i'll make it look for both
variables.
heasley
2016-06-16 22:19:19 UTC
Permalink
Post by Howard Leadmon
FYI, I did get it sorted out, but strange more haven't run into this unless
my environment is screwy for some reason.
I had to set the USER name in the environment. I looked at the
environment, and saw LOGNAME=rancid, but that I didn't see USER= rancid.
So in the crontab I set USER=rancid, and off everything went..
this will help. not all of the login scripts use this file yet, but it can
be applied to the others.

Index: bin/login_top.in
===================================================================
--- bin/login_top.in (revision 3410)
+++ bin/login_top.in (revision 3412)
@@ -2,13 +2,22 @@
# x == do not set xterm banner or name

# Find the user in the ENV, or use the unix userid.
-if {[info exists env(CISCO_USER)]} {
- set default_user $env(CISCO_USER)
-} elseif {[info exists env(USER)]} {
- set default_user $env(USER)
-} elseif {[info exists env(LOGNAME)]} {
- set default_user $env(LOGNAME)
-} else {
+if {![info exists default_user] && [info exists env(CISCO_USER)]} {
+ if {[string length $env(CISCO_USER)]} {
+ set default_user $env(CISCO_USER)
+ }
+}
+if {![info exists default_user] && [info exists env(USER)]} {
+ if {[string length $env(USER)]} {
+ set default_user $env(USER)
+ }
+}
+if {![info exists default_user] && [info exists env(LOGNAME)]} {
+ if {[string length $env(LOGNAME)]} {
+ set default_user $env(LOGNAME)
+ }
+}
+if (![info exists default_user]) {
# This uses "id" which I think is portable. At least it has existed
# (without options) on all machines/OSes I've been on recently -
# unlike whoami or id -nu.

Loading...