Thread Unterschiedliche Funktionen bei Console und Shell Ausführung (2 answers)
Opened by kami at 2010-03-31 14:32

topeg
 2010-03-31 17:34
#135536 #135536
User since
2006-07-10
2611 Artikel
BenutzerIn

user image
Das Perlscript überarbeitet:
Code (perl): (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/perl

use strict;
use warnings;
use Getopt::Long;
use File::Copy;
use File::Spec;
use File::Glob ':glob';

my $test='';
my $testdir='/home/kami/test';
my $test2dir='/home/kami/test2';
my $infofile='/home/kami/scripts/test.txt';
GetOptions(
    'test=s'      => \$test,
    'source_dir=s'=> \$testdir,
    'dest_dir=s'  => \$test2dir,
    'info_file=s' => \$infofile,
) or die("unbekannte Option!");


my $verzeichnis=File::Spec->join($downloaddir, $test);
my $test_check=File::Spec->join($testdir, '*.test');


for $source_path (bsd_glob($test_check))
{
  if(-f $source_path)
  {   
    my (undef,undef,$file) = File::Spec->splitpath( $source_path );
    my $dest_path=File::Spec->join($test2dir, $file);

    warn "oeffne jetzt die datei $file2";
    open(my $fh, '>>' $infofile) or die "unable to open $infofile $!";
    print $fh $source_path." ==> ".$dest_path."\n";
    close($fh);
    move($source_path,$dest_path) or die("ERROR move($source_path,$dest_path) $!\n");
  }
}


wo kommt in deinem shellscript "$hash" her?
und was machst du am da am ende? Willst du nur die Noch nicht 100% haben bekommen? oder die die 100% haben? Ich bin da etwas verwirrt. Das scheint mir sehr kompliziert gelöst...

Hier mal meine vermutete Umsetzung in perl. In perl verstehe ich einfach besser was passiert und was passieren soll.

Code (perl): (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/perl
use strict;
use warnings;

my $FILEPATH="/home/kami/info";
my $NOTIFY_FILE="$FILEPATH/notified";

my $cmd_list='calltest -l';
my $cmd_info='calltest -t "%s" -i';

my $cmd_pl1=q(/home/kami/scripts/checkfiles.pl -test="%s");
my $cmd_pl2=q(/home/kami/scripts/prowl.pl -application=test -event=test -notification="%s");


my %seen_files=();
my %notify_files=();
my %not_notify_files=();

$notify_files{$_}++ for(read_file($NOTIFY_FILE));

for my $line (qx($cmd_list))
{
  next if $line=~/^(?:Sum|ID)/;
  my ($id,$percent)=split(/\s+|:|,|;/,$line); # keine Ahnung wecher Separator das nun ist...

  my $name='';

  $cmd=sprintf($cmd_info,$id);
  for my $info (qx($cmd))
  {
    $name=$1 if($info=~/^  Name...(.+)/);
  }

  if(!$notify_files{$name} && $percent eq '100%' )
  {
    # könntest du nun auch als Funktionen einbinden
    # das wäre schneller und sicherer
    # zudem ist dann die fehlersuche einfacher
    my $cmd1=splrintf($cmd_pl1,$name);
    system($cmd1)==0 or die("ERROR $cmd1\n");

    my $cmd2=splrintf($cmd_pl2,$name);
    system($cmd2)==0 or die("ERROR $cmd2\n");
    $notify_files{$name}++
  }
  else
  { $not_notify_files{$name}++; }

  $seen_files{$name}++;
}

write_file($NOTIFY_FILE,sort keys(%notify_files));


###############################################################

sub read_file
{
  my $file=shift;
  my @list=();
  open(my $fh,'<',$file) or die ("ERROR open $file ($!)");
  while(<$fh>)
  {
    chomp($_);
    push(@list,$_);
  }
  close($fh);
  return @list;
}

sub write_file
{
  my $file=shift;
  my @list=@_;
  open(my $fh, '>', $file) or die("ERROR open $file ($!)");
  print $fh "$_\n" for(@list);
  close($fh);
}

View full thread Unterschiedliche Funktionen bei Console und Shell Ausführung