<?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: help with script in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/help-with-script/m-p/4287148#M336248</link>
    <description>&lt;!--!*#--&gt;&amp;gt;There's a need to monitor a directory to see if a new file has been created and dropped there.&lt;BR /&gt;&lt;BR /&gt;Does the file get removed if it is processed?&lt;BR /&gt;If it gets removed you can just do:&lt;BR /&gt;while : ; do&lt;BR /&gt;   for file in directory/*; do&lt;BR /&gt;      process-file-here&lt;BR /&gt;   done&lt;BR /&gt;   sleep 60&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;&amp;gt;I don't think the script should be run as a cron job&lt;BR /&gt;&lt;BR /&gt;This would be the easiest.  You just need a way to prevent another copy from running.  It could look at ps(1) to see if there is another.</description>
    <pubDate>Wed, 15 Oct 2008 07:08:01 GMT</pubDate>
    <dc:creator>Dennis Handly</dc:creator>
    <dc:date>2008-10-15T07:08:01Z</dc:date>
    <item>
      <title>help with script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/help-with-script/m-p/4287147#M336247</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;I need the help of scripting gurus out there with this :&lt;BR /&gt;&lt;BR /&gt;There's a need to monitor a directory to see if a new file has been created and dropped there. If there is, I need this same script to run an application to process this file.&lt;BR /&gt;&lt;BR /&gt;How should I go about it? I don't think the script should be run as a cron job, but should be something (a daemon, maybe) in the background running all the time. &lt;BR /&gt;&lt;BR /&gt;I'm not at all familiar with shell scripts, would appreciate if someone point me in the right direction.&lt;BR /&gt;&lt;BR /&gt;At the same time, instead of shell script, would perl script be an alternate option ?&lt;BR /&gt;&lt;BR /&gt;Thanks in advance.</description>
      <pubDate>Wed, 15 Oct 2008 06:38:02 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/help-with-script/m-p/4287147#M336247</guid>
      <dc:creator>so.nimda</dc:creator>
      <dc:date>2008-10-15T06:38:02Z</dc:date>
    </item>
    <item>
      <title>Re: help with script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/help-with-script/m-p/4287148#M336248</link>
      <description>&lt;!--!*#--&gt;&amp;gt;There's a need to monitor a directory to see if a new file has been created and dropped there.&lt;BR /&gt;&lt;BR /&gt;Does the file get removed if it is processed?&lt;BR /&gt;If it gets removed you can just do:&lt;BR /&gt;while : ; do&lt;BR /&gt;   for file in directory/*; do&lt;BR /&gt;      process-file-here&lt;BR /&gt;   done&lt;BR /&gt;   sleep 60&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;&amp;gt;I don't think the script should be run as a cron job&lt;BR /&gt;&lt;BR /&gt;This would be the easiest.  You just need a way to prevent another copy from running.  It could look at ps(1) to see if there is another.</description>
      <pubDate>Wed, 15 Oct 2008 07:08:01 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/help-with-script/m-p/4287148#M336248</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2008-10-15T07:08:01Z</dc:date>
    </item>
    <item>
      <title>Re: help with script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/help-with-script/m-p/4287149#M336249</link>
      <description>&lt;!--!*#--&gt;I'd use cron.  It's the easiest and poses less issues.&lt;BR /&gt;&lt;BR /&gt;Along with Dennis's suggestion.  I looked more at the steps to finding a newer file.  Without using Perl etc.  &lt;BR /&gt;&lt;BR /&gt;I've attached a file with a simple script.&lt;BR /&gt;Note that this script will also search any Sub-Directories.  Don't know if that's an issue for you.&lt;BR /&gt;&lt;BR /&gt;Is simply lists the files to standard output.  You can adjust the script to redirect to a file.  Or in your cron entry you could redirect to a file.&lt;BR /&gt;&lt;BR /&gt;Cheers</description>
      <pubDate>Wed, 15 Oct 2008 07:45:45 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/help-with-script/m-p/4287149#M336249</guid>
      <dc:creator>OFC_EDM</dc:creator>
      <dc:date>2008-10-15T07:45:45Z</dc:date>
    </item>
    <item>
      <title>Re: help with script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/help-with-script/m-p/4287150#M336250</link>
      <description>Sorry meant to mention.  That script was written on Tru64.  The options to commands such as "date" and "find" may be different on your OS.&lt;BR /&gt;&lt;BR /&gt;So test it first you may have to change some syntax.&lt;BR /&gt;&lt;BR /&gt;Cheers</description>
      <pubDate>Wed, 15 Oct 2008 07:46:55 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/help-with-script/m-p/4287150#M336250</guid>
      <dc:creator>OFC_EDM</dc:creator>
      <dc:date>2008-10-15T07:46:55Z</dc:date>
    </item>
    <item>
      <title>Re: help with script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/help-with-script/m-p/4287151#M336251</link>
      <description>If you're curious about writing daemons here's a link to a snippet from an O'Reilly book that talks about it.&lt;BR /&gt;&lt;BR /&gt;But I don't recommend writing daemons if you're new to scripting on Unix.&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://www.unix.com.ua/orelly/unix/upt/ch38_11.htm" target="_blank"&gt;http://www.unix.com.ua/orelly/unix/upt/ch38_11.htm&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;Regards</description>
      <pubDate>Wed, 15 Oct 2008 08:06:57 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/help-with-script/m-p/4287151#M336251</guid>
      <dc:creator>OFC_EDM</dc:creator>
      <dc:date>2008-10-15T08:06:57Z</dc:date>
    </item>
    <item>
      <title>Re: help with script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/help-with-script/m-p/4287152#M336252</link>
      <description>&lt;!--!*#--&gt;Here's an example of something like that in perl. This not only monitors files that have been dropped here, but also files that have been removed.&lt;BR /&gt;&lt;BR /&gt;--8&amp;lt;---&lt;BR /&gt;#!/pro/bin/perl&lt;BR /&gt;&lt;BR /&gt;use strict;&lt;BR /&gt;use warnings;&lt;BR /&gt;&lt;BR /&gt;sub usage&lt;BR /&gt;{&lt;BR /&gt;    my $err = shift and select STDERR;&lt;BR /&gt;    print "usage: $0 [-t &lt;SEC&gt;]\n";&lt;BR /&gt;    exit $err;&lt;BR /&gt;    } # usage&lt;BR /&gt;&lt;BR /&gt;use Cwd;&lt;BR /&gt;use Getopt::Long qw(:config bundling nopermute passthrough);&lt;BR /&gt;my $wait = 1;&lt;BR /&gt;GetOptions (&lt;BR /&gt;    "help|?"    =&amp;gt; sub { usage (0); },&lt;BR /&gt;&lt;BR /&gt;    "t|w=i"     =&amp;gt; \$wait,&lt;BR /&gt;    ) or usage (1);&lt;BR /&gt;&lt;BR /&gt;sub current&lt;BR /&gt;{&lt;BR /&gt;    my %dir;&lt;BR /&gt;    opendir my $dh, "." or die "Cannot open .: $!\n";&lt;BR /&gt;    foreach my $e (readdir $dh) {&lt;BR /&gt;        (-f $e &amp;amp;&amp;amp; $e =~ m/\.xml$/) or next;&lt;BR /&gt;        $dir{$e} = [ "f", (stat $e)[7, 9, 10] ];&lt;BR /&gt;        }&lt;BR /&gt;    closedir $dh;&lt;BR /&gt;    \%dir;&lt;BR /&gt;    } # current&lt;BR /&gt;&lt;BR /&gt;my @state;&lt;BR /&gt;&lt;BR /&gt;sub state&lt;BR /&gt;{&lt;BR /&gt;    my ($state, $f, $d) = @_;&lt;BR /&gt;    my @date = localtime $d-&amp;gt;{$f}[2];&lt;BR /&gt;    my $date = sprintf "%4d-%02d-%02d %02d:%02d:%02d",&lt;BR /&gt;        1900 + $date[5], ++$date[4], @date[3,2,1,0];&lt;BR /&gt;    printf "%s %s %5d %s %s\n", $state, $d-&amp;gt;{$f}[0], $d-&amp;gt;{$f}[1], $date, $f;&lt;BR /&gt;    } # state&lt;BR /&gt;&lt;BR /&gt;my $prev = current;&lt;BR /&gt;my $cwd = getcwd ();&lt;BR /&gt;&lt;BR /&gt;while (1) {&lt;BR /&gt;    sleep ($wait);&lt;BR /&gt;    my $dir = current;&lt;BR /&gt;&lt;BR /&gt;    # Deleted files&lt;BR /&gt;    foreach my $f (sort keys %$prev) {&lt;BR /&gt;        exists $dir-&amp;gt;{$f} and next;&lt;BR /&gt;        state "DEL", $f, $prev;&lt;BR /&gt;        # Do something for deleted files here ...&lt;BR /&gt;        }&lt;BR /&gt;&lt;BR /&gt;    foreach my $f (sort keys %$dir) {&lt;BR /&gt;        if (exists $prev-&amp;gt;{$f}) {&lt;BR /&gt;            # Changed files&lt;BR /&gt;            $f =~ m/^\.+$/ || "@{$prev-&amp;gt;{$f}}" eq "@{$dir-&amp;gt;{$f}}" and next;&lt;BR /&gt;            state "CHG", $f, $dir;&lt;BR /&gt;            # Do something for changed files here ...&lt;BR /&gt;            }&lt;BR /&gt;        else {&lt;BR /&gt;            # New files&lt;BR /&gt;            state "NEW", $f, $dir;&lt;BR /&gt;            # Do something for new files here ...&lt;BR /&gt;            }&lt;BR /&gt;        }&lt;BR /&gt;&lt;BR /&gt;    $prev = $dir;&lt;BR /&gt;    }&lt;BR /&gt;--&amp;gt;8---&lt;BR /&gt;&lt;BR /&gt;Enjoy, Have FUN! H.Merijn&lt;/SEC&gt;</description>
      <pubDate>Wed, 15 Oct 2008 09:14:41 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/help-with-script/m-p/4287152#M336252</guid>
      <dc:creator>H.Merijn Brand (procura</dc:creator>
      <dc:date>2008-10-15T09:14:41Z</dc:date>
    </item>
    <item>
      <title>Re: help with script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/help-with-script/m-p/4287153#M336253</link>
      <description>Hi &lt;BR /&gt;&lt;BR /&gt;I have a script that checks for new "dump/ core files" if a new one is found an email is sent to some users. This email is only sent out ONCE.&lt;BR /&gt;Works a treat and its nice and simply. Hope it helps.&lt;BR /&gt;&lt;BR /&gt;#!/sbin/sh&lt;BR /&gt;# WARNING: Do not modify this script&lt;BR /&gt;# Author : Eric A .lipede&lt;BR /&gt;&lt;BR /&gt;###############################################&lt;BR /&gt;&lt;BR /&gt;ODIR="/VMD1/acudump"&lt;BR /&gt;DDIR="/hpuxsw/utilities/scratch/acudump"&lt;BR /&gt;DLIST="$DDIR/acudump_list_orig"&lt;BR /&gt;ELIST="$DDIR/email_list"&lt;BR /&gt;SCRATCH="$DDIR/acudump_scratch.$(date +%y%m%d)"&lt;BR /&gt;HEADER="$DDIR/header.$(date +%y%m%d)"&lt;BR /&gt;MACHINE=`uname -a | awk '{ print $2 }'`&lt;BR /&gt;GROUP="itops itdevelopment el"&lt;BR /&gt;&lt;BR /&gt;email()&lt;BR /&gt;{&lt;BR /&gt;export NAME="$MACHINE:Acuconnect dump monitor"&lt;BR /&gt;export USER="$MACHINE:Acuconnect dump monitor"&lt;BR /&gt;if [ $# -eq 2 ]&lt;BR /&gt;then&lt;BR /&gt;  cat  $2 | mailx -s "$1" $GROUP&lt;BR /&gt;else&lt;BR /&gt;  echo " " | mailx -s "$1" $GROUP&lt;BR /&gt;fi&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;check_original()&lt;BR /&gt;{&lt;BR /&gt;if [ ! -f $DLIST ]&lt;BR /&gt;then&lt;BR /&gt;  email "$DLIST not found - investigate"&lt;BR /&gt;  exit&lt;BR /&gt;fi&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;create_new_list()&lt;BR /&gt;{&lt;BR /&gt;ll $ODIR | grep -v  "\$mp" | grep rtf | awk '{ print $5"_"$8"_"$9 }' &amp;gt; $SCRATCH&lt;BR /&gt;if [ $? != 0 ]&lt;BR /&gt;then&lt;BR /&gt;  email "$SCRATCH creation failed - investigate"&lt;BR /&gt;  exit&lt;BR /&gt;fi&lt;BR /&gt;} &lt;BR /&gt;&lt;BR /&gt;compare_files()&lt;BR /&gt;{&lt;BR /&gt;cat $SCRATCH | while read&lt;BR /&gt;do&lt;BR /&gt; FILEINSCRATCH=`echo ${REPLY}`&lt;BR /&gt; if        &lt;BR /&gt;  !  grep $FILEINSCRATCH $DLIST &amp;gt; /dev/null 2&amp;gt;&amp;amp;1 &amp;amp;&amp;amp;&lt;BR /&gt;  !  grep $FILEINSCRATCH $ELIST &amp;gt; /dev/null 2&amp;gt;&amp;amp;1&lt;BR /&gt; then&lt;BR /&gt;   NEWFILE=$ODIR/`echo $FILEINSCRATCH | awk -F_ '{print $3}'` &lt;BR /&gt;   echo "Title:\t$NEWFILE"          &amp;gt;  $HEADER&lt;BR /&gt;   echo "Contents:\t 1st 100 lines" &amp;gt;&amp;gt; $HEADER&lt;BR /&gt;   head -100 $NEWFILE               &amp;gt;&amp;gt; $HEADER&lt;BR /&gt;   email "$MACHINE:Report - New Acuconnect exception file created: `echo ${REPLY} | awk -F_ '{print $3}'`" "$HEADER"&lt;BR /&gt;   if [ $? = 0 ]&lt;BR /&gt;   then&lt;BR /&gt;     echo $FILEINSCRATCH &amp;gt;&amp;gt; $ELIST&lt;BR /&gt;     rm $HEADER&lt;BR /&gt;   fi &lt;BR /&gt; fi&lt;BR /&gt;done&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;clean_up()&lt;BR /&gt;{&lt;BR /&gt;if [ -f $SCRATCH ]&lt;BR /&gt;then&lt;BR /&gt;  rm $SCRATCH&lt;BR /&gt;fi&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;# Start&lt;BR /&gt;&lt;BR /&gt;check_original&lt;BR /&gt;create_new_list&lt;BR /&gt;compare_files&lt;BR /&gt;clean_up&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;###########################&lt;BR /&gt;The email list (that contains unique entries so we dont get duplicate emails going out) looks like ...&lt;BR /&gt;1017_10:46_dump.8975.rtf&lt;BR /&gt;1024_10:46_dump.9008.rtf&lt;BR /&gt;1032_10:46_dump.27552.rtf&lt;BR /&gt;1045_10:46_dump.27631.rtf&lt;BR /&gt;1051_10:46_dump.7946.rtf&lt;BR /&gt;etc&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 15 Oct 2008 10:24:55 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/help-with-script/m-p/4287153#M336253</guid>
      <dc:creator>Eric Lipede</dc:creator>
      <dc:date>2008-10-15T10:24:55Z</dc:date>
    </item>
    <item>
      <title>Re: help with script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/help-with-script/m-p/4287154#M336254</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;@Dennis : thanks for the reply and the sample script. If it's to run as a crontab, how should the frequency be set? That's what stumped me. =(&lt;BR /&gt;&lt;BR /&gt;@Kevin : thanks for the reply and sample script and link to writing daemons (yes, I should refrain from that as a noob =)). Most helpful.&lt;BR /&gt;&lt;BR /&gt;@H.Merijn Brand (procura) : thanks for your reply and the sample perl script. It's an alternative.&lt;BR /&gt;&lt;BR /&gt;@Eric : thanks for your reply. The sample script was helpful, too! =)&lt;BR /&gt;</description>
      <pubDate>Thu, 16 Oct 2008 23:59:31 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/help-with-script/m-p/4287154#M336254</guid>
      <dc:creator>so.nimda</dc:creator>
      <dc:date>2008-10-16T23:59:31Z</dc:date>
    </item>
    <item>
      <title>Re: help with script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/help-with-script/m-p/4287155#M336255</link>
      <description>&lt;!--!*#--&gt;&amp;gt;If it's to run as a crontab, how should the frequency be set?&lt;BR /&gt;&lt;BR /&gt;How often does your system go down?&lt;BR /&gt;If it does go down, will someone remember to start this script up if it only restarts once a day?&lt;BR /&gt;&lt;BR /&gt;You may want it to restart every hour.&lt;BR /&gt;&lt;BR /&gt;How to check if already running:&lt;BR /&gt;base=$(basename $0)&lt;BR /&gt;running=$(UNIX95=EXTENDED_PS ps -C $base -opid= | wc -w)&lt;BR /&gt;if [ $running -gt 1 ]; then&lt;BR /&gt;   exit 0 # already running&lt;BR /&gt;fi</description>
      <pubDate>Fri, 17 Oct 2008 01:27:19 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/help-with-script/m-p/4287155#M336255</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2008-10-17T01:27:19Z</dc:date>
    </item>
  </channel>
</rss>

