Showing posts with label Solaris. Show all posts
Showing posts with label Solaris. Show all posts

Monday, November 15, 2010

scripts and hash bang ( #! )

More often than not, people have to tell the unix shell / perl scripts or other programs where lies their interpretor, e.g. write their command line calls as 

perl SomeScript.pl

or 

ruby ARubyProgram.rb

or 

sh SomeShellScript.sh

this is because the system may not be aware of the location of the the executable interpreter of the exact type that needs to be used for the corresponding script.  Well, for this purpose, windows has the file extension association concept, but we are dealing with Unix like systems not windows, so that option is not really available to us (besides, there are ill effects of that convention too, but lets not go in that discussion).

So, to tell a unix program where to find its interpreter, besides launching the script along with it on command line, there is another way, and rather beautiful at that.

Just put the exact path of your interpreter executable at the very first line of your script preceded by these two magic characters, a hash and an exclamation (#!) also called as hash-bang or shebang.  Now, once your script is marked as executable (see chmod), you are good to go, no need of putting explicit calls to the interpreter to run your code.

Basically, your code should now look like this - 

#!/usr/local/bin/perl5
print "testing hashbang with raghav"

Save this short script as aa.pl (assuming that your system has perl 5 interpreter installed in the location I used). Make the script executable (chmod) and you can just launch the script, like ./aa.pl  instead of earlier example perl aa.pl

A word of caution though, these magic characters have to be absolutely the first and second character of the file, no exceptions to that. Else, the system cant make out the special meaning of this and the purpose is lost.

Pretty neat.. hunh...

Monday, April 14, 2008

chown : not owner !!!

Apparantly, you cant do a chown in Solaris. Here's more...

http://unix.derkeiler.com/Newsgroups/comp.unix.solaris/2004-03/2579.html

another one here

http://www.itworld.com/Comp/3380/nls_unixchown040923/index.html

The reasoning explained sounds logical. Apparantly (as one of the article also explains), the restriction helps a user fill another user's quota by creating a huge file and chowning it to the other user. Even worse, if the other user doesnt have privs to access the dir hosting that huge file, he cant even delete that.

Looks like a safety precaution, turned into a bit of blockade for normal users... :(

Wednesday, April 9, 2008

inet daemons : the way they react to SMF

For a given service, in an SMF manifest, you can invoke any script using the "exec" thing. That works for normal programs.

You can also provide environment to the executable by adding sub-tags envvar..

However, For a network daemon based service, it wont work as nice as it does for other programs.

I came to understand that programs that run as streams need to be designed to work that way specifically, you cant just make ANY program run as a stream through an SMF service.

Using Solaris SMF : Initial Steps

Startup article about SMF usage..

O'Reilly Network -- Using Solaris SMF: "In most Unix environments, the startup process consists of a handful of autonomous boot scripts। They act independently of one another; unaware of what scripts have already run or which ones will run after them. When they are invoked, there is no serious error checking and no recourse if the script fails."

Another interesting tutorial from Sun... Solaris Operating System - SMF Manifest How To Guide