Variable not an identifier when script is run as another user | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Variable not an identifier when script is run as another user

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 11-29-2012
newbie2010 newbie2010 is offline
Registered User
 
Join Date: Nov 2012
Last Activity: 4 April 2014, 10:01 AM EDT
Posts: 131
Thanks: 51
Thanked 12 Times in 2 Posts
Variable not an identifier when script is run as another user

I am new to scripting

I keep getting the error var2= is not an identifier when I run this script as another user. BUT when I run it as myself, the script completes without error. Any idea why? I assume it is because the new user has a different environment . How do I make the variables active for this new user? I don't have setenv and I've already exported them. As I said, the script works fine until i run it after logging in and running su - newuser to change to the newuser. I wish I could fix this so the newuser could also run the script.


Code:
echo "enter filername" 
read filername 
echo "enter days ago" 
read daysago 
command=`/px/finderquery -client=$filername -days=$daysago`; 
export var2=`echo $command`; 
if [[ `echo $var2 |grep show` ]]; 
then 
     echo "filer does not exist"; 
else 
     echo "you have the right name";
fi; 
export new2=`echo $var2 |gawk '{print $31}'`

Any ideas would be helpful to a newbie, thanks!

Last edited by vbe; 11-29-2012 at 11:26 AM.. Reason: You insert your code in between the code tags! I revamped you code for reading...
Sponsored Links
    #2  
Old 11-29-2012
vbe's Avatar
vbe vbe is offline Forum Staff  
Moderator
 
Join Date: Sep 2005
Last Activity: 17 April 2014, 3:54 AM EDT
Location: Switzerland - GE
Posts: 5,490
Thanks: 148
Thanked 362 Times in 339 Posts
What shell are you using?
Sponsored Links
    #3  
Old 11-29-2012
vbe's Avatar
vbe vbe is offline Forum Staff  
Moderator
 
Join Date: Sep 2005
Last Activity: 17 April 2014, 3:54 AM EDT
Location: Switzerland - GE
Posts: 5,490
Thanks: 148
Thanked 362 Times in 339 Posts
I wonder if it is not a shell issue... Since in your code there is no shell, it will use your default, I suppose yours is a bash ( looking at your syntax...) it may not be true for your other user... otherwise it has to be something with your environment...
    #4  
Old 11-29-2012
newbie2010 newbie2010 is offline
Registered User
 
Join Date: Nov 2012
Last Activity: 4 April 2014, 10:01 AM EDT
Posts: 131
Thanks: 51
Thanked 12 Times in 2 Posts
duh... I should have told you I was using bash shell!
Sponsored Links
    #5  
Old 11-29-2012
vbe's Avatar
vbe vbe is offline Forum Staff  
Moderator
 
Join Date: Sep 2005
Last Activity: 17 April 2014, 3:54 AM EDT
Location: Switzerland - GE
Posts: 5,490
Thanks: 148
Thanked 362 Times in 339 Posts
try puttinf as first line of your script:

Code:
#!/bin/bash

and see if it changes anything...( I suppose you made the script executable...) I cant do more, I dont use bash...
Sponsored Links
    #6  
Old 11-29-2012
newbie2010 newbie2010 is offline
Registered User
 
Join Date: Nov 2012
Last Activity: 4 April 2014, 10:01 AM EDT
Posts: 131
Thanks: 51
Thanked 12 Times in 2 Posts
VBE: Dude, you are so right! The other user is running csh! Thanks for the help. I guess I will have to look into how csh treats variables. Maybe it uses setenv or something like that! Thanks for the help and if you have any further suggestions, let me know.

---------- Post updated at 01:41 PM ---------- Previous update was at 11:59 AM ----------

VBE you were right! using the #!/bin/bash fixed it! THANKS A MILLION!
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to allow a different user to run a script DallasT UNIX for Dummies Questions & Answers 6 08-16-2011 08:36 AM
Run SAME SCRIPT as different user linuxadmin Shell Programming and Scripting 2 07-16-2011 09:53 AM
Run the script as other user vasuarjula Shell Programming and Scripting 5 01-19-2011 07:06 PM
Run script by another user Mr.AIX AIX 2 10-03-2010 04:16 PM
Run the script from another user Krishnaramjis Shell Programming and Scripting 4 11-02-2007 01:34 AM



All times are GMT -4. The time now is 02:54 AM.