Help understanding the script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help understanding the script
# 15  
Old 10-14-2016
I cannot cite the output format of all the NIM-commands from memory, but i think the whole script can be replaced by one NIM-command executed. If you do a mksysb from the NIM server a resource of the type MKSYSB is created and entered into the NIMs database, which can subsequently be queried.

You will have to wait until monday when i return to office for details, but i think it will be possible to replace the whole script with a few select lines of code.

I hope this helps.

bakunin
# 16  
Old 10-17-2016
Hello Bakunin,

Thanks for the offer to help, I look forward to hearing back from you.


Thanks
# 17  
Old 10-17-2016
OK, being at the office and sitting in front of an xterm pointing at my NIM server does wonders for that old brain of mine ...

Here it is: you can get a list of all NIM objects of a certain type. In this case you are interested in the resources of type "mksysb". Do yourself a favour and, when you take the mksysb with NIM means, give it a proper name. In my case this means: hostname plus a suffix. Issue:

Code:
root@nim-server # lsnim -t mksysb | more
aix71_04_02                     resources       mksysb
system_1_mksysb                 resources       mksysb
system_2_mksysb                 resources       mksysb
system_3_mksysb                 resources       mksysb
[...]

If you work your NIM-server like me you perhaps have some installation-images as mksysbs which you use to instll new systems (see above, the aix71_04_02) and the images of the various installed LPARs you take regularly (the others in the list above). Now filter out all the installation images so that only the systems are left and cycle through them, using the -l command line option of lsnim to see the details:

Code:
# lsnim -l system_1_mksysb
system_1_mksysb:
   class         = resources
   type          = mksysb
   creation_date = Sat Oct 15 21:10:56 2016
   source_image  = system_1
   arch          = power
   Rstate        = ready for use
   prev_state    = unavailable for use
   location      = /export/mksysb/sys.mksysb
   version       = 7
   release       = 1
   mod           = 3
   oslevel_r     = 7100-03
   oslevel_s     = 7100-03
   alloc_count   = 0
   server        = master

For instance, a (quick and dirty) code fragment that lists the systems and the creation date of their respective mksysbs, supposing your naming convention is like mine, would be (remove the comments to actually run it):

Code:
lsnim -t mksysb | grep -v '^aix' |\                 # filter out install-images
while read MKSYSB junk ; do                         # read only the mksysb-names
     lpar="${MKSYSB%%_mksysb}"                      # cut off trailing "_mksysb"
     cdate=$(lsnim -l $MKSYSB |\                    # trim o/p to creation date
             sed -n '/creation_date/ s/^.*= //p' \
            )
     print - "$lpar  $cdate"                        # print results
done

I am aware that this is only the sketch of a solution, but it should be fairly straightforward to implement that into a script.

I hope this helps.

bakunin
# 18  
Old 10-17-2016
Code:
./agedays.pl
Day '' out of range 1..31 at ./agedays.pl line 10

I am getting this error for the code below

Code:
#!//usr/local/bin/perl
use POSIX;
use Time::Local;

my %mon;
@mon{qw/Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec/} = 0..11;

my ($mmm, $dd, $yy) = split(/[-\/ ]/, $ARGV[0]);

printf "%.0f", (time() - timelocal(0,0,0,$dd,$mon{$mmm}, $yy) - 0.4999) / (24*60*60);

# 19  
Old 10-17-2016
Hi,

Note that your script, in line number 8 expects commandline argument but you did not pass it as per your post#18.

Code:
my ($mmm, $dd, $yy) = split(/[-\/ ]/, $ARGV[0]);

Try running with arg as follows (example):
Code:
.agedays.pl /12/10/2016

Refer CPAN for more : Time::Local
# 20  
Old 10-18-2016
Since I will be calling agedays.pl in the other script, how do I use the date with agedays.pl in the other script.
# 21  
Old 10-18-2016
Hi,

Did you see post#9 written by Chubler_XL ?
Not sure, what you really meant ?
Check if below example helps .

Code:
cat try.sh
#!/bin/bash

datev=$(date +%D)
./1.pl $datev

Below perl code is same as from post#9 .

Code:
cat 1.pl
#!/usr/bin/perl
use POSIX;
use Time::Local;

my %mon;
@mon{qw/Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec/} = 0..11;

my ($mmm, $dd, $yy) = split(/[-\/ ]/, $ARGV[0]);

printf "%.0f\n", (time() - timelocal(0,0,0,$dd,$mon{$mmm}, $yy) - 0.4999) / (24*60*60);

Run it as :
Code:
./try.sh

Gives output:
Quote:
275
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Understanding a script for sum

Hello, How come the following script adds each numeric value to a total sum ? x=$1 func() { for i in $1 $2 $3; do let x= $x+$i done } func "8 8 8" 9 9 echo $x A.How the program sums the string "8 8 8" if it`s only the first field value ($1)? B.If we define x to be $1... (3 Replies)
Discussion started by: uniran
3 Replies

2. UNIX for Beginners Questions & Answers

Shall script use and understanding

Below script is called as Reducer, I am not sure how it work, can some expert explain me what this script does as i am a beginner. inputfile: hi hi how are are you code: #!/bin/bash lastkey=""; -- what does this mean, because i saw in debug mode it is taking value as hi count=0;... (13 Replies)
Discussion started by: mirwasim
13 Replies

3. Shell Programming and Scripting

Help--understanding the script

Hi, New to this forum, as well as to unix scripting..need help to understand below script ... sendNotice_sp() { ATTACH=${LNXLOG:-} if ; then if ; then mail -s "$ERR_MSG" $ERR_EMAIL_TO < $ATTACH fi else mail -s "$ERR_MSG" $ERR_EMAIL_TO < /dev/null fi } afaik this is sm kind of... (6 Replies)
Discussion started by: gnnsprapa
6 Replies

4. Shell Programming and Scripting

Help understanding the script

Hi Guys, I am new to scripting , I am trying to rebuild a script based on an old script. Can someone help me figure out what the script is doing? This is only a part of the script. I am looking to interpret these two points in the scripts:- 1) test=`echo $?` while I do not... (3 Replies)
Discussion started by: rajsan
3 Replies

5. UNIX for Dummies Questions & Answers

help with understanding script

i am trying to understand this script example. the text does not explain it. can someone tell me briefly what each of the functions do. any help will be appreciated. #!/bin/bash killtree() { local _pid=$1 local _sig=${2-TERM} for _child in $(ps -o pid --no-headers --ppid... (1 Reply)
Discussion started by: iluvsushi
1 Replies

6. Shell Programming and Scripting

Need help understanding this script.

Can someone explain what is happening line by line in this script, particularly after the do statement. The script works, it renames all the files in my directory that has a date in the file name. But I would like to know more about it. #!/bin/bash newdate=12-10-1995 for file in *--* do ... (6 Replies)
Discussion started by: Harleyrci
6 Replies

7. UNIX for Advanced & Expert Users

understanding awk in this script

i am analyzing a query written by another developer ,need to understand part of script am looking at a code ..and it converts comma files to pipe delimited and also takes away quotes from any columns, source field format: 2510,"Debbie",NewYork changes to target: 2510|Debbie|NewYork ... (1 Reply)
Discussion started by: coolrock
1 Replies

8. Shell Programming and Scripting

Need help for understanding of script

# sub: find block (in cols), return line-numbers (begin-end) or 0 if notfound sub findb{ my ($exp1,$col1,$exp2,$col2)= @_; # $exp = expression to find, $col - column to search in my $cnt=0; my ($val1,$val2); my ($beg,$end); for($cnt=1;$cnt<=65536;$cnt++){ $val1 =... (3 Replies)
Discussion started by: suvenduperl
3 Replies

9. Shell Programming and Scripting

Help understanding a script

Hello everybody, Can anybody tell me of what "~" refers to in the below code snippet. lsvg $vgNAME | awk 'BEGIN {freeDISK=1} {if (($4 ~ /PP/ && $5 ~ /SIZE/) || ($4 ~ /FREE/ && $5 ~ /PPs/)) {freeDISK *= $6 }} END {print freeDISK*1024 }' Thanks in advance, (6 Replies)
Discussion started by: tenderfoot
6 Replies

10. UNIX for Dummies Questions & Answers

Need help understanding script command

We use a UNIX-based system (Lawson) at work and I was given this command to request a data extract from the db admin. The only thing I really understand is the last line as it appears to be joining the files created from the first three lines into one. Is there anyone who can help me breakdown the... (4 Replies)
Discussion started by: KGee
4 Replies
Login or Register to Ask a Question