LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 09-07-2011, 11:58 AM   #1
JZL240I-U
Senior Member
 
Registered: Apr 2003
Location: Germany
Distribution: openSuSE Tumbleweed-KDE, Mint 18.3+19.0, MX-18
Posts: 4,258

Rep: Reputation: Disabled
Running a perl script: "No permission". What can cause this?


I have a perl script to find out signal strenght on a mobile internet stick. Running it I get "No permission", or, as it is a German installation "Keine Berechtigung". That's all. How can I find out what's really up, i.e. what permission is where needed?
 
Old 09-07-2011, 01:22 PM   #2
rkdavies
LQ Newbie
 
Registered: Jan 2010
Location: San Diego, California
Distribution: Debian, RHEL, SuSE
Posts: 6

Rep: Reputation: 2
Can you paste the contents of your perl script to review?

You may need to be root to poll that device for that information. Try running your perl script through sudo.
 
Old 09-07-2011, 03:23 PM   #3
jake3988
Member
 
Registered: Mar 2005
Location: Ohio
Distribution: Freebsd and Ubuntu
Posts: 69

Rep: Reputation: 17
It would be impossible to know unless you gave us more info.

Were you unable to start the script? Do you not have access to something the script accesses? Were you running with the same user that created the script? Etc.
 
Old 09-07-2011, 03:57 PM   #4
knudfl
LQ 5k Club
 
Registered: Jan 2008
Location: Copenhagen DK
Distribution: PCLinuxOS2019 CentOS6.10 CentOS7.7 + 50+ other Linux OS, for test only.
Posts: 17,314

Rep: Reputation: 3576Reputation: 3576Reputation: 3576Reputation: 3576Reputation: 3576Reputation: 3576Reputation: 3576Reputation: 3576Reputation: 3576Reputation: 3576Reputation: 3576
When a text file is run with e.g. the command ./perl_script , and replies:
bash: ./perl_script: Permission denied
... It's probably not an executable script.


Also : A perl script should have this text in line 1 : #!/usr/bin/perl ,
if you want to execute it.

If not executable, and no " #!/usr/bin/perl ", the command is: 'perl perl_script'

..
 
Old 09-08-2011, 01:55 AM   #5
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.10, Centos 7.5
Posts: 17,697

Rep: Reputation: 2494Reputation: 2494Reputation: 2494Reputation: 2494Reputation: 2494Reputation: 2494Reputation: 2494Reputation: 2494Reputation: 2494Reputation: 2494Reputation: 2494
If its executable perms on the script, see http://linux.die.net/man/1/chmod.
you can use the cmd
Code:
ls -l
to check perms. NB: that's a lowercase L there...
 
Old 09-08-2011, 02:23 AM   #6
JZL240I-U
Senior Member
 
Registered: Apr 2003
Location: Germany
Distribution: openSuSE Tumbleweed-KDE, Mint 18.3+19.0, MX-18
Posts: 4,258

Original Poster
Rep: Reputation: Disabled
Whoa, that many replies. Okay I'll answer successively:

@ rkdavies: Here you are:
Code:
#!/usr/bin/perl
#
# Copyright (C) 2009 Lars Engels <lars@0x20.net>
# All rights reserved. Standard 2-clause BSD license and disclaimer applies.

# umts_stick


use strict;
use warnings;

use Getopt::Std;

my $VERSION = 0.1;

my $modem = "/dev/ttyUSB1";     # Change to your device name
my $pin = "6122";               # Insert your device's PIN

my $rc = 0;
my %options=();
my $i = 0;

$SIG{ALRM} = sub {
        die("Timeout: no response from modem $modem\n");
};

sub query_pin_status;
sub query_provider;
sub query_signal;
sub send_pin;
sub usage;


usage if ((@ARGV <= 0) || (@ARGV >= 2));

getopts("ahsp", \%options) or usage;
usage if defined $options{h};

open(MODEM, "+<", $modem) or die("can't open modem $modem: $!");
alarm(10);

send_pin if defined $options{a};

if (defined $options{s}) {
        query_provider;
	for ($i=1; $i<=1000; $i++) {
	        query_signal;
	        sleep(5);
	}
}

query_pin_status if defined $options{p};


close(MODEM) or die "Cannot close modem: $!";
exit $rc;



#### SUBS ####
sub query_pin_status {
        my $query_pin_cmd = "AT+CPIN?\n\r";
        print MODEM  $query_pin_cmd;
        while (<MODEM>) {
                if (/READY/) {
                        print "Ready: PIN already accepted or no PIN needed.\n";
                        last;
                } elsif (/SIM\ PIN/) {
                        print "Waiting for PIN.\n";
                        last;
                } elsif (/SIM\ PUK/) {
                        print "Waiting for PUK.\n";
                        last;
                } elsif (/^(OK)|$/) {
                        next;
                } else {
                        print "Unknown PIN status!\n";
                        $rc = 1;
                }
        }
        $rc = 0;
}

sub query_provider {
        my $query_prov_cmd = "AT+COPS?\n\r";
        my @conn_types = ('GSM', 'Compact GSM', 'UMTS', 'EDGE', 'UMTS with HSDPA', 'UMTS with HSUPA', 'UMTS with HSDPA and HSUPA');
        print MODEM $query_prov_cmd;
        while (<MODEM>) {
                if (/^\+COPS/) {
                        my (undef, undef, $provider, $conn_type) = split /,/;
                        printf "Provider: %s\nConnection type: %s\n", $provider, $conn_types[$conn_type];
                        $rc = 0;
                        last;
                }
        }
}

sub query_signal {
        my $query_signal_cmd = "AT+CSQ\n\r";
        print MODEM $query_signal_cmd;
        while (<MODEM>) {
                if (/^\+CSQ:\ (\d+),\d+/) {
                        my $rssi = $1;
                        printf "Signal strength: %d dBm\n", ($rssi * 2) - 113;
                        $rc = 0;
                        last;
                }
        }
}

sub send_pin {
        my $send_pin_cmd = "AT+CPIN=\"$pin\"\n\r";
        print MODEM $send_pin_cmd;
        while (<MODEM>) {
                if (/OK/) {
                        print "PIN accepted\n" ;
                        $rc = 0;
                        last;
                }
                if (/ERROR/) {
                        print "PIN rejected\n" ;
                        $rc = 1;
                        last;
                }
        }
}

sub usage {
        print "Usage: $0 [-a] [-h] [-s] [-p]\n";
        print "Options:\n";
        print "    -a     send PIN to device\n";
        print "    -s     print current provider, connection type and signal quality\n";
        print "    -p     get current PIN status\n";
        print "    -h     this help message\n";
        exit -1;
}
I ran it as root as well. No change.

@ jake3988: I started the script and got the error message I posted. Perl is installed. I started it as normal user (who owns the script file) and as root and got the same dismal result. "Etc." .

@ knudfl: I switched it from chmod 644 to 755 and back. No change. The script starts with "#!/usr/bin/perl" which you can easily check in the code posted above. Thanks for explaining how to start a non-executable and no shebang containing file.

@ chrism01: Did that (see above). Neither "rw-r--r--" nor "rwxr-xr-x" runs, both produce the same error.


Question for the honourable assembly: Is there a log which I might consult somewhere hidden in the system, or can I force the script to generate more error messages?

Last edited by JZL240I-U; 09-08-2011 at 02:26 AM.
 
Old 09-08-2011, 05:10 AM   #7
knudfl
LQ 5k Club
 
Registered: Jan 2008
Location: Copenhagen DK
Distribution: PCLinuxOS2019 CentOS6.10 CentOS7.7 + 50+ other Linux OS, for test only.
Posts: 17,314

Rep: Reputation: 3576Reputation: 3576Reputation: 3576Reputation: 3576Reputation: 3576Reputation: 3576Reputation: 3576Reputation: 3576Reputation: 3576Reputation: 3576Reputation: 3576
Works OK here ..

[knudfl@localhost ~]$ ./perl_script -s
can't open modem /dev/ttyUSB1: No such file or directory at ./perl_script line 39.

Please show 'ls -l' reply, ref. post #5.


"Permission denied" : Could it be, that the script functions
are not allowed by 'selinux' ?
Suggest : Try with "permissive", and also selinux "disabled".
EDIT : Sorry, it's "apparmor" in Suse, isn't it ?

..

Last edited by knudfl; 09-08-2011 at 09:48 AM.
 
Old 09-08-2011, 07:30 AM   #8
JZL240I-U
Senior Member
 
Registered: Apr 2003
Location: Germany
Distribution: openSuSE Tumbleweed-KDE, Mint 18.3+19.0, MX-18
Posts: 4,258

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by knudfl View Post
[knudfl@localhost ~]$ ./perl_script -s
I didn't use a trailing "-s". Will try tonight.

Quote:
Originally Posted by knudfl View Post
Please show 'ls -l' reply, ref. post #5.
Will do (tonight).

Quote:
Originally Posted by knudfl View Post
"Permission denied" ...
EDIT : Sorry, it's "apparmor" in Suse, isn't it ?
Apparmor, right. I created no profile for this script.
 
Old 09-08-2011, 09:52 AM   #9
knudfl
LQ 5k Club
 
Registered: Jan 2008
Location: Copenhagen DK
Distribution: PCLinuxOS2019 CentOS6.10 CentOS7.7 + 50+ other Linux OS, for test only.
Posts: 17,314

Rep: Reputation: 3576Reputation: 3576Reputation: 3576Reputation: 3576Reputation: 3576Reputation: 3576Reputation: 3576Reputation: 3576Reputation: 3576Reputation: 3576Reputation: 3576
Comment : "./perl_script -s" is just an example command.

./perl_script -a :
Behaves in a similar OK way on an OS with no selinux or apparmor.
( E.g. PCLinuxOS, Slackware ).

.
 
Old 09-08-2011, 12:26 PM   #10
JZL240I-U
Senior Member
 
Registered: Apr 2003
Location: Germany
Distribution: openSuSE Tumbleweed-KDE, Mint 18.3+19.0, MX-18
Posts: 4,258

Original Poster
Rep: Reputation: Disabled
Uarghhh.

Code:
me@linux-txzu:~> perl ./poll -a
can't open modem /dev/ttyUSB1: Keine Berechtigung at ./poll line 39.
Well, they say in brevity lies mastery, but not when you obscure the cause of a problem...

I'll have a look into that and be back. Thanks to all of you.

Oh, and this is the result from "ls -l" (as you might have guessed from my "chmod" plea in post #6 for chrism01 ):

Code:
me@linux-txzu:~> ls -l
...
-rw-r--r--  1 me users    4400 30. Jan 2010  poll
...
<edit> Works as root. Script doesn't do what I want, though

Code:
me@linux-txzu:~> ls -l /dev/ttyUSB*
crw-rw---- 1 root dialout 188, 0  8. Sep 18:10 /dev/ttyUSB0
crw-rw---- 1 root dialout 188, 1  8. Sep 18:09 /dev/ttyUSB1
crw-rw---- 1 root dialout 188, 2  8. Sep 18:09 /dev/ttyUSB2
</edit>

Last edited by JZL240I-U; 09-08-2011 at 12:37 PM.
 
Old 09-08-2011, 09:43 PM   #11
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.10, Centos 7.5
Posts: 17,697

Rep: Reputation: 2494Reputation: 2494Reputation: 2494Reputation: 2494Reputation: 2494Reputation: 2494Reputation: 2494Reputation: 2494Reputation: 2494Reputation: 2494Reputation: 2494
Given you've got this at the top of your prog
Code:
#!/usr/bin/perl
that means you can invoke it directly, assuming that's the correct path to Perl; try 'which perl' to check
Code:
./poll -a
but you will need to add the 'x' perms first of course
 
Old 09-09-2011, 02:14 AM   #12
JZL240I-U
Senior Member
 
Registered: Apr 2003
Location: Germany
Distribution: openSuSE Tumbleweed-KDE, Mint 18.3+19.0, MX-18
Posts: 4,258

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by chrism01 View Post
...try 'which perl' to check...
...you will need to add the 'x' perms first of course
Will do both. Easier to invoke during debug, then. Thanks again fo all participants of this thread. Marked as solved.
 
  


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
[SOLVED] Problem running .sh script with "screen" and "java" IJustinI Linux - Newbie 31 06-01-2010 08:13 AM
"Permission denied " running any .sh file mamunbabu2001 Linux - Newbie 9 09-24-2009 01:09 PM
"cp: cannot stat" running a perl installer script juanacevedo Linux - Newbie 1 06-19-2009 02:52 AM
Eclipse SDK v3.0 running problem: "Permission denied" AlexDunnCpp Linux - Newbie 1 08-03-2004 12:45 PM
Compiling KDE 3.2.0 - "Can't open perl script "/dcopidlng/kalyptus" linuxgamer09483 Linux - Software 3 04-09-2004 09:25 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 08:06 AM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration