LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
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.

Notices


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

Rep: Reputation: 17
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:

Code:
#!/bin/bash

#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:
Code:
me@mycomputer:~$ env | grep MAINT_FILE
MAINT_FILE=/root/maintenance/maintenance.log
I've tried to run this script from my non-root account by typing:
Code:
me@mycomputer:~$ sudo /root/bin/mupdt "this is a test"
but I get the error:
Code:
/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:
Code:
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
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

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


Cheers,
Tink
 
Old 06-01-2007, 09:57 AM   #3
chadwick
Member
 
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: 17
Makes sense. I guess you have to pass it as a parameter instead.
 
  


Reply



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

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 02:20 PM.

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