Execution problem with perl


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Execution problem with perl
# 8  
Old 03-10-2010
Quote:
Originally Posted by radoulov
Hm ...

Code:
$ w
  8:26pm  up 278 day(s),  4:58,  2 users,  load average: 0.02, 0.03, 0.04
User     tty           login@  idle   JCPU   PCPU  what
drado    pts/1         8:21pm                      w
drado    pts/2         8:25pm     1                bash
$ perl -wle '
  @a = qx(who| perl -wlane \47print \$F[0];\47 | sort -u);
  chomp @a;
  print @a;
'
drado

It works for me.
really strange!!!! ...I am using SunOs 5.10, will this affect the code o/p?
# 9  
Old 03-10-2010
Quote:
Originally Posted by ahmad.diab
Sorry Alister but the problem as in radoulov solution
Just to be sure you realize it, allow me to reiterate: The code being passed to the perl interpreter is mangled by the single-quote problem I explained in my prior post. If you are pursuing a different solution that does not use any perl code with single quotes within a single quoted string that's parsed by the shell, then cool. Nevermind this paragraph Smilie

By the way, your original code with properly-escaped single quoting (as in my first post) works fine.

Cheers,
Alister
# 10  
Old 03-10-2010
I really don't know, it works for me on Solaris 10:

Code:
$ who
drado      pts/3        Mar 10 20:26    (xxx)
xxx   pts/2        Mar 10 20:10    (xxx)
$ uname -sr
SunOS 5.10
$ perl -wle '
  @a = qx(who| perl -wlane \47print \$F[0];\47 | sort -u);
  chomp @a;
  print @a;
'
dradoxxx

# 11  
Old 03-10-2010
thank you guys for your reply I think some think wrong in my server I don't know where the problem is exist but I hope you could suggest to me where to start troubleshooting this.

radoulov thank you for your previous solution it worked great.

Alister:- I have also tried awk '{print $1}' instead of the inner perl in my code but with same problem!!!!


but guys is my problem related to any env variable in my system?



---------- Post updated at 21:43 ---------- Previous update was at 21:36 ----------

guys i have tried the below:-

Code:
perl -wle '
  @a = qx(who| cut -d" " -f1 | sort -u);
  chomp @a;
  print @a;
'

perl -wle '
  @a = qx(who| cut -d'\'' '\'' -f1 | sort -u);
  chomp @a;
  print @a;
'
and
perl -wle '
  @a = qx(who| cut -d\47 \47 -f1 | sort -u);
  chomp @a;
  print @a;
'

the above codes worked great with cut!!! but failed with awk and perl.

is this related to awk or perl version?

and when using below

Code:
perl -wle '
  @a = qx(who| cut -d' ' -f1 | sort -u);
  chomp @a;
  print @a;
'

the code failed.!!!
# 12  
Old 03-10-2010
Or, of course, as alister correctly pointed out, you need to close the external/escape the embedded single quotes. alister's solution works fine for me too:

Code:
perl -wle '
@a=`who| perl -wlane '\''print \$F[0];'\'' | sort -u` ;
chomp @a ;
print @a;
'



---------- Post updated at 09:14 PM ---------- Previous update was at 08:57 PM ----------

Quote:
Originally Posted by ahmad.diab
[...]
the above codes worked great with cut!!! but failed with awk and perl.

is this related to awk or perl version?

and when using below

Code:
perl -wle '
  @a = qx(who| cut -d' ' -f1 | sort -u);
  chomp @a;
  print @a;
'

the code failed.!!!
Could you post the exact code and output you get (just copy/paste from your terminal)?

Last edited by radoulov; 03-10-2010 at 04:38 PM..
# 13  
Old 03-10-2010
The following works fine for me.
Code:
$ perl -wle '
  @a = qx(who| cut -d'\'' '\'' -f1 | sort -u);
  chomp @a;
  print @a;
'

Perl isn't my area, but i would suggest that you take the perl code you're passing on the command line and place it in a file, then tell perl to interpret that file. If you still get an error, then it's likely that the problem is perl related. If that works fine, then you can be reasonably sure that the issue lies with your shell. Worst case scenario, install windows and code it in powershell Smilie

Best of luck,
Alister
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Perl execution commands

I don't know to debug the program todaylive.pl program. plz someone let me know what are the commands I need to know to debug the perl programs to find out the error on it. (3 Replies)
Discussion started by: ramkumar15
3 Replies

2. Shell Programming and Scripting

Execution problem

hi all, when i tried executing the script by giving following command $ sh test.sh <parameter> it shows the following output: <none> status code=0 Previously it was working fine.But now its showing this output. (1 Reply)
Discussion started by: sanjay mn
1 Replies

3. Shell Programming and Scripting

Execution problem unix commands in Perl CGI

I am trying to run SSH , mkdir and other unix commands using Perl CGI. But i am not able to Execute these commands. Please help me out !!!! SSH and mkdir is necessity for me. I will be thankful to you...!!!!! I am trying like: In perl CGI file i am writing like: @list = `ssh... (28 Replies)
Discussion started by: Navrattan Bansa
28 Replies

4. Programming

Perl script remote execution as another user

Hi gurus, I have a requirement where I need to remotely run a perl script as another user. Running the script locally as the required user is fine, however I need to su with the script due to filesystem permission issues. I do not want to update permissions on the remote server due to security... (5 Replies)
Discussion started by: melias
5 Replies

5. Programming

"execution problem with perl"

hi everyone, before stating my problem , i just want to say thanks in advance for the time and trouble taken:-) i am an newbie to perl programming, the problem is a text file needed to be parsed, i have looked over regular expressions and string matching but coudnt helped out.. the... (4 Replies)
Discussion started by: raghuraipur
4 Replies

6. Shell Programming and Scripting

Perl during execution???

Hi All, What happens when a Pelr script is executed.??(Jus like in C/C++ we have several stages like preprocessing,assembling,complining ,linkin',loadin'...) So similiarly In Perl we have something like compile pahse and run phase. but what exactly happens during its exec and what all... (3 Replies)
Discussion started by: Ranji Raj
3 Replies

7. Shell Programming and Scripting

Perl execution debugger

If this is the wrong forum, move it. It seemed like the best. Does anyone know of a perl thing that does the same thing as bash -x except for perl? I know I can output the information I want at the right times by actually putting that in the code, but it's harder... (2 Replies)
Discussion started by: killer54291
2 Replies

8. Shell Programming and Scripting

Give input to a perl script while execution

Hi, I have a perl script which prints me the epoch value of a specific date and time given.Now I want to proceed to a next step ie i want to give the input at the time of execution. I have to initialise the date and time values in the script before executing it.But now i want to give the date... (3 Replies)
Discussion started by: jyothi_wipro
3 Replies

9. Shell Programming and Scripting

Shell Command execution through PERL

Hi Guys, I wish to execute some shell commands through PERL. Here is what I desire to do 1) I wish to find list of directories in current working location 2) Then go in each directory and execute few commands like a) rm -rf *.log (Shell command) b) coreBuilder -f cb_tests.tcl (Some... (6 Replies)
Discussion started by: hardik_snps
6 Replies

10. Solaris

Solaris 10.5 perl and cron job execution problem

Hi, I want to run a crontab job on solaris 10.5. I have configured the crontab accordingly 10 * * * * /scripts/dbalter.pl >> /scripts/cronout.txt However this does not work .Then I go to /var/mail/root and find an error in the output: From root@myserver Wed Feb 4 17:02:00 2009... (1 Reply)
Discussion started by: sonu2die4
1 Replies
Login or Register to Ask a Question