LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 10-28-2006, 09:51 AM   #1
hoodedmanwithsythe
Member
 
Registered: Apr 2006
Location: West Midlands, UK
Distribution: mandriva, centos, debian
Posts: 91

Rep: Reputation: 15
args or questions in a shell script which is easyer


Hi,
I am creating a shell script that will save some blender users a lot of time at the moment I have 2 separate scripts the 64 bit version and the 32 bit version the script basically loads the PYTHONPATH and then runs blender but what i wan't to do is have only one script that asks you wether or not your system is 64Bit and if the default command for blender is what you wish to use.
The script currently looks like this
Code:
#!/bin/sh
    PATH=/usr/ucb:/usr/bin:/bin; export PATH
# setting Python Directory
echo "Setting PYTHONPATH for 64Bit OS"
export PYTHONHOME=/lib64/python2.4
export PYTHONPATH=/lib64/python2.4
set $PYTHONHOME /lib64/python2.4
set $PYTHONPATH /lib64/python2.4
# loading blender
echo "Running Blender"
/usr/bin/blender
What I was wondering is wether I should use questions or arguments for this and how would i do this?
I realise that scripting at this level may not be classed as a thing so i am sorry if i have placed this in the wrong area of this forum

Last edited by hoodedmanwithsythe; 10-28-2006 at 09:55 AM.
 
Old 10-28-2006, 09:59 AM   #2
uselpa
Senior Member
 
Registered: Oct 2004
Location: Luxemburg
Distribution: Slackware, OS X
Posts: 1,507

Rep: Reputation: 46
I think that you can find out if the system is 64 bits without asking at all. Like checking if there is a /lib64/ directory.

Generally speaking, I'd suggest args or command-line switches because this allows you to use your script from another script.

So
- the best option is to find out yourself (if possible)
- the second best option is to use args
- the last resort would be an interactive question.
 
Old 10-28-2006, 10:55 AM   #3
frob23
Senior Member
 
Registered: Jan 2004
Location: Roughly 29.467N / 81.206W
Distribution: Ubuntu, FreeBSD, NetBSD
Posts: 1,449

Rep: Reputation: 47
I have to agree with uselpa. If it asks questions, and I'm unable to edit it to accept args instead, then I'm going to need to write an expect script or something if I want to have a default. There seems to be many ways to know the 64 bit answer instead of needing args so you can use those instead.

If there was no way to tell, then you could always define a default value and have a shell variable choose the different path. Much like $EDITOR does. It defaults to vi in most applications if not defined but if defined then the programs will use the editor you want and don't need to prompt you or anything for it.
 
Old 10-28-2006, 11:07 AM   #4
makyo
Member
 
Registered: Aug 2006
Location: Saint Paul, MN, USA
Distribution: {Free,Open}BSD, CentOS, Debian, Fedora, Solaris, SuSE
Posts: 719

Rep: Reputation: 72
Hi.

If you cannot determine about the 64-bit, you may be able to automate using either arguments or an interactive question. If you are called with STDIN being re-directed, you could assume non-interactive, in which case you might look for arguments, otherwise ask a question.

For example:
Code:
#!/bin/sh

# @(#) s2       Demonstrate test for interactive use.

if tty -s
then
        echo " YES! Interactive use."
        exit 0
else
        echo " Not interactive."
        exit 0
fi
And a driver:
Code:
#!/bin/sh

# @(#) s1       Drive test for interactive use.

./s2

touch t2
./s2 <t2
Running the driver produces:
Code:
% ./s1
 YES! Interactive use.
 Not interactive.
Best wishes ... cheers, makyo
 
Old 10-28-2006, 01:28 PM   #5
hoodedmanwithsythe
Member
 
Registered: Apr 2006
Location: West Midlands, UK
Distribution: mandriva, centos, debian
Posts: 91

Original Poster
Rep: Reputation: 15
64bit detection

Ok,
I like the idea of auto detection as i have seen this done before if i recall it has something to do with the system locale so I will start my search for info on this grounds there using the locale command.
any help would be greatly appreciated.
secondly I have no idea on how to put args in to my script,I could do with some help for this part please.

thanks for the suggestions guys
 
Old 10-28-2006, 01:30 PM   #6
hoodedmanwithsythe
Member
 
Registered: Apr 2006
Location: West Midlands, UK
Distribution: mandriva, centos, debian
Posts: 91

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by hoodedmanwithsythe
Ok,
I like the idea of auto detection as i have seen this done before if i recall it has something to do with the system locale so I will start my search for info on this grounds there using the locale command.
any help would be greatly appreciated.
secondly I have no idea on how to put args in to my script,I could do with some help for this part please.

thanks for the suggestions guys
red=wrong I think I will keep searching I have read about this some where
 
Old 10-28-2006, 01:34 PM   #7
uselpa
Senior Member
 
Registered: Oct 2004
Location: Luxemburg
Distribution: Slackware, OS X
Posts: 1,507

Rep: Reputation: 46
I don't have a 64bit processor, but try uname. On my P4:
Code:
pu@slackw:~$ uname -p
pentium4
pu@slackw:~$ uname -i
i386
 
Old 10-28-2006, 01:46 PM   #8
hoodedmanwithsythe
Member
 
Registered: Apr 2006
Location: West Midlands, UK
Distribution: mandriva, centos, debian
Posts: 91

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by uselpa
I don't have a 64bit processor, but try uname. On my P4:
Code:
pu@slackw:~$ uname -p
pentium4
pu@slackw:~$ uname -i
i386
close but no cigar mmy 64bit mandrake says:
Code:
timothy@Linux-Box ~$ uname -p
AMD Athlon(tm) 64 Processor 3200+
timothy@Linux-Box ~$ uname -i
unknown
I need something that works on all linux machines without fail

Last edited by hoodedmanwithsythe; 10-28-2006 at 01:49 PM.
 
Old 10-28-2006, 01:49 PM   #9
uselpa
Senior Member
 
Registered: Oct 2004
Location: Luxemburg
Distribution: Slackware, OS X
Posts: 1,507

Rep: Reputation: 46
Code:
pu@slackw:~$ cat /proc/cpuinfo
processor       : 0
vendor_id       : GenuineIntel
cpu family      : 15
model           : 2
model name      : Intel(R) Pentium(R) 4 CPU 2.80GHz
stepping        : 9
cpu MHz         : 2810.351
cache size      : 512 KB
fdiv_bug        : no
hlt_bug         : no
f00f_bug        : no
coma_bug        : no
fpu             : yes
fpu_exception   : yes
cpuid level     : 2
wp              : yes
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe up cid xtpr
bogomips        : 5624.91
 
Old 10-28-2006, 01:58 PM   #10
hoodedmanwithsythe
Member
 
Registered: Apr 2006
Location: West Midlands, UK
Distribution: mandriva, centos, debian
Posts: 91

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by uselpa
Code:
pu@slackw:~$ cat /proc/cpuinfo
processor       : 0
vendor_id       : GenuineIntel
cpu family      : 15
model           : 2
model name      : Intel(R) Pentium(R) 4 CPU 2.80GHz
stepping        : 9
cpu MHz         : 2810.351
cache size      : 512 KB
fdiv_bug        : no
hlt_bug         : no
f00f_bug        : no
coma_bug        : no
fpu             : yes
fpu_exception   : yes
cpuid level     : 2
wp              : yes
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe up cid xtpr
bogomips        : 5624.91
Code:
 cat /proc/cpuinfo
processor       : 0
vendor_id       : AuthenticAMD
cpu family      : 15
model           : 31
model name      : AMD Athlon(tm) 64 Processor 3200+
stepping        : 0
cpu MHz         : 2200.236
cache size      : 512 KB
fpu             : yes
fpu_exception   : yes
cpuid level     : 1
wp              : yes
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 syscall nx mmxext fxsr_opt lm 3dnowext 3dnow lahf_lm
bogomips        : 4358.14
TLB size        : 1024 4K pages
clflush size    : 64
cache_alignment : 64
address sizes   : 40 bits physical, 48 bits virtual
power management: ts fid vid ttp
on this our systems are simmilar but on yours i cannot see the 64/32 bit defineing sections higlited on mine in red text
 
Old 10-28-2006, 02:00 PM   #11
hoodedmanwithsythe
Member
 
Registered: Apr 2006
Location: West Midlands, UK
Distribution: mandriva, centos, debian
Posts: 91

Original Poster
Rep: Reputation: 15
Maby if i were to runn a seek on these variables, but how
 
Old 10-28-2006, 02:01 PM   #12
unSpawn
Moderator
 
Registered: May 2001
Posts: 27,666
Blog Entries: 54

Rep: Reputation: 2952Reputation: 2952Reputation: 2952Reputation: 2952Reputation: 2952Reputation: 2952Reputation: 2952Reputation: 2952Reputation: 2952Reputation: 2952Reputation: 2952
How about taking hints from FOSS?
Rootkit Hunter uses the distributions release file.
Get Rootkit Hunter then do a "grep 64\) os.dat".
 
Old 10-28-2006, 02:17 PM   #13
hoodedmanwithsythe
Member
 
Registered: Apr 2006
Location: West Midlands, UK
Distribution: mandriva, centos, debian
Posts: 91

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by unSpawn
How about taking hints from FOSS?
Rootkit Hunter uses the distributions release file.
Get Rootkit Hunter then do a "grep 64\) os.dat".
This would require a compiled program that was written in source not in shell and so is not possible sorry but I had already looked at this option.
thinking back to the idea of checking for the /lib64 directory this could solve all problems and no args or other detection would be needed provided that we can find a way of detecting the existance of both that and the blender binarythen the rest would simply be else and elif strings
 
Old 10-28-2006, 05:54 PM   #14
hoodedmanwithsythe
Member
 
Registered: Apr 2006
Location: West Midlands, UK
Distribution: mandriva, centos, debian
Posts: 91

Original Poster
Rep: Reputation: 15
a new idea

ok so while trying various things I thought there has to be an easy way of checking the platform type.
I had tried all the obvious and all of the ideas above and came to no end. so when i finally got board of trying various techniques including;
Code:
find /lib64/python2.4 >$HOME/python.lock
if [ "$HOME/Python.lock" = "/lib64/python2.4/*" ]
then etc...
I decided to google for "shell script" and guess what the fist item was "Advanced Bash-Scripting Guide" "An in-depth exploration of the art of shell scripting"
When flicking through it's pages i came across "9.1. Internal Variables" intreagued i scrolled down to find "$HOSTTYPE"
host type

Like $MACHTYPE, identifies the system hardware.

Code:
bash$ echo $HOSTTYPE
i686
and so I ran this on my machine and it came up
Code:
[timothy@Linux-Box ~]$ echo $HOSTTYPE
x86_64
So I thought and then i tested it on my 32bit machine
Code:
[timothy@Slow-Linux-Box ~]$ echo $HOSTTYPE
i386
So it turns out that bash has a builtin platform checker, so i guess it is time for me to get working on the final coding of my blender starter program.
 
Old 10-28-2006, 07:39 PM   #15
hoodedmanwithsythe
Member
 
Registered: Apr 2006
Location: West Midlands, UK
Distribution: mandriva, centos, debian
Posts: 91

Original Poster
Rep: Reputation: 15
Finished

Ok what I have Finaly Decided to do is use the forgotten about built in
Code:
$HOSTTYPE
system variable in a bog standard
Code:
if [ "<Attribute1>" = "<Attribute2>" ]
then <run this>
layout for my PYTHONPATH preloader for blender. At the moment I am going to stick to a simple version of my preloader that doesn't check the python version nor does it check the location of the Blender Wrapper Script.
The reason for this is that I have not worked out how to check the version of python other than with the python -V command(which I cannot channle the output of) and the reason for not checking where the blender Shell Script is because i have made a icon for my preloader and have also made a .desktop for it so as the preloader will now need to reside in /usr/bin or wherever your Blender Wrapper Script (/usr/bin/ is standard location for static versions of blender)resides.

here is my final release of the code
Code:
#!/bin/bash
    PATH=/usr/ucb:/usr/bin:/bin; export PATH
# checking the platform
echo "checking Platform"
echo "Platform is "$HOSTTYPE
if [ "$HOSTTYPE" = "x86_64" ]
then	#Checking Python Directory
	echo "Setting PYTHONPATH for 64Bit OS"
	export PYTHONHOME=/usr/lib64/python2.4
	export PYTHONPATH=/usr/lib64/python2.4
	# loading blender
	echo "Running Blender"	
	./blender

else	# setting Python Directory
	echo "Setting PYTHONPATH for a 32Bit OS"
	export PYTHONHOME=/usr/lib/python2.4
	export PYTHONPATH=/usr/lib/python2.4
	# loading blender
	echo "Running Blender"
	./blender

fi
exit
here is where you can download it from
 
  


Reply

Tags
args, arguments, blender, python, qus, scripting, shell


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
running a command with args from a shell script KM3 Programming 3 10-19-2006 02:46 PM
three shell script questions qrshat Programming 4 02-27-2006 09:40 AM
Couple of Shell Script Questions mathias1979 Programming 3 06-16-2005 04:22 PM
two shell script questions tutwabee Linux - General 4 08-10-2004 07:03 PM
Shell Script Questions Col Panic Linux - General 13 10-12-2003 01:51 PM


All times are GMT -5. The time now is 07:52 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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration