<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Function calling another function in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/function-calling-another-function/m-p/3583682#M103676</link>
    <description>Pat,&lt;BR /&gt;&lt;BR /&gt;Where do I insert your piece into the code?</description>
    <pubDate>Fri, 15 Jul 2005 09:53:30 GMT</pubDate>
    <dc:creator>Mike Keys</dc:creator>
    <dc:date>2005-07-15T09:53:30Z</dc:date>
    <item>
      <title>Function calling another function</title>
      <link>https://community.hpe.com/t5/operating-system-linux/function-calling-another-function/m-p/3583678#M103672</link>
      <description>At the sake of simplifying code, I moved a transaction logging function it's own routine and am calling it through the actual transaction routines. However, the file is being created but nothing is being written. Here is a sample of a transaction function and the logging funciton.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;#######################################################################&lt;BR /&gt;#                         Remove a user                               #&lt;BR /&gt;#######################################################################&lt;BR /&gt;sub userdel {&lt;BR /&gt;   &lt;BR /&gt;   my $cmd = sprintf("/usr/sbin/userdel %s",$user);&lt;BR /&gt;   my $status = system($cmd);&lt;BR /&gt;   writetrans($cmd);&lt;BR /&gt;   return ($status);&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;#######################################################################&lt;BR /&gt;#                   Write transactions to file                        #&lt;BR /&gt;#######################################################################&lt;BR /&gt;sub writetrans {&lt;BR /&gt;&lt;BR /&gt;   my $tmpfile = "/home/ops/passwd.fil";&lt;BR /&gt;   my $trans = sprintf("%s \n",$cmd);&lt;BR /&gt;   open (TMPFILE,"&amp;gt;&amp;gt;$tmpfile"); # Write transactions to logfile&lt;BR /&gt;      print TMPFILE "$trans"; &lt;BR /&gt;   close (TMPFILE) || die "\nCould not write to file: $tmpfile:$!";&lt;BR /&gt;&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;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?</description>
      <pubDate>Fri, 15 Jul 2005 09:05:44 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/function-calling-another-function/m-p/3583678#M103672</guid>
      <dc:creator>Mike Keys</dc:creator>
      <dc:date>2005-07-15T09:05:44Z</dc:date>
    </item>
    <item>
      <title>Re: Function calling another function</title>
      <link>https://community.hpe.com/t5/operating-system-linux/function-calling-another-function/m-p/3583679#M103673</link>
      <description>It looks like your setting $cmd in one function and it will be locale to that function only. Two ways around it are;&lt;BR /&gt;&lt;BR /&gt;1) create global $cmd&lt;BR /&gt;2) change writetrans to;&lt;BR /&gt;&lt;BR /&gt;sub writetrans {&lt;BR /&gt;&lt;BR /&gt;my $cmd = $_;&lt;BR /&gt;&lt;BR /&gt;my $tmpfile = "/home/ops/passwd.fil";&lt;BR /&gt;my $trans = sprintf("%s \n",$cmd);&lt;BR /&gt;open (TMPFILE,"&amp;gt;&amp;gt;$tmpfile"); # Write transactions to logfile&lt;BR /&gt;print TMPFILE "$trans";&lt;BR /&gt;close (TMPFILE) || die "\nCould not write to file: $tmpfile:$!";&lt;BR /&gt;&lt;BR /&gt;}</description>
      <pubDate>Fri, 15 Jul 2005 09:16:45 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/function-calling-another-function/m-p/3583679#M103673</guid>
      <dc:creator>David Child_1</dc:creator>
      <dc:date>2005-07-15T09:16:45Z</dc:date>
    </item>
    <item>
      <title>Re: Function calling another function</title>
      <link>https://community.hpe.com/t5/operating-system-linux/function-calling-another-function/m-p/3583680#M103674</link>
      <description>&lt;BR /&gt;Which shell are you trying this, I believe it is not BASH, anyway Let us do a basic check:&lt;BR /&gt;&lt;BR /&gt;move the writetrans function before userdel function and see whether it solves the problem&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;Gopi&lt;BR /&gt;</description>
      <pubDate>Fri, 15 Jul 2005 09:17:32 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/function-calling-another-function/m-p/3583680#M103674</guid>
      <dc:creator>Gopi Sekar</dc:creator>
      <dc:date>2005-07-15T09:17:32Z</dc:date>
    </item>
    <item>
      <title>Re: Function calling another function</title>
      <link>https://community.hpe.com/t5/operating-system-linux/function-calling-another-function/m-p/3583681#M103675</link>
      <description>I had trouble with this before and it had to do with buffers not being flushed, so my log file was empty while the process was running.  You can force it to not cache the writes to your logfile by doing:&lt;BR /&gt;&lt;BR /&gt;$| = 1;&lt;BR /&gt;&lt;BR /&gt;That's a pipe symbol by the way.&lt;BR /&gt;&lt;BR /&gt;Hope this helps.&lt;BR /&gt;&lt;BR /&gt;-Pat Lieberg&lt;BR /&gt;Unix Systems Admin.&lt;BR /&gt;3M IT Operations</description>
      <pubDate>Fri, 15 Jul 2005 09:44:16 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/function-calling-another-function/m-p/3583681#M103675</guid>
      <dc:creator>Pat Lieberg</dc:creator>
      <dc:date>2005-07-15T09:44:16Z</dc:date>
    </item>
    <item>
      <title>Re: Function calling another function</title>
      <link>https://community.hpe.com/t5/operating-system-linux/function-calling-another-function/m-p/3583682#M103676</link>
      <description>Pat,&lt;BR /&gt;&lt;BR /&gt;Where do I insert your piece into the code?</description>
      <pubDate>Fri, 15 Jul 2005 09:53:30 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/function-calling-another-function/m-p/3583682#M103676</guid>
      <dc:creator>Mike Keys</dc:creator>
      <dc:date>2005-07-15T09:53:30Z</dc:date>
    </item>
    <item>
      <title>Re: Function calling another function</title>
      <link>https://community.hpe.com/t5/operating-system-linux/function-calling-another-function/m-p/3583683#M103677</link>
      <description>This is being done with Perl.</description>
      <pubDate>Fri, 15 Jul 2005 09:56:01 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/function-calling-another-function/m-p/3583683#M103677</guid>
      <dc:creator>Mike Keys</dc:creator>
      <dc:date>2005-07-15T09:56:01Z</dc:date>
    </item>
    <item>
      <title>Re: Function calling another function</title>
      <link>https://community.hpe.com/t5/operating-system-linux/function-calling-another-function/m-p/3583684#M103678</link>
      <description>So far suggestions mentioned do not work.</description>
      <pubDate>Fri, 15 Jul 2005 10:04:06 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/function-calling-another-function/m-p/3583684#M103678</guid>
      <dc:creator>Mike Keys</dc:creator>
      <dc:date>2005-07-15T10:04:06Z</dc:date>
    </item>
    <item>
      <title>Re: Function calling another function</title>
      <link>https://community.hpe.com/t5/operating-system-linux/function-calling-another-function/m-p/3583685#M103679</link>
      <description>&lt;BR /&gt;oops i am sorry, i better get some specs :)&lt;BR /&gt;&lt;BR /&gt;ok the problem looks like $cmd variable is local to the function userdel and is not reachable in writetrans function.&lt;BR /&gt;&lt;BR /&gt;modify writetrans function to get $cmd as command line argument.&lt;BR /&gt;&lt;BR /&gt;eg:&lt;BR /&gt;&lt;BR /&gt;sub writetrans {&lt;BR /&gt;&lt;BR /&gt;  my ($cmd) = @_;&lt;BR /&gt;&lt;OTHER statements="" as="" they="" are=""&gt;&lt;BR /&gt;&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;Gopi&lt;/OTHER&gt;</description>
      <pubDate>Fri, 15 Jul 2005 10:07:53 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/function-calling-another-function/m-p/3583685#M103679</guid>
      <dc:creator>Gopi Sekar</dc:creator>
      <dc:date>2005-07-15T10:07:53Z</dc:date>
    </item>
    <item>
      <title>Re: Function calling another function</title>
      <link>https://community.hpe.com/t5/operating-system-linux/function-calling-another-function/m-p/3583686#M103680</link>
      <description>Hey, now i'm getting zeros written to the file. Hooray!&lt;BR /&gt;</description>
      <pubDate>Fri, 15 Jul 2005 10:15:28 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/function-calling-another-function/m-p/3583686#M103680</guid>
      <dc:creator>Mike Keys</dc:creator>
      <dc:date>2005-07-15T10:15:28Z</dc:date>
    </item>
    <item>
      <title>Re: Function calling another function</title>
      <link>https://community.hpe.com/t5/operating-system-linux/function-calling-another-function/m-p/3583687#M103681</link>
      <description>what appears to be happening is that if I place the commands that are in writetrans(); into each transaction function, i get output just fine. yes, because the variable is local to that function. &lt;BR /&gt;&lt;BR /&gt;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?</description>
      <pubDate>Fri, 15 Jul 2005 10:31:33 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/function-calling-another-function/m-p/3583687#M103681</guid>
      <dc:creator>Mike Keys</dc:creator>
      <dc:date>2005-07-15T10:31:33Z</dc:date>
    </item>
    <item>
      <title>Re: Function calling another function</title>
      <link>https://community.hpe.com/t5/operating-system-linux/function-calling-another-function/m-p/3583688#M103682</link>
      <description>I tested the subroutines in my system and it is working as expected. Below are my changes to the function (note I modified program to make sure I dont delete any user in my system :)&lt;BR /&gt;&lt;BR /&gt;My system is Linux (Fedora Core 4), if this is not working on your system then it is more likely that the perl compiler you have is not working as expected&lt;BR /&gt;&lt;BR /&gt;Hope this helps,&lt;BR /&gt;Gopi&lt;BR /&gt;&lt;BR /&gt;sub userdel {&lt;BR /&gt;$user='/tmp';&lt;BR /&gt;my $cmd = sprintf("/bin/ls %s",$user);&lt;BR /&gt;my $status = system($cmd);&lt;BR /&gt;writetrans($cmd);&lt;BR /&gt;return ($status);&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;sub writetrans {&lt;BR /&gt;my ($cmd) = @_;&lt;BR /&gt;&lt;BR /&gt;my $tmpfile = "/tmp/passwd.fil";&lt;BR /&gt;my $trans = sprintf("%s \n",$cmd);&lt;BR /&gt;open (TMPFILE,"&amp;gt;&amp;gt;$tmpfile"); # Write transactions to logfile&lt;BR /&gt;print TMPFILE "$trans";&lt;BR /&gt;close (TMPFILE) || die "\nCould not write to file: $tmpfile:$!";&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Sat, 16 Jul 2005 01:35:24 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/function-calling-another-function/m-p/3583688#M103682</guid>
      <dc:creator>Gopi Sekar</dc:creator>
      <dc:date>2005-07-16T01:35:24Z</dc:date>
    </item>
  </channel>
</rss>

