LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-14-2012, 06:36 PM   #1
fatalerror0x00
Member
 
Registered: Oct 2012
Location: Holden, ME, USA
Distribution: SlackWare64 14.00
Posts: 185

Rep: Reputation: 0
Bash: Variable issue?


Code:
#!/bin/bash

# script description blah blah blah

if [ -L "$0" ]; then
     source "$(readlink -e "$0" | sed "s:[^/]*$:cbi.test:")"

     if [ $? -eq 0 ]; then
          echo "[Script diagnostics]: Loaded config file through readlink" >> "$CBI_LOG"

     fi

else
     source "$(echo "$0" | sed "s:[^/]*$:cbi.test:")"

     if [ $? -eq 0 ]; then
          echo "[Script diagnostics]: Loaded config file using echo" >> "$CBI_LOG"

     fi

fi
okay so thats my code now I have 4 ways I can execute this script (2 which I think are practically the same)

format will be: executed command - error message

by symlink contained in /usr/local/bin/ and is called minecraft and actual script is loacted at /home/shawn/programs/craftbukkit-init/ called minecraft

USERNAME="shawn"
MC_PATH="/home/${USERNAME}/server/test"
CBI_LOG="${MC_PATH}/cbi.log"

minecraft - /usr/local/bin/minecraft: line 10: /cbi.log: Permission denied

sh minecraft - minecraft: line 18: /cbi.log: Permission denied

./minecraft - ./minecraft: line 18: /cbi.log: Permission denied

. minecraft - writes to the log file fine

well that's it you have my code and all the errors my location of executing all the variables are in the same folder as the original script. it's loading from the cbi.test file (currently using a test file and all it really is is without all the extra information about what the settings i have for my script are is all. Hope this helps alot please let me know if you need anything more

I have this in another post but i believe where it's so far at the end it might be just getting ignored plus the issue wasn't originally about this so I think it should have it's own post on it.
 
Old 11-15-2012, 07:23 AM   #2
elucches
Member
 
Registered: Jan 2011
Posts: 108

Rep: Reputation: 11
Where do you define the environment variables USERNAME, MC_PATH and CBI_LOG?
 
Old 11-15-2012, 10:09 AM   #3
fatalerror0x00
Member
 
Registered: Oct 2012
Location: Holden, ME, USA
Distribution: SlackWare64 14.00
Posts: 185

Original Poster
Rep: Reputation: 0
Ah yes I defined them in the cbi.test file that the script is loading which is successful loading or supposedly is successful loading because $? is 0 and should only execute the log file if $? is 0. there for it should know the location of where the log goes but only knows when doing . minecraft. Which is very strange to me that ihe errors I get don't know where it's logging too and and different execution styles I just realized now actually are tying to all log to the root directory of the system (not the /root directory but /) which is strange it would do that in any case where the path defined in the variable is not /cbi.log unless the config file isn't loading but then it wouldn't do anything or shouldn't. So i believe I may have just found my issue :P I'm trying to use a variable I'm assuming before it's even defined. I believe that might be my issue? I have in my config CBI_LOG before MC_PATH but yes USERNAME is before MC_PATH (this mistake is only in my test config file and not my original as I added this is later and just put it in randomly not thinking)

and it works just find now I can't believe I didn't notice that before -.- Feel like such an idiot I should have known to check that but i think I didn't realize cause I didn't realize they all tried to log to the same location some reason I thought sh and ./ were the only ones trying to log to /cbi.log -.- solved guys thanks

Last edited by fatalerror0x00; 11-15-2012 at 10:24 AM.
 
  


Reply


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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[bash] re-evaluate variable inside variable muzzol Programming 9 12-01-2010 11:31 AM
Bash: How do I read data from a variable while that variable is being populated? theaceoffire Programming 4 04-23-2010 02:29 PM
How to get variable from text file into Bash variable mcdef Linux - Software 2 06-10-2009 01:15 PM
bash script path issue - how to pass a path as a string to a variable PiNPOiNT Programming 5 04-17-2009 05:48 PM
[SOLVED] issue with variable in bash script angel115 Programming 4 08-21-2006 01:42 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:38 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