- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: ksh scripting to perl
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2005 02:26 AM
09-07-2005 02:26 AM
following from ksh script.
owner=`ll t | awk '{print $3}'`
cat data.file | mailx -s "Data" $owner
I am not having much luck and cannot find
any examples in the book to do the equivalent.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2005 02:39 AM
09-07-2005 02:39 AM
Solution$owner = `ls -l t |awk'{print $3}';
`cat data.file |mailx -s "Data" $owner`;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2005 02:43 AM
09-07-2005 02:43 AM
Re: ksh scripting to perl
perl -e '$uid=(stat "x")[4]; $name=getpwuid $uid; open OU,"|mailx -s Data $name"; open IN,"
Here I started the mail process through an open, piping data into it.
Alternatives are 'system()', fork, backtick,....
hth,
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2005 03:54 AM
09-07-2005 03:54 AM
Re: ksh scripting to perl
in the commands as you described. But for
some reason the "awk" part does not get
executed and I end up with $owner being the
total line from the "ll" command and mailx
trying to send to each field listing from
the "ll" listing.
Hein van den, Your syntax does not show
any errors but it does not do anything.
I did change x to t for file name.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2005 04:12 AM
09-07-2005 04:12 AM
Re: ksh scripting to perl
I think Hein meant something like:
# perl -e '$x="/etc/hosts";$uid=(stat $x)[4];$name=getpwuid $uid;open OU,"|mailx -s Data $name";open IN,"<",$x;print OU $_ while
...or slightly more generalized to use a filename as an argument:
# perl -e '$uid=(stat $ARGV[0])[4];$name=getpwuid $uid;open OU,"|mailx -s Data $name";open IN,"<",$ARGV[0];print OU $_ while
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2005 04:13 AM
09-07-2005 04:13 AM
Re: ksh scripting to perl
foreach $LINE (`ls -l *.dat`) {
chomp $LINE;
@LINE = split " ", $LINE;
`cat $LINE[8] |mailx -s Data $LINE[2]`;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2005 04:20 AM
09-07-2005 04:20 AM
Re: ksh scripting to perl
Jerry, Hein's original solution DID WORK just fine if you merely substitute the name of your file for "x". My first cut-and-paste of it mangled it. The credit is his!
Regards!
...JRF...
/* no points please */
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2005 05:20 AM
09-07-2005 05:20 AM
Re: ksh scripting to perl
James is correct, I (over?) simplified the example to test for and send out the same file called "x". I assumed you needed changes anyway to pass in particular file names.
A little more clear perhpas by spreading it out in a script, and using your file names:
(untested)
$uid=(stat "t")[4];
$name=getpwuid $uid;
open OU,"|mailx -s Data $name";
open IN,"
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2005 08:12 AM
09-07-2005 08:12 AM
Re: ksh scripting to perl
'$uid=(stat "x")[4]; $name=getpwuid $uid; open OU,"|mailx -s Data $name"; open IN,"
did not work for me is because of the begin
' and end '
When I took them out it worked.
It's back to the perl books. I have been
assimilated by ksh too long.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-08-2005 02:22 AM
09-08-2005 02:22 AM
Re: ksh scripting to perl
It runs but I am getting this error message
on one line. The line is:
my $name=getpwuid ($uid);
The error message is:
Use of uninitialized value in getpwuid at script1 line 33.
Why??
The script is enclosed if anyone wants to
use it, look at it. The code given by all
here was used in a script I wrote using the perl Net::FTP module.
It was the only was I could trap error messages.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-08-2005 03:24 AM
09-08-2005 03:24 AM
Re: ksh scripting to perl
#!/usr/bin/perl
use strict;
use warnings;
No script enclose as far as I can see
Enjoy, Have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-08-2005 03:49 AM
09-08-2005 03:49 AM
Re: ksh scripting to perl
trying to enclose again.
#!/usr/bin/perl
use strict;
use warnings;
use Net::FTP;
use Net::Netrc;
my $server="host1";
my $file="data.file";
my $destination = "/";
my $pageid = "admins";
my $pager = "/usr/local/bin/pager";
my $ftpid = "user2";
my $pass = "xyzzy";
my $ftp = Net::FTP->new ($server, Timeout => 9000, Debug => 3) or die (exec "$pager $pageid \"$server: ftp AP cannot connect: $@\"") ;
$ftp->login("$ftpid","$pass") or die (exec "$pager $pageid \"ftp AP cannot login.\"") ;
$ftp->binary or die (exec "$pager $pageid \"ftp AP failed binary mode.\"") ;
$ftp->cwd ($destination) or die (exec "$pager $pageid \"ftp AP failed cwd.\"") ;
$ftp->put ($file) or die (exec "$pager $pageid \"ftp AP cannot put file. \"") ;
$ftp->quit;
my $date = "date +%Y%m%d%H%M";
my $uid=(stat "originalfile.$date")[4];
my $name=getpwuid ($uid);
open OU,"|mailx -s \"AP file sent to Citibank\" $name"; open IN,"data.file"; print OU $_ while
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-08-2005 04:07 AM
09-08-2005 04:07 AM
Re: ksh scripting to perl
my $uid = (stat "originalfile.$date")[4];
my $name = getpwuid $uid;
if "originalfile.$date" does not exist, a stat () call on it will return undef in the user field, so maybe you will need to bail out if the file does not exist at all and then find out *why* it does not exist
my $date = "date +%Y%m%d%H%M";
my $org_file = "originalfile.$date";
-f $org_file or die "$org_file does not exist";
my $uid = (stat $org_file)[4];
my $name = getpwuid $uid;
or maybe you just wanted to stat () on $file instead
Enjoy, Have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-08-2005 04:41 AM
09-08-2005 04:41 AM
Re: ksh scripting to perl
I took out %H%M from $date =
And touched a file ttt.`date +%Y%m%d`
But it still gives me the error:
Use of uninitialized value in getpwuid at aa line 33.
If I just touch the file name ttt and
change the code to only have ttt in:
my $uid = (stat "ttt")[4];
It works.
It has something to do with .$date in:
my $uid = (stat "ttt.$date")[4];
??
Does anyone know how to run debug with -d
-w. I can't seen to get anything meaningful
from it?
I can't get anything enclosed also in these
posts. I use Browse and open the file. It
shows G:\script1 in the attachment box but
does not get posted. Any clues for the clueless here?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-08-2005 04:45 AM
09-08-2005 04:45 AM
Re: ksh scripting to perl
You need to use back-ticks to surround your date; not double quote marks. Thus:
my $ date = `date +%Y%m%d%H%M`;
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-08-2005 05:12 AM
09-08-2005 05:12 AM
Re: ksh scripting to perl
Unsuccessful stat on filename containing newline at script1 line 32.
Use of uninitialized value in getpwuid at script1 line 33.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-08-2005 05:34 AM
09-08-2005 05:34 AM
Re: ksh scripting to perl
my $date = `date +%Y%m`;
chomp $date;
my $uid=(stat("/tmp/stuff.200509"))[4];
Note the 'chomp' of the newline delivered back from the 'date()'. That fixes stat() complaining.
Note the additional parentheses for the list context of the slice. That allows a value to be returned to $uid which then satisfies getpwuid().
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-08-2005 05:54 AM
09-08-2005 05:54 AM
Re: ksh scripting to perl
Oops, forget my addition of the additional parenthesis with the stat() call. The 'chomp' fixes both of your errors!
Regards!
...JRF...
/* no points for this correction */
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-08-2005 06:23 AM
09-08-2005 06:23 AM
Re: ksh scripting to perl
Thanks James.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-08-2005 07:08 AM
09-08-2005 07:08 AM
Re: ksh scripting to perl
is not very perlish
Perl has two native ways:
my @date = localtime;
my $date = sprintf "%4d%02d%02d%02d%02d", $date[5] + 1900, $date[4] + 1, @date[3,2,1];
or
use POSIX qw( strftime );
my $date = strftime ("%Y%m%d%H%M", localtime);
the first is completely native and most likely the fastest.
Neither needs chomp :)
Enjoy, Have FUN! H.Merijn