1834149 Members
2284 Online
110064 Solutions
New Discussion

Re: Ksh in backgroung

 
Ricardo Bassoi
Regular Advisor

Ksh in backgroung


Hi All,

One more time I need your help. 2 Questions:

1-In the ksh at the attachment I??d like to get the vars ( file_exit and interval ) and put the script as a background job
2- Covert this ksh to perl ?
If you never try, never will work
10 REPLIES 10
harry d brown jr
Honored Contributor

Re: Ksh in backgroung


if [ "$1" -eq "" ]; then
read file_exit?" Please inform the output file: "
else
file_exit = $1
fi
if [ "$2" -eq "" ]; then
read interval?" Please inform the interval [ in seconds ]: "
else
interval = $2
fi


Then:

nohup scriptname.ksh outputfilename interval &


live free or die
harry
Live Free or Die
harry d brown jr
Honored Contributor

Re: Ksh in backgroung

ksh to perl?


#!/usr/contrib/bin/perl
#
clear;
if ( "$ARGV[0]" eq "" ) {
print " Please inform the output file: ";
chomp($file_exit = );
} else {
$file_exit = $ARGV[0];
}
if ( "$ARGV[1]" eq "" ) {
print "Please inform the interval [ in seconds ]: ";
chomp($interval = );
} else {
$interval = $ARGV[1];
}
print "\n";
while (1) {
$i=0;
while ( $i < 1 ) {
$dia=`date +"%D"`;
$hora=`date +"%H:%M:%S"`;
`srvman -l|grep App > app.lst`;
`srvman -l|grep TOTAL > total.lst`;
$var_system=`cut -c 39,40,41,42 app.lst`;
$var_mem=`cut -c 39,40,41,42,43,44 total.lst`;
$var_caps=`cut -c 58,59,60,61,62 total.lst`;
`echo "Day=>${dia} Time=>${hora} System=>${var_system} Memory=>${var_mem}
Caps=>${var_caps}" | tee -a $file_exit`;
$i += 1;
}
sleep $interval;
}
exit 0;


live free or die
harry
Live Free or Die
Rodney Hills
Honored Contributor

Re: Ksh in backgroung

Here is another perl program that doesn't need to do so many "forks".

#!/usr/bin/perl
die "Must supply file name!" unless $file_exit=$_[1];
$interval=$_[2];
$interval=60 unless $interval;
while(1) {
($sec,$min,$hr,$mday,$mon,$yr,$wday,$yday,$isdst)=localtime(time());
$mon++; $yr=substr($yr,-2);
$dia="$mon/$mday,$yr"; $hora="$hr:$min:$sec";
open(INP,"srvman -l|");
while() {
/App/ && do {
$var_system=substr($_,38,4);
}
/TOTAL/ && do {
$var_mem=substr($_,38,6);
$var_caps=substr($_,57,5);
}
}
close(INP);
print "Day=>$dia Time=>$hora System=>$var_system Memroy=>$var_mem Caps=>$var_caps\n"
sleep $interval
}


You can then launch by entering
--> nohup myprog outputfile 120 &
to send the output to "outputfile" and a 120 second interval.

-- Rod Hills
There be dragons...
Ricardo Bassoi
Regular Advisor

Re: Ksh in backgroung


Harry,

When I tried to put in bg I received the following message:

scpsmp linus> ./edu.sh bassoi 12&
[7] 4735
scpsmp linus> ls
app.lst exp_tpu4.dmp sql total.lst
bassoi exp_tpu4.log srvinst.log updlms.sh
edu.sh exp_tpu4.sh srvman.pl
edu.sh.old nohup.out teste.srvman.sh
[7] + Stopped(SIGTTOU) ./edu.sh bassoi 12&
scpsmp linus>

and so the script stop !!!
If you never try, never will work
harry d brown jr
Honored Contributor

Re: Ksh in backgroung

Ricardo,

repost your script with the changes you made.

live free or die
harry
Live Free or Die
Ricardo Bassoi
Regular Advisor

Re: Ksh in backgroung

Here is the script...

Regards,

Bassoi
If you never try, never will work
Ricardo Bassoi
Regular Advisor

Re: Ksh in backgroung

Here is the script...

Regards,

Bassoi
If you never try, never will work
harry d brown jr
Honored Contributor

Re: Ksh in backgroung

Ricardo,

sorry, try putting this at the top line:

#!/usr/bin/ksh


THen change the "IF's" to this:


if [ "$1" = "" ]; then


if [ "$2" = "" ]; then

live free or die
harry
Live Free or Die
Ricardo Bassoi
Regular Advisor

Re: Ksh in backgroung


Thanks to all !!!

Harry,
The solution using the ksh didn??t work.I used the stuffs like you told but nothing. The script stop with signal termination.
I??m using the Perl solution that works fine. One more doubt : How to monitoring, inside the script, what??s been writting in the output file ?

Regards,

Bassoi
If you never try, never will work
Rodney Hills
Honored Contributor

Re: Ksh in backgroung

use "tail" command-

tail -f yourfile

Will display the last few lines of a file then wait for any additional lines.

-- Rod Hills
There be dragons...