- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: Function calling another function
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
Discussions
Discussions
Forums
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
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
тАО07-15-2005 02:05 AM
тАО07-15-2005 02:05 AM
Function calling another function
#######################################################################
# Remove a user #
#######################################################################
sub userdel {
my $cmd = sprintf("/usr/sbin/userdel %s",$user);
my $status = system($cmd);
writetrans($cmd);
return ($status);
}
#######################################################################
# Write transactions to file #
#######################################################################
sub writetrans {
my $tmpfile = "/home/ops/passwd.fil";
my $trans = sprintf("%s \n",$cmd);
open (TMPFILE,">>$tmpfile"); # Write transactions to logfile
print TMPFILE "$trans";
close (TMPFILE) || die "\nCould not write to file: $tmpfile:$!";
}
I am passing the $cmd to the transaction logging function (writetrans) and have tried everything I could think of to get this to work. What am I missing?
- Tags:
- Perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-15-2005 02:16 AM
тАО07-15-2005 02:16 AM
Re: Function calling another function
1) create global $cmd
2) change writetrans to;
sub writetrans {
my $cmd = $_;
my $tmpfile = "/home/ops/passwd.fil";
my $trans = sprintf("%s \n",$cmd);
open (TMPFILE,">>$tmpfile"); # Write transactions to logfile
print TMPFILE "$trans";
close (TMPFILE) || die "\nCould not write to file: $tmpfile:$!";
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-15-2005 02:17 AM
тАО07-15-2005 02:17 AM
Re: Function calling another function
Which shell are you trying this, I believe it is not BASH, anyway Let us do a basic check:
move the writetrans function before userdel function and see whether it solves the problem
Regards,
Gopi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-15-2005 02:44 AM
тАО07-15-2005 02:44 AM
Re: Function calling another function
$| = 1;
That's a pipe symbol by the way.
Hope this helps.
-Pat Lieberg
Unix Systems Admin.
3M IT Operations
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-15-2005 02:53 AM
тАО07-15-2005 02:53 AM
Re: Function calling another function
Where do I insert your piece into the code?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-15-2005 02:56 AM
тАО07-15-2005 02:56 AM
Re: Function calling another function
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-15-2005 03:04 AM
тАО07-15-2005 03:04 AM
Re: Function calling another function
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-15-2005 03:07 AM
тАО07-15-2005 03:07 AM
Re: Function calling another function
oops i am sorry, i better get some specs :)
ok the problem looks like $cmd variable is local to the function userdel and is not reachable in writetrans function.
modify writetrans function to get $cmd as command line argument.
eg:
sub writetrans {
my ($cmd) = @_;
}
Regards,
Gopi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-15-2005 03:15 AM
тАО07-15-2005 03:15 AM
Re: Function calling another function
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-15-2005 03:31 AM
тАО07-15-2005 03:31 AM
Re: Function calling another function
However, by placeing the commands within their own function, I am getting 0's written to the file. Could it be that the 'sprint' command is doing something odd when passing the variable by reference?