shebang and ubuntu

P

Phred Phungus

My perfect sunday began with an Americano, 2 chocolate-glazed donuts,
and perl. That may sound very decadent, but that held me food-wise
until the Super Bowl.

I have a common problem that files tell my that I'm not allowed there.
If I recall my reading, I was referred to chmod(). I've looked at that
several times, and it doesn't seem to take, at least as a man page.

Does perl have a way to manipulate these file permissions?

dan@dan-desktop:~/source42$ perl t1.pl
t1.pl out b1.c~ t1.pl~ .. . b1.c
dan@dan-desktop:~/source42$ ./t1.pl
bash: ./t1.pl: Permission denied
dan@dan-desktop:~/source42$ cat t1.pl
#!/usr/bin/perl

opendir(THISDIR, ".") or die "tja $!";
@allfiles = readdir THISDIR;
closedir THISDIR;
print "@allfiles\n";

# perl t1.pl
dan@dan-desktop:~/source42$
 
J

Josef Moellers

Phred said:
My perfect sunday began with an Americano, 2 chocolate-glazed donuts,
and perl. That may sound very decadent, but that held me food-wise
until the Super Bowl.

I have a common problem that files tell my that I'm not allowed there.
If I recall my reading, I was referred to chmod(). I've looked at that
several times, and it doesn't seem to take, at least as a man page.

Does perl have a way to manipulate these file permissions?

dan@dan-desktop:~/source42$ perl t1.pl
t1.pl out b1.c~ t1.pl~ .. . b1.c
dan@dan-desktop:~/source42$ ./t1.pl
bash: ./t1.pl: Permission denied
dan@dan-desktop:~/source42$ cat t1.pl
#!/usr/bin/perl

opendir(THISDIR, ".") or die "tja $!";
@allfiles = readdir THISDIR;
closedir THISDIR;
print "@allfiles\n";

# perl t1.pl
dan@dan-desktop:~/source42$

Have you tried
chmod u+x t1.pl

It has nothing to do with perl.

Josef
 
J

Jürgen Exner

Phred Phungus said:
I have a common problem that files tell my that I'm not allowed there.
If I recall my reading, I was referred to chmod(). I've looked at that
several times, and it doesn't seem to take, at least as a man page.

Does perl have a way to manipulate these file permissions?

dan@dan-desktop:~/source42$ perl t1.pl

What is "~/source42$"? Is that part of your prompt? That is confusing to
say the least!
t1.pl out b1.c~ t1.pl~ .. . b1.c
dan@dan-desktop:~/source42$ ./t1.pl
bash: ./t1.pl: Permission denied

That error message is a bash error message, it has nothing to do with
Perl.
There can be more obscure reasons but most likely you didn't set the
file permissions for t1.pl to executable.
dan@dan-desktop:~/source42$ cat t1.pl
#!/usr/bin/perl

One of those more obscure reasons could be that /usr/bin/perl itself is
not executable for you and this is being masked by a different perl
being executed in your first command (did you try 'which perl'?).

jue
 
H

Huge

What is "~/source42$"? Is that part of your prompt? That is confusing to
say the least!


That error message is a bash error message, it has nothing to do with
Perl.
There can be more obscure reasons but most likely you didn't set the
file permissions for t1.pl to executable.

IOW,

chmod +x ./t1.pl
 
C

ccc31807

I have a common problem that files tell my that I'm not allowed there.
If I recall my reading, I was referred to chmod().  I've looked at that
several times, and it doesn't seem to take, at least as a man page.

I find chmod very easy and intuitive, but I never use the + or -
syntax, I always use the octal syntax, e.g., 'chomd 755 some.file'

Read is 4, write is 2, and execute is 1, so that 755 meas that owner
has read, write, and execute permissions, and that group and other has
read and execute permissions. 644 means that owner has read and write
permissions and group and other only has read. 700 locks out everyone
except the owner.

CC.
 
P

Phred Phungus

ccc31807 said:
I find chmod very easy and intuitive, but I never use the + or -
syntax, I always use the octal syntax, e.g., 'chomd 755 some.file'

Read is 4, write is 2, and execute is 1, so that 755 meas that owner
has read, write, and execute permissions, and that group and other has
read and execute permissions. 644 means that owner has read and write
permissions and group and other only has read. 700 locks out everyone
except the owner.

CC.

Thanks all for replies. I hope this sticks now. I've made a linuxlog
for this go around and I'm gonna put your comments and this there:

dan@dan-desktop:~/source42$ chmod u + x t1.pl
chmod: invalid mode: `u'
Try `chmod --help' for more information.
dan@dan-desktop:~/source42$ chmod u+x t1.pl
dan@dan-desktop:~/source42$ ls -l
total 32
-rw-r--r-- 1 dan dan 2556 2010-02-07 18:46 b1.c
-rw-r--r-- 1 dan dan 2555 2010-02-07 18:46 b1.c~
-rwxr-xr-x 1 dan dan 13344 2010-02-07 18:47 out
-rwxr--r-- 1 dan dan 138 2010-02-08 01:34 t1.pl
-rw-r--r-- 1 dan dan 31 2010-02-08 01:30 t1.pl~

One sees here the permissions as gcc creates an executable (out).


dan@dan-desktop:~/source42$ ./t1.pl
t1.pl out b1.c~ t1.pl~ .. . b1.c
dan@dan-desktop:~/source42$ chmod 755 t1.pl
dan@dan-desktop:~/source42$ ls -l t1.pl
-rwxr-xr-x 1 dan dan 138 2010-02-08 01:34 t1.pl
dan@dan-desktop:~/source42$ ./t1.pl
t1.pl out b1.c~ t1.pl~ .. . b1.c
dan@dan-desktop:~/source42$ chmod 644 t1.pl
dan@dan-desktop:~/source42$ ls -l t1.pl
-rw-r--r-- 1 dan dan 138 2010-02-08 01:34 t1.pl
dan@dan-desktop:~/source42$ ./t1.pl
bash: ./t1.pl: Permission denied
dan@dan-desktop:~/source42$ chmod 700 t1.pl
dan@dan-desktop:~/source42$ ls -l t1.pl
-rwx------ 1 dan dan 138 2010-02-08 01:34 t1.pl
dan@dan-desktop:~/source42$ ./t1.pl
t1.pl out b1.c~ t1.pl~ .. . b1.c

chmod seems to have been another instance where my C notion that
whitespace is better has led me astray. Since it's just me on this
machine, I think I'll go with chmod 700 in the future.

Cheers,
 
P

Phred Phungus

Jürgen Exner said:
What is "~/source42$"? Is that part of your prompt? That is confusing to
say the least!

I've got all these refugee directories named source leftover from when I
would use gnu software on windows. Now on linux, not only do I have a
shebang line that does something, but I also have the option of creating
a terminal anywhere I want with a right-click and selection. So I've
got a lot more flexibility than trying bring up a dos terminal quickly.

Since this is x-posted to alt.os.linux.ubuntu, I would be curious where
others like to put their perl scripts.
That error message is a bash error message, it has nothing to do with
Perl.
There can be more obscure reasons but most likely you didn't set the
file permissions for t1.pl to executable.


One of those more obscure reasons could be that /usr/bin/perl itself is
not executable for you and this is being masked by a different perl
being executed in your first command (did you try 'which perl'?).

dan@dan-desktop:~/source42$ which perl
/usr/bin/perl

I've now tripped on another instance of being denied permission:

dan@dan-desktop:/usr/bin$ ls -l >text1.txt
bash: text1.txt: Permission denied
dan@dan-desktop:/usr/bin$ ls -l text1.txt
ls: cannot access text1.txt: No such file or directory
dan@dan-desktop:/usr/bin$


How can a non-existent file deny me permission?
 
S

sreservoir

ccc31807 said:
I find chmod very easy and intuitive, but I never use the + or -
syntax, I always use the octal syntax, e.g., 'chomd 755 some.file'

Read is 4, write is 2, and execute is 1, so that 755 meas that owner
has read, write, and execute permissions, and that group and other has
read and execute permissions. 644 means that owner has read and write
permissions and group and other only has read. 700 locks out everyone
except the owner.

CC.

Thanks all for replies. I hope this sticks now. I've made a linuxlog for
this go around and I'm gonna put your comments and this there:

dan@dan-desktop:~/source42$ chmod u + x t1.pl
chmod: invalid mode: `u'
Try `chmod --help' for more information.
dan@dan-desktop:~/source42$ chmod u+x t1.pl
dan@dan-desktop:~/source42$ ls -l
total 32
-rw-r--r-- 1 dan dan 2556 2010-02-07 18:46 b1.c
-rw-r--r-- 1 dan dan 2555 2010-02-07 18:46 b1.c~
-rwxr-xr-x 1 dan dan 13344 2010-02-07 18:47 out
-rwxr--r-- 1 dan dan 138 2010-02-08 01:34 t1.pl
-rw-r--r-- 1 dan dan 31 2010-02-08 01:30 t1.pl~

One sees here the permissions as gcc creates an executable (out).
[snip]
chmod seems to have been another instance where my C notion that
whitespace is better has led me astray. Since it's just me on this
machine, I think I'll go with chmod 700 in the future.

well, you're giving chmod two extra arguments. do you expect it to work?
 
S

sreservoir

* what is the current directory?
* which user are you?
* which user owns the current directory?

he seems to be a non-root user in /usr/bin (usually root:root/wheel).

naturally he wouldn't be able to create a file.
 
S

sreservoir

I've got all these refugee directories named source leftover from when I
would use gnu software on windows. Now on linux, not only do I have a
shebang line that does something, but I also have the option of creating
a terminal anywhere I want with a right-click and selection. So I've got
a lot more flexibility than trying bring up a dos terminal quickly.

Since this is x-posted to alt.os.linux.ubuntu, I would be curious where
others like to put their perl scripts.


dan@dan-desktop:~/source42$ which perl
/usr/bin/perl

I've now tripped on another instance of being denied permission:

dan@dan-desktop:/usr/bin$ ls -l >text1.txt
bash: text1.txt: Permission denied
dan@dan-desktop:/usr/bin$ ls -l text1.txt
ls: cannot access text1.txt: No such file or directory
dan@dan-desktop:/usr/bin$


How can a non-existent file deny me permission?

it isn't. the directory is denying creat permission.
 
J

Jonathan N. Little

Phred said:
I've now tripped on another instance of being denied permission:

dan@dan-desktop:/usr/bin$ ls -l >text1.txt
bash: text1.txt: Permission denied

If you are not root you cannot write to the /usr/bin folder

Try
sudo sh -c "ls -l > text1.txt"

Or redirect do a folder that you *do* have write permission
ls -l > ~/text1.txt
 
S

sreservoir

If you are not root you cannot write to the /usr/bin folder

Try
sudo sh -c "ls -l > text1.txt"

ls -l | sudo tee text1.txt >&-
Or redirect do a folder that you *do* have write permission
ls -l > ~/text1.txt

this is probably the best idea, since /usr/bin isn't a good place to
keep directory listings.
 
J

Jürgen Exner

Phred Phungus said:
I've got all these refugee directories named source leftover from when I
would use gnu software on windows. Now on linux, not only do I have a
shebang line that does something, but I also have the option of creating
a terminal anywhere I want with a right-click and selection. So I've
got a lot more flexibility than trying bring up a dos terminal quickly.

???
Is the above meant to be an answer to my question? If yes then I have no
idea what you are talking about.
dan@dan-desktop:~/source42$ which perl
/usr/bin/perl

Ok, then it is not this one of the more obscure reasons. My bets are
still on the most trivial: you forgot to make t1.pl executable.
I've now tripped on another instance of being denied permission:

dan@dan-desktop:/usr/bin$ ls -l >text1.txt
bash: text1.txt: Permission denied

Ok, I am beginning to suspect that this funny "~/source42$" or now
"/usr/bin$" is supposed to indicate the current working directory.
How can a non-existent file deny me permission?

If that is the case then does your account have permissions to create a
file in /usr/bin? Hopefully not because otherwise that would be A Very
Bad Idea. You absolutely, totally, completely don't want just any user
to mess around in /usr/bin.

Again, this has nothing at all whatsoever to do with Perl.

jue
 
J

Jürgen Exner

Jonathan N. Little said:
If you are not root you cannot write to the /usr/bin folder

Try
sudo sh -c "ls -l > text1.txt"

Of course this begs the question why on earth would somewone want to
create a txt file in /usr/bin?
Or redirect do a folder that you *do* have write permission
ls -l > ~/text1.txt

A much saner idea.

jue
 
P

Phred Phungus

Jürgen Exner said:
Of course this begs the question why on earth would somewone want to
create a txt file in /usr/bin?

If you want to see what's in there and you don't have the below advice.
A much saner idea.

dan@dan-desktop:/usr/bin$ ls -l > ~/zax1.txt
dan@dan-desktop:/usr/bin$ locate zax1.txt
dan@dan-desktop:/usr/bin$ man sh
dan@dan-desktop:/usr/bin$ sudo sh -c "ls -l > qext1.txt"
[sudo] password for dan:
dan@dan-desktop:/usr/bin$ locate qext1.txt
dan@dan-desktop:/usr/bin$ ls qext1.txt

I'm so glad I finally figured out this bit here. It will enter my
linuxlog, and so I hope never to ask this question again.

Why did my locate commands not work? The first should have indicated
that the text file was in the home folder, and the second is in the same
directory whence the locate originates.
 
D

Dan C

I've got all these refugee directories named source leftover from when I
would use gnu software on windows. Now on linux, not only do I have a
shebang line that does something, but I also have the option of creating
a terminal anywhere I want with a right-click and selection. So I've
got a lot more flexibility than trying bring up a dos terminal quickly.

Since this is x-posted to alt.os.linux.ubuntu, I would be curious where
others like to put their perl scripts.



dan@dan-desktop:~/source42$ which perl /usr/bin/perl

I've now tripped on another instance of being denied permission:

dan@dan-desktop:/usr/bin$ ls -l >text1.txt bash: text1.txt: Permission
denied
dan@dan-desktop:/usr/bin$ ls -l text1.txt ls: cannot access text1.txt:
No such file or directory dan@dan-desktop:/usr/bin$


How can a non-existent file deny me permission?


Jesus, you're fucking stupid even for a n00b. Almost so stupid that one
would have to believe you're just deliberately trolling.

Bugger off, stupid troll boy.
 
M

Martijn Lievaart

dan@dan-desktop:/usr/bin$ ls -l > ~/zax1.txt dan@dan-desktop:/usr/bin$
locate zax1.txt dan@dan-desktop:/usr/bin$ man sh
dan@dan-desktop:/usr/bin$ sudo sh -c "ls -l > qext1.txt" [sudo] password
for dan:
dan@dan-desktop:/usr/bin$ locate qext1.txt dan@dan-desktop:/usr/bin$ ls
qext1.txt

I'm so glad I finally figured out this bit here. It will enter my
linuxlog, and so I hope never to ask this question again.

Why did my locate commands not work? The first should have indicated
that the text file was in the home folder, and the second is in the same
directory whence the locate originates.

Locate works on a database that is created each night.

I think you would be better of in a unix/linux newsgroup. Your questions
are VERY basic unix questions and have NOTHING to do with perl.

M4
 
J

Josef Moellers

Phred said:
Since this is x-posted to alt.os.linux.ubuntu, I would be curious where
others like to put their perl scripts.

It depends (aus usual).
If you feel that it is a generic script and should be made available to
anyone using the system, the best place to put it would be
/usr/local/bin (it not being a generally avaliable script). If you just
want to keep it to yourself, put it into the bin-directory inside your
home-directory: $HOME/bin.
I've now tripped on another instance of being denied permission:

dan@dan-desktop:/usr/bin$ ls -l >text1.txt
bash: text1.txt: Permission denied
dan@dan-desktop:/usr/bin$ ls -l text1.txt
ls: cannot access text1.txt: No such file or directory
dan@dan-desktop:/usr/bin$


How can a non-existent file deny me permission?

It's not the file which denies you permission, it's the directory.
"/usr/bin" is a directory which holds system-wide commands and is
writable only by the super-user "root", or else anyone could put trojans
there.
You can check a directory's permissions with
ls -ld <directoryname>
e.g.
ls -ld /usr/bin

drwxr-xr-x 2 root root 69632 2010-02-08 15:48 /usr/bin

This means:
it's a directory ("d"),
The owner (the first "root") may read, write, and search ("rwx"),
anyone belonging to the group "root" (the second "root", users and
groups can have the same name) may read and search but not write (the
first "r-x") and the resto of the world may read and searcg but not
write (the second "r-x").
The large number is the size in bytes of the directory index (so to
speak) and is of little importance. The next is the date and time of the
last modification of that directory (e.g. a new file was created in that
directory), followed by the name of the directory.

HTH,

Josef
 
H

Huge

Since this is x-posted to alt.os.linux.ubuntu, I would be curious where
others like to put their perl scripts.

When I'm working on something;

~/Prog/{progname}/

When it's finished, if it's just for me;

~/bin/

If it's for anyone who might use my computer;

/usr/local/bin/
I've now tripped on another instance of being denied permission:

dan@dan-desktop:/usr/bin$ ls -l >text1.txt
bash: text1.txt: Permission denied
dan@dan-desktop:/usr/bin$ ls -l text1.txt
ls: cannot access text1.txt: No such file or directory
dan@dan-desktop:/usr/bin$


How can a non-existent file deny me permission?

It can't. You're attempting to write a file (text1.txt) in a directory
in which you don't have write permission.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,813
Latest member
lawrwtwinkle111

Latest Threads

Top