[sudo-users] appending to /etc/hosts as a non root user using sudo

DBSMITH at OhioHealth.com DBSMITH at OhioHealth.com
Thu Jan 6 16:17:58 EST 2005


All, 

I was looking in the archives and found some data related to what I want 
to accomplish, but not quite.
It told me to : 

% sudo sh -c 'echo foo >> /var/log/bar'

With a sudoers entry like:

dude             somehost = /bin/sh -c /bin/echo foo >> /var/log/bar


but what I want is to append to /etc/hosts using sudo from with a script 
that holds variables. 
For example,

dev=172.25.123.123
loc=ISF
id=prt207

sudo echo $dev"\t"$id"\t""#" $loc >> /etc/hosts

but this is given me permission errors.
so then I tried:

sudo sh -c 'echo $dev"\t"$id"\t""#" $loc >> /etc/hosts'
with the line in my sudoers file  /usr/bin/sh -c

I am running 1.6.6
Any ideas?

thank you
Derek B. Smith
OhioHealth IT
UNIX / TSM / EDM Teams




More information about the sudo-users mailing list