Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back > Forums > Linux Forums > Linux - General
User Name
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.


  Search this Thread
Old 05-31-2007, 10:59 AM   #1
Registered: Apr 2005
Location: At the 100th Meridian where the great plains begin
Distribution: Debian Testing on T60 laptop
Posts: 105

Rep: Reputation: 16
ambiguous redirect when running a script in /root/bin with sudo as normal user

I have a simple script /root/bin/mupdt
which contains the following:


#This script will print the date plus a comment
#to the file called $MAINT_FILE.
echo "" >> $MAINT_FILE
echo "[$(date +%d)$(date +%b)$(date +%y) $(date +%H:%M:%S)]  $1" >> $MAINT_FILE
I have the following environment variable declared:
me@mycomputer:~$ env | grep MAINT_FILE
I've tried to run this script from my non-root account by typing:
me@mycomputer:~$ sudo /root/bin/mupdt "this is a test"
but I get the error:
/root/bin/mupdt: line 6: $MAINT_FILE: ambiguous redirect
/root/bin/mupdt: line 7: $MAINT_FILE: ambiguous redirect
If I run the script as root there's no problem:
root@mycomputer# /root/bin/mupdt "this is a test"
root@mycomputer# cat $MAINT_FILE | tail -n 1
[31May07 04:53:23]  this is a test
What is it that becomes ambiguous when I run it as a normal user? How can I make it so that it's no longer ambiguous?
Old 05-31-2007, 08:23 PM   #2
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
That's because the user root (when invoked via sudo) doesn't get
the environment variables from your users session?

Old 06-01-2007, 09:57 AM   #3
Registered: Apr 2005
Location: At the 100th Meridian where the great plains begin
Distribution: Debian Testing on T60 laptop
Posts: 105

Original Poster
Rep: Reputation: 16
Makes sense. I guess you have to pass it as a parameter instead.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
SuSE93 Root password rejected from normal user mode (No Sudo, No YaST) Peacepunk SUSE / openSUSE 2 02-11-2007 06:34 PM
Running a script as root with sudo without entering the user password kloss Linux - General 8 10-10-2005 11:39 AM
allow sudo for www user to run root shell script cccc *BSD 12 07-23-2005 03:48 PM
Ambiguous output redirect XFox Linux - Newbie 5 10-17-2003 07:29 PM
ambiguous redirect? cuss Linux - General 4 03-06-2003 10:58 AM

All times are GMT -5. The time now is 07:05 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration