OS using: Linux(core 1), Solaris (5.6 to 5.8), Unix
Perl version: v5.8.5
I need to find the path or alias that the user used to execute the program with (aka $0), just like the built-in shell commands which or where, but using Perl.
Now if I just want the path I have found many ways to do that using things like: -
use Cwd qw(realpath);
-
my $exe_path = realpath($0);
-
print "\nYou are executing $exe_path.\n";
-
or -
use File::Which qw(which where);
-
my $exe_path = which($0);
-
or -
use Shell;
-
$exe_path = which("$0");
-
etc.....
But none of those work if the user had an alias. I can doing the following examples from the shells command line prompt and it gets what I want, but haven't been able to do the same thing from my Perl script.
Example:
PROMPT> where gp gp is aliased to egrep --color PROMPT> alias -p| /usr/bin/which -i -a gp gp egrep --color
/bin/egrep <--(this is what I really want) I would prefer the second case (alias -p| /usr/bin/which -i -a) since it gives you the path to the egrep that is being used, but its not absolute that I get that. I would just be happy if I got "gp is aliased to egrep --color". I also what to avoid having to parse through the .cshrc file of the user.
So does anyone know how to do what I want. At this point I'm thinking I may have to create some perl module thats written in another language to do what I want.
9 2924
OS using: Linux(core 1), Solaris (5.6 to 5.8), Unix
Perl version: v5.8.5
I need to find the path or alias that the user used to execute the program with (aka $0), just like the built-in shell commands which or where, but using Perl.
Now if I just want the path I have found many ways to do that using things like: -
use Cwd qw(realpath);
-
my $exe_path = realpath($0);
-
print "\nYou are executing $exe_path.\n";
-
or -
use File::Which qw(which where);
-
my $exe_path = which($0);
-
or -
use Shell;
-
$exe_path = which("$0");
-
etc.....
But none of those work if the user had an alias. I can doing the following examples from the shells command line prompt and it gets what I want, but haven't been able to do the same thing from my Perl script.
Example:
PROMPT> where gpgp is aliased to egrep --color PROMPT> alias -p| /usr/bin/which -i -a gpgp egrep --color
/bin/egrep <--(this is what I really want) I would prefer the second case (alias -p| /usr/bin/which -i -a) since it gives you the path to the egrep that is being used, but its not absolute that I get that. I would just be happy if I got "gp is aliased to egrep --color". I also what to avoid having to parse through the .cshrc file of the user.
So does anyone know how to do what I want. At this point I'm thinking I may have to create some perl module thats written in another language to do what I want.
First, when posting, please be sure and be clear. There seem to be so many thoughts in this posting that it is hard to truly decipher what it is you want.
As far as having to cycle through the users .cshrc or whatever other type of dot file, I doubt there will be a way around that. That is where users set their environment up, define functions, set aliases, etc. Unless you are logged in as that user and can type "alias" as them, there would not be another way that I know of.
Regards,
Jeff
First, when posting, please be sure and be clear. There seem to be so many thoughts in this posting that it is hard to truly decipher what it is you want.
Jeff
Sorry about not being clear. I just want the path to the file the user typed in to execute my script. The problem has been some people use aliases instead, so I don't get the path to the file that was being executed. The script will be executed by the user from there home account.
The reason I need this information is to find rogue/forked copies of my script and log the output to a log file that I can audit.
prn 254
Expert 100+
I'm not sure whether it's a language problem or what, but I have no idea at all what you are looking for.
I have created the following file (called mypath): - #! /usr/bin/perl
-
use strict;
-
print "You are executing $0 \n";
On Linux (Fedora Core 6), in bash, I run - $ alias shmoo='mypath'
-
$ shmoo
-
You are executing /home/prn/perltest/mypath
On Solaris 9, (c shell, since Bourne shell does not do alias), I run: - % alias shmoo '/export/home/prn/mypath'
-
% shmoo
-
You are executing /export/home/prn/mypath
So, what did you want?
Best Regards,
Paul
I'm not sure whether it's a language problem or what, but I have no idea at all what you are looking for.
I have created the following file (called mypath): - #! /usr/bin/perl
-
use strict;
-
print "You are executing $0 \n";
On Linux (Fedora Core 6), in bash, I run - $ alias shmoo='mypath'
-
$ shmoo
-
You are executing /home/prn/perltest/mypath
On Solaris 9, (c shell, since Bourne shell does not do alias), I run: - % alias shmoo '/export/home/prn/mypath'
-
% shmoo
-
You are executing /export/home/prn/mypath
So, what did you want?
Best Regards,
Paul
I think that he is looking to resolve the aliases for commands that other users have executed and that he sees running in "ps". He would not have a way to really know what the aliases are unless he was sourced into their dot file or logged in as them, I believe.
Regards,
Jeff
Well after many hours of google searches and banging away at the keyboard, it doesn't appear to be a good clean way. I will parse through the users .cshrc (C shell file) for aliases and do a which command and do some fancy comparison. That will be the only way to catch 98% of the cases.
I'm just really surprised that there was no way to read in a users aliases from a script in any language that I could find.
Well after many hours of google searches and banging away at the keyboard, it doesn't appear to be a good clean way. I will parse through the users .cshrc (C shell file) for aliases and do a which command and do some fancy comparison. That will be the only way to catch 98% of the cases.
I'm just really surprised that there was no way to read in a users aliases from a script in any language that I could find.
Actually, I am not so suprised. Even in Unix itself you would have to be logged in as that user or have sourced their .cshrc file in order to know what their aliases are. This, to me, sounds like a good project for a module.
Regards,
Jeff
... Even in Unix itself you would have to be logged in as that user ....
Regards,
Jeff
That wouldn't be a problem, since the "user" will be the one running the script. So basically it would be logged in as that user.
That wouldn't be a problem, since the "user" will be the one running the script. So basically it would be logged in as that user.
Well, if it is part of the script that the user is running, then just do an:
and it will return what it is triggering.
Regards,
Jeff
When I was testing that out it didn't seem to work at all and just kept giving me errors about not finding command alias.
Since we are running older versions of Linux (Red Hat 4) & Solaris (5.6 or 5.8), I believe that we are just missing updates that allow it to work.
Thanks
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Xah Lee |
last post by:
suppose you want to do find & replace of string of all files in a
directory.
here's the code:
©# -*- coding: utf-8 -*-
©# Python
©
©import os,sys
©
©mydir= '/Users/t/web'
|
by: John Bailo |
last post by:
I have created several aliases to members using the CREATE ALIAS
command, but I lost track of them.
Now I want to see a catalog of all the aliases mapped to all members in
a FILE.
Is there a...
|
by: haylow |
last post by:
Hi
I am new to ASP.NET and am working on an application that runs on a
webserver. The user will open up the web interface in a browser on
their local machine and enter a path to a directory. I...
|
by: PC Datasheet |
last post by:
Transaction data is given with date ranges:
Beginning End
4/1/06 4/4/06
4/7/06 4/11/06
4/14/06 4/17/06
4/18/06 4/21/06
426/06 ...
|
by: amir |
last post by:
Hi,
When compiling a page in VS2005 this morning I received 101 messages
regarding schema problems in my web.config file.
When I go to view an aspx page in my IIS, IE just displays a blank...
|
by: Sandra-24 |
last post by:
Comparing file system paths as strings is very brittle. Is there a
better way to test if two paths point to the same file or directory
(and that will work across platforms?)
Thanks,
-Sandra
|
by: nimjerry |
last post by:
i am using db2 udb V 9 on aix 5.3 and in db2diag.log alwas has this error occurr
below is sample message
2008-03-03-09.45.34.366406+420 I306667A443 LEVEL: Warning
PID : 835622 ...
|
by: sweavo |
last post by:
Hi all,
(Python 2.5 under cygwin)
I'm reading a bunch of XML files and merging them in memory - each file contains a number of packages which are to be merged:
for fname in gInfiles:
...
|
by: jacob navia |
last post by:
Hi
We are rewriting the libc for the 64 bit version of lcc-win
and we have added a new field in the FILE structure:
char *FileName;
fopen() will save the file name and an accessor function
will...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |