script unexpectedly terminating


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting script unexpectedly terminating
# 1  
Old 06-10-2008
script unexpectedly terminating

I now that this isnt the greatest code around. Im a network guy by trade not a programer .. but needed something to compare config files ...
Anyway ... intermittently, the program terminates.

Ive been looking at the code for a week trying to figure it out and Im stumped. Can anyone provide input. Thanks.



use English;
require Tk;
use Tk;
use Cwd;

#perl2exe_include "Tk/Text.pm"
#perl2exe_include "Tk/Scrollbar.pm"
#
$stim = localtime($^T);
$userName = $ENV{'USERNAME'};
my $main = MainWindow ->new;


$main->minsize(qw(275 120));
$main->configure(-title => 'MSD File Compare',
-background => 'black');
$main->geometry('+15+25');

#build main body
my $top = $main->Frame(-background => 'black',
)->pack(-side =>'top', -fill => 'x');
my $left1 = $top->Frame(-background=>'black',)->pack
(-side => 'left', -pady => 1, -padx => 9);
my $t1 = $left1->Label(-text => '', -foreground=> 'white',
-background=>'black')->pack();

#Get Files buttons/place status label
my $t1 = $left1->Button(-text => 'Get File One', -foreground=> 'white',
-background=>'blue', -command => [\&gfil1],)->pack();
my $t1 = $left1->Button(-text => 'Get File Two', -foreground=> 'white',
-background=>'blue', -command => [\&gfil2],)->pack();
my $left2 = $top->Frame(-background=>'black')->pack
(-side => 'left', -pady => 2, -padx =>15);
my $filloc = $left2->Label(-text=>'File Location and name',
-foreground=>'white', -background=>'black')->pack();
#
#File input fields
$filename = $left2->Entry(-textvariable => \$filnam1, -background=>'blue',
-foreground=> 'white',-width=>20, -borderwidth=>6, -relief=>'sunken')->pack();
$filename2 = $left2->Entry(-textvariable => \$filnam2,-background=>'blue',
-foreground=> 'white', -width=>20, -borderwidth=>6, -relief=>'sunken')->pack();
#
#build separator
my $lin=$main->Frame(-borderwidth=> 4, -relief=>'groove',
-background=>'blue')->pack(-side=>'top');
my $stat=$lin->Label (-width=>80, -height=>0,-foreground=>'white',
-background=>'blue', -anchor => 'n')->pack();
$stat->configure(-text=>"Status Display");

#set up frame to show results
my $fr1 = $main->Frame(-width => 250, -height => 280);
$fr1->pack;
my $text = $fr1->Scrolled("Text")->pack( );
$text->insert('end', "\t- V1.4\n");
$text->insert('end', "\t\n");
$text->insert('end', "\t$^O $stim $userName\n\n");
#
#Do check File1 to file2 button1
$main->Button(-text => 'Compare File One->File Two', -background=> 'blue',
-foreground=> 'white',
-command => sub{runit($filename, $filename2)},
)->pack(-side => 'left');
#Do check Finish-Start button3
$main->Button(-text => 'Compare File Two->File One', -background=> 'blue',
-foreground=> 'white',
-command => sub{runit3($filename, $filename2)}

)->pack(-side => 'left');
#Do clear button
$main->Button(-text => 'Clear Output',-background=> 'blue',
-foreground=> 'white',
-command => \&clear_output
)->pack(-side => 'left');
#
#Exit Button
$main->Button(-text => 'Quit', -background=> 'blue',
-foreground=> 'white',
-command => [$main => 'destroy']
)->pack(-side => 'right');
#
MainLoop;

#
sub runit {
my ($file1, $file2) = @_;
my $file1_val = $file1->get;
my $file2_val = $file2->get;
open (FILE1, "$file1_val") or die;
open (FILE2, "$file2_val") or die;
@xray=<FILE2>;
# take care of white space put in by router.
for ($i=0; $i<@xray; $i++) {
$xray[$i] =~ s/\s+//g;
$xray[$i] =~ s/\s+$//g;
push (@clean2, $xray[$i]);
}
$text->insert('end', "\nFile One to File Two Comparison.\n");
$text->insert('end', "Lines in the push config missing from the device config:\n");
$text->insert('end', "* * * * * * * * * * * * * * * * * * * * * * * * * * * * * \n");
for $line (<FILE1>) {
$house=$line;
$line =~ s/\s+//g;
$line =~ s/\s+$//g;
if (!(grep $line eq $_, @clean2)) {
$text->insert('end', "$house");
}
}
close FILE1;
close FILE2;
}
#
sub runit3 {
my ($file1, $file2) = @_;
my $file1_val = $file1->get;
my $file2_val = $file2->get;
open (FILE1, "$file1_val") or die;
open (FILE2, "$file2_val") or die;
@xray1=<FILE1>;
# take care of white space put in by router.
for ($i=0; $i<@xray1; $i++) {
$xray1[$i] =~ s/\s+//g;
$xray1[$i] =~ s/\s+$//g;
push (@clean, $xray1[$i]);
}
$text->insert('end', "\nFinish to Starting Comparison.\n");
$text->insert('end', "Lines in the Finish config not in the Starting config:\n");
$text->insert('end', "* * * * * * * * * * * * * * * * * * * * * * * * * * * * \n");
for $line (<FILE2>) {
$house2=$line;
$line =~ s/\s+//g;
$line =~ s/\s+$//g;
if (!(grep $line eq $_, @clean)) {
$text->insert('end', "$house2");
}
}
close FILE1;
close FILE2;
}
#
sub gfil1 {
$filnam1 = $main->getOpenFile(-title => "Select File One");
}
#
sub gfil2 {
$filnam2 = $main->getOpenFile(-title => "Select File Two");
}
#
sub clear_output {
$text->configure(-state => 'normal');
$text->delete('1.0', 'end');
}
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

tcsh: how to prevent a foreach from terminating a script when the result is null?

Sorry if this has been answered. I did search both Google and this site and did find this post: unix.com/unix-dummies-questions-answers/152992-how-ignore-errors-script.html However, it wasn't answered. I have the same question - how do you prevent a tcsh script from terminating when the... (4 Replies)
Discussion started by: deepstructure
4 Replies

2. Shell Programming and Scripting

AIX-ksh script ends unexpectedly

Hi, I have a ksh script running on AIX 5.3 which has sometimes a bizarre behaviour. The script runs a child script like follow. trap 'rm -f /tmp/res.log;exit 0' 2 15 run_child.sh > /tmp/res.log 2>&1 echo "run_child.sh is terminated" next instructions... rm -f /tmp/res.log ... (12 Replies)
Discussion started by: rivalgro
12 Replies

3. UNIX for Advanced & Expert Users

why the script is not terminating with proper results

Hi everyone, I am new to the linux.I wrote a small script and assigning two values to fname and lname and I want if the fname or lname are not given proper name like Toys or Gun the script should terminate and if they are given proper name it should execute.please help thanks:wall: #!/bin/bash... (4 Replies)
Discussion started by: starter2011
4 Replies

4. Shell Programming and Scripting

How can i terminating expect script without terminating SSH connection.

Hi all , i know i ask a lot of question but these are really hard to solve and important question. I send two scripts: expect.sh: #!/usr/local/bin/expect spawn ssh root@172.30.64.163 expect "login:" send "root\n" expect "password:" send "root\n^M" interact and son.sh: ... (2 Replies)
Discussion started by: fozay
2 Replies

5. Shell Programming and Scripting

how to terminate ssh connection without terminating script

Hi all, I connect with SSH connection to remote machine in the script and ı want to logout at half of the script then continue to script. If ı write exit in the script it terminates script not SSH connection. How can i do that please help me (1 Reply)
Discussion started by: fozay
1 Replies

6. Shell Programming and Scripting

nohup terminating

hi all, i m running few batch process through shell script using nohup command but when session get terminated(due to network, reboot of desktop and closing session directly) all processes terminating abnormally and core file is generating. application batch process is connecting oracle... (4 Replies)
Discussion started by: arvindng
4 Replies

7. HP-UX

Terminating Processes by Name

Hi! Just want to know if there is one command that I can use to kill processes by its name. Thanks. (1 Reply)
Discussion started by: love833
1 Replies

8. UNIX for Dummies Questions & Answers

Terminating child script with terminating the parent script

Hi I was working on a shell script with randomly shows a page of text from a randomly selected topic .As soon as the page is displayed it callers a timer script which keeps on running indefinitely until the timer script is killed by the user. This is where I have the problem,if I press... (2 Replies)
Discussion started by: mervin2006
2 Replies

9. Shell Programming and Scripting

terminating script with CTRL+D

Hi, I'm trying to make a script that reads the console input and terminates with CTRL+D. It's absolutely basic but I don't know how to "read" the CTRL+D. I've tried a bunch of things like EOT=^D while //with & without quotations do read input echo $input done while while ] ... (12 Replies)
Discussion started by: sanchopansa
12 Replies

10. UNIX for Dummies Questions & Answers

Terminating myself

just like what the subject said but the ip is different example if now my IP is 192.168.0.50 and my name is seed if i wanna terminate 192.168.0.55 with the same nick of mine, seed can i do that ?? and what is the command ?? (2 Replies)
Discussion started by: SeeD
2 Replies
Login or Register to Ask a Question