Help with ksh scripting in AIX


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with ksh scripting in AIX
# 8  
Old 08-14-2010
I don't think that will work. I doubt that /etc/filesystems changes. If AIX has a /proc/mtab that might be worth a try.

You can continue to get help here, you don't need my email address or telephone number. Besides, other folks might have better answers than me.

As for your previous question:
Quote:
Somehow error is coming when I execute.
I'm still in the dark here. What error?
# 9  
Old 08-14-2010
I am unable to get the exact script which was corrected by you could u pls help in cropping

I am not able to crop the script what you had mentioned ..Appreciate if you can crop it and sent it ..

thx a lot !

sai

---------- Post updated at 02:39 PM ---------- Previous update was at 01:47 PM ----------

Code:
km17590@cbnap001c[20# ./gopalan
Filesystem    1024-blocks      Free %Used    Iused %Iused Mounted on
/dev/hd4          1048576    907448   14%     3929     2% /
/dev/hd2          2555904   1377372   47%    35234    10% /usr
/dev/hd9var       2097152   1955096    7%     2176     1% /var
/dev/hd3          3145728   3141496    1%       19     1% /tmp
/dev/hd1          2097152   2096484    1%        6     1% /lhome
/proc                   -         -    -         -     -  /proc
/dev/hd10opt      2097152    972580   54%     8828     4% /opt
/dev/exportlv       65536     64140    3%        7     1% /export
/dev/optwarelv       65536     64156    3%        5     1% /optware
/dev/orabinlv     2097152   2088308    1%        5     1% /optware/oracle
/dev/ndmbinlv     1048576    877836   17%     1485     1% /opt/cdunix
/dev/oraclntlv     4849664   2493804   49%     8768     2% /opt/oraClient
/dev/optswlv     10551296   8495064   20%     6072     1% /opt/sw
/dev/cbnadlv        65536     64136    3%       19     1% /cbnad
/dev/cbnabkplv       65536     64140    3%        8     1% /cbnabkp
/dev/lvabinit1     3145728   2052348   35%     5968     2% /opt/sw/abinitio
/dev/lvappl       4849664   4091500   16%     6307     1% /cbnad/data/appl
/dev/lveme       10354688   6994392   33%       89     1% /cbnad/data/eme
/dev/lvadmd1     10354688  10263764    1%     1338     1% /cbnad/data/admin
/dev/lvserial   314572800 305906528    3%     1382     1% /cbnad/data/serial
/dev/lvdata01   681574400 544718576   21%     1371     1% /cbnad/data/data01
/dev/lvdata02   681574400 544556824   21%     1370     1% /cbnad/data/data02
/dev/lvdata03   681574400 545085816   21%     1370     1% /cbnad/data/data03
/dev/lvdata04   681574400 544268116   21%     1370     1% /cbnad/data/data04
/dev/lvmeta1     10485760  10442876    1%        4     1% /cbnad/data/meta
/dev/lvabini1     2097152   2075244    2%     3026     1% /cbnad/data/abinitio
/dev/lvstage1   283115520 189556728   34%     2183     1% /cbnad/data/stage
/dev/lvfeed1   1730150400 1722278156    1%      491     1% /cbnad/feed
/dev/lvstage2     2228224   2218340    1%        4     1% /stage
/dev/lvcmmigr     1048576   1039896    1%        4     1% /cmmigr
/dev/lvbkdata1   131727360 131191920    1%        4     1% /cbnabkp/data01
/dev/lvbkdata2   131727360 131191920    1%        4     1% /cbnabkp/data02
/dev/lvbkdata3   131727360 131191920    1%        4     1% /cbnabkp/data03
/dev/lvbkdata4   131727360 131191920    1%        4     1% /cbnabkp/data04
/dev/lveers1       524288    519784    1%        4     1% /cbnad/EERS
/dev/expoptibmlv     6291456   3149788   50%    26575     4% /export/opt/IBM
/dev/expoptzloclv    10485760   6085100   42%    12920     1% /export/opt/z_local
/dev/performlv      786432    584864   26%     2021     2% /opt/perform
/dev/sshcntllv     1048576   1039892    1%        5     1% /opt/sw/sshcntl
nasswd10v1prd.nam.nsroot.net:/vol/ClearCase/cbnabi    61656272  52672936   15%     4079     1% /net/nasswd10v1prd/vol/ClearCase/cbnabi
cchome01.core.afcc.com:/export/home   282066944  52152264   82%   839861    34% /home/cchome01
grep: can't open
grep: can't open
grep: can't open
grep: can't open
grep: can't open
grep: can't open
grep: can't open
grep: can't open
grep: can't open
grep: can't open
grep: can't open
grep: can't open
grep: can't open
grep: can't open
grep: can't open
grep: can't open
grep: can't open
grep: can't open
grep: can't open
grep: can't open
grep: can't open
grep: can't open
grep: can't open
grep: can't open
grep: can't open
grep: can't open
grep: can't open
grep: can't open
grep: can't open
grep: can't open
grep: can't open
grep: can't open
grep: can't open
grep: can't open
grep: can't open
grep: can't open
grep: can't open
grep: can't open
grep: can't open
(Interrupt -- one more to kill letter)

And the script is here

Code:
  +1  # think the hostname is available as the preset var HOSTNAME.
    +2  # HOSTNM=`hostname`
    +3  DATE=$(date +"%d-%b-%y %H:%M")
    +4  SHORTNAME="FileSystem Mount"
    +5  LONGNAME="Filesystem check"
    +6  #I don't think grep supports |, just egrep.
    +7  # You can also break apart really, really long lines with backslashes
    +8  # so that it doesn't stretch your editor 3 miles wide.
    +9  #checking filesystem if its mounted or not
   +10  df -k |egrep '
   +11  [/dev/hd4|/dev/hd2|/dev/hd9var|/dev/hd3|/dev/hd1|/proc|/dev/hd10opt|/dev/exportlv|/dev/optwarelv|/dev/orabinlv|/dev/ndmbinlv|/dev/oraclntlv|/dev/opts
wlv|/dev/cbnadlv|/dev/cbnabkplv|/dev/lvabinit1|/dev/lvappl|/dev/lveme|/dev/lvadmd1|/dev/lvserial|/dev/lvdata01|/dev/lvdata02|/dev/lvdata03|/dev/lvdata04|/dev
/lvmeta1|/dev/lvabini1|/dev/lvstage1|/dev/lvfeed1|/dev/lvstage2|/dev/lvcmmigr|/dev/lvbkdata1|/dev/lvbkdata2|/dev/lvbkdata3|/dev/lvbkdata4|/dev/lveers1| /dev/
expoptibmlv|/dev/expoptzloclv|/dev/performlv|/dev/sshcntllv|nasswd10v1prd.nam.nsroot.net:/vol/ClearCase/cbnabi|cchome01.core.afcc.com:/export/home]'>d.txt
   +12
   +13  # You can't just stick a file into []'s and expect it to work!
   +14  # You're probably trying to check the return code of grep instead, right?
   +15  # unfortunately, grep isn't going to work here since it'll return OK even if it
   +16  # finds only ONE of these filesystems.
   +17  #if [ d.txt == "1" ]
   +18  #then
   +19  #mail -s "Filesystem check pls inestigate "$DATE" "$HOSTNM" xx@domain.com
   +20  #else
   +21  #mail -s "Filesystem check success  $DATE HOSTNM " xx@domain.com
   +22  #fi
   +23  #exit
   +24
   +25  SUCCESS=0
   +26  # Create a temp file with a secure random name.
   +27  TMP=`mktemp`
   +28  df -k >$TMP
   +29  # Loop through each of these filesystems/paths individually.
   +30  # if I knew AIX well enough I might try reading from /etc/fstab instead
   +31  for DEV in  /dev/hd4 /dev/hd2 /dev/hd9var /dev/hd3 /dev/hd1 \
   +32          /proc /dev/hd10opt /dev/exportlv /dev/optwarelv \
   +33          /dev/orabinlv/dev/ndmbinlv /dev/oraclntlv /dev/optswlv \
   +34          /dev/cbnadlv /dev/cbnabkplv /dev/lvabinit1 /dev/lvappl \
   +35          /dev/lveme /dev/lvadmd1 /dev/lvserial /dev/lvdata01 \
   +36          /dev/lvdata02 /dev/lvdata03 /dev/lvdata04 /dev/lvmeta1 \
   +37          /dev/lvabini1 /dev/lvstage1 /dev/lvfeed1 /dev/lvstage2 \
   +38          /dev/lvcmmigr /dev/lvbkdata1 /dev/lvbkdata2 /dev/lvbkdata3 \
   +39          /dev/lvbkdata4 /dev/lveers1 /dev/expoptibmlv \
   +40          /dev/expoptzloclv /dev/performlv/dev/sshcntllv\
   +41          nasswd10v1prd.nam.nsroot.net:/vol/ClearCase/cbnabi \
   +42          cchome01.core.afcc.com:/export/home
   +43  do
   +44          # Check if grep can find the device in the file.  If not, set SUCCESS=1.
   +45          # The -q flag tells grep to not print anything, all we need is the return code.
   +46          grep -i "${DEV}" "${TMP}" || SUCCESS=1
   +47  done
   +48  # Delete the temp file.
   +49  rm -f "$TMP"
   +50
   +51  if [ "${SUCCESS}" -eq 0 ]
   +52  then
   +53         mail -s "Filesystem check success $DATE $HOSTNAME" xx@domain.com
   +54  else
   +55         mail -s "Filesystem check pls inestigate $DATE $HOSTNAME" xx@domain.com
   +56  fi


Last edited by Scott; 08-14-2010 at 03:48 PM.. Reason: Code tags, please...
# 10  
Old 08-14-2010
AIX doesn't even have mktemp? Good grief...

Replace TMP=`mktemp` with TMP=/tmp/$$

You should also be commenting out or removing lines 10 and 11.
This User Gave Thanks to Corona688 For This Post:
# 11  
Old 08-14-2010
I think error is gone but the script is hanging

I am attaching the output when i run the script

Code:
km17590@cbnap001c[36]# ./gopalan
/dev/hd4          1048576    906760   14%     3929     2% /
/dev/hd2          2555904   1377372   47%    35234    10% /usr
/dev/hd9var       2097152   1954460    7%     2177     1% /var
/dev/hd3          3145728   3141492    1%       21     1% /tmp
/dev/hd1          2097152   2096484    1%        6     1% /lhome
/dev/hd10opt      2097152    976960   54%     8828     4% /opt
/proc                   -         -    -         -     -  /proc
/dev/hd10opt      2097152    976960   54%     8828     4% /opt
/dev/exportlv       65536     64140    3%        7     1% /export
/dev/optwarelv       65536     64156    3%        5     1% /optware
/dev/oraclntlv     4849664   2493804   49%     8768     2% /opt/oraClient
/dev/optswlv     10551296   8495064   20%     6072     1% /opt/sw
/dev/cbnadlv        65536     64136    3%       19     1% /cbnad
/dev/cbnabkplv       65536     64140    3%        8     1% /cbnabkp
/dev/lvabinit1     3145728   2052348   35%     5968     2% /opt/sw/abinitio
/dev/lvappl       4849664   4091500   16%     6307     1% /cbnad/data/appl
/dev/lveme       10354688   6994392   33%       89     1% /cbnad/data/eme
/dev/lvadmd1     10354688  10263764    1%     1338     1% /cbnad/data/admin
/dev/lvserial   314572800 305906528    3%     1382     1% /cbnad/data/serial
/dev/lvdata01   681574400 544718576   21%     1371     1% /cbnad/data/data01
/dev/lvdata02   681574400 544556824   21%     1370     1% /cbnad/data/data02
/dev/lvdata03   681574400 545085816   21%     1370     1% /cbnad/data/data03
/dev/lvdata04   681574400 544268116   21%     1370     1% /cbnad/data/data04
/dev/lvmeta1     10485760  10442876    1%        4     1% /cbnad/data/meta
/dev/lvabini1     2097152   2075244    2%     3026     1% /cbnad/data/abinitio
/dev/lvstage1   283115520 189556728   34%     2183     1% /cbnad/data/stage
/dev/lvfeed1   1730150400 1722278156    1%      491     1% /cbnad/feed
/dev/lvstage2     2228224   2218340    1%        4     1% /stage
/dev/lvcmmigr     1048576   1039896    1%        4     1% /cmmigr
/dev/lvbkdata1   131727360 131191920    1%        4     1% /cbnabkp/data01
/dev/lvbkdata2   131727360 131191920    1%        4     1% /cbnabkp/data02
/dev/lvbkdata3   131727360 131191920    1%        4     1% /cbnabkp/data03
/dev/lvbkdata4   131727360 131191920    1%        4     1% /cbnabkp/data04
/dev/lveers1       524288    519784    1%        4     1% /cbnad/EERS
/dev/expoptibmlv     6291456   3149788   50%    26575     4% /export/opt/IBM
/dev/expoptzloclv    10485760   6085092   42%    12920     1% /export/opt/z_local
nasswd10v1prd.nam.nsroot.net:/vol/ClearCase/cbnabi    61656272  52672936   15%     4079     1% /net/nasswd10v1prd/vol/ClearCase/cbnabi
cchome01.core.afcc.com:/export/home   282066944  52152264   82%   839861    34% /home/cchome01
(Interrupt -- one more to kill letter)

The script is not terminating

I am attaching the script which is corrected as per your advice
Code:
km17590@cbnap001c[37]# vi gopalan
"gopalan" 57 lines, 2889 characters
    +1  # think the hostname is available as the preset var HOSTNAME.
    +2  # HOSTNM=`hostname`
    +3  DATE=$(date +"%d-%b-%y %H:%M")
    +4  SHORTNAME="FileSystem Mount"
    +5  LONGNAME="Filesystem check"
    +6  #I don't think grep supports |, just egrep.
    +7  # You can also break apart really, really long lines with backslashes
    +8  # so that it doesn't stretch your editor 3 miles wide.
    +9  #checking filesystem if its mounted or not
   +10  df -k |egrep '
   +11  [/dev/hd4|/dev/hd2|/dev/hd9var|/dev/hd3|/dev/hd1|/proc|/dev/hd10opt|/dev/exportlv|/dev/optwarelv|/dev/orabinlv|/dev/ndmbinlv|/dev/oraclntlv|/dev/opts
wlv|/dev/cbnadlv|/dev/cbnabkplv|/dev/lvabinit1|/dev/lvappl|/dev/lveme|/dev/lvadmd1|/dev/lvserial|/dev/lvdata01|/dev/lvdata02|/dev/lvdata03|/dev/lvdata04|/dev
/lvmeta1|/dev/lvabini1|/dev/lvstage1|/dev/lvfeed1|/dev/lvstage2|/dev/lvcmmigr|/dev/lvbkdata1|/dev/lvbkdata2|/dev/lvbkdata3|/dev/lvbkdata4|/dev/lveers1| /dev/
expoptibmlv|/dev/expoptzloclv|/dev/performlv|/dev/sshcntllv|nasswd10v1prd.nam.nsroot.net:/vol/ClearCase/cbnabi|cchome01.core.afcc.com:/export/home]'>d.txt
   +12
   +13  # You can't just stick a file into []'s and expect it to work!
   +14  # You're probably trying to check the return code of grep instead, right?
   +15  # unfortunately, grep isn't going to work here since it'll return OK even if it
   +16  # finds only ONE of these filesystems.
   +17  #if [ d.txt == "1" ]
   +18  #then
   +19  #mail -s "Filesystem check pls inestigate "$DATE" "$HOSTNM" xx@domain.com
   +20  #else
   +21  #mail -s "Filesystem check success  $DATE HOSTNM " xx@domain.com
   +22  #fi
   +23  #exit
   +24
   +25  SUCCESS=0
   +26  # Create a temp file with a secure random name.
   +27  TMP=/tmp/$$
   +28  df -k >$TMP
   +29  # Loop through each of these filesystems/paths individually.
   +30  # if I knew AIX well enough I might try reading from /etc/fstab instead
   +31  for DEV in  /dev/hd4 /dev/hd2 /dev/hd9var /dev/hd3 /dev/hd1 \
   +32          /proc /dev/hd10opt /dev/exportlv /dev/optwarelv \
   +33          /dev/orabinlv/dev/ndmbinlv /dev/oraclntlv /dev/optswlv \
   +34          /dev/cbnadlv /dev/cbnabkplv /dev/lvabinit1 /dev/lvappl \
   +35          /dev/lveme /dev/lvadmd1 /dev/lvserial /dev/lvdata01 \
   +36          /dev/lvdata02 /dev/lvdata03 /dev/lvdata04 /dev/lvmeta1 \
   +37          /dev/lvabini1 /dev/lvstage1 /dev/lvfeed1 /dev/lvstage2 \
   +38          /dev/lvcmmigr /dev/lvbkdata1 /dev/lvbkdata2 /dev/lvbkdata3 \
   +39          /dev/lvbkdata4 /dev/lveers1 /dev/expoptibmlv \
   +40          /dev/expoptzloclv /dev/performlv/dev/sshcntllv\
   +41          nasswd10v1prd.nam.nsroot.net:/vol/ClearCase/cbnabi \
   +42          cchome01.core.afcc.com:/export/home
   +43  do
   +44          # Check if grep can find the device in the file.  If not, set SUCCESS=1.
   +45          # The -q flag tells grep to not print anything, all we need is the return code.
   +46          grep -i "${DEV}" "${TMP}" || SUCCESS=1
   +47  done
   +48  # Delete the temp file.
   +49  rm -f "$TMP"
   +50
   +51  if [ "${SUCCESS}" -eq 0 ]
   +52  then
   +53         mail -s "Filesystem check success $DATE $HOSTNAME" xx@domain.com
   +54  else
   +55         mail -s "Filesystem check pls inestigate $DATE $HOSTNAME" xx@domain.com
   +56  fi
   +57  exit


Last edited by Scott; 08-16-2010 at 05:29 PM.. Reason: Code tags, PLEASE!
# 12  
Old 08-14-2010
No it's not. You still need to comment out or remove lines 10 and 11.
This User Gave Thanks to Corona688 For This Post:
# 13  
Old 08-14-2010
the script doesnt email and terminating ..Where is the mistake?Pls guide

I have done that still its not terminating.Pls help

thx!
sai
# 14  
Old 08-16-2010
Please post the corrected script.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

KSH scripting

Hi Guys, I am trying to learn to script. first I have 2 server, A and B. A with IP 192.168.82.22. B with IP 192.168.82.44. Both with login user admin and password admin. server A will generate a file every day with name gg.log under /app/gg/20171002.log. I wish to write a script to copy the... (7 Replies)
Discussion started by: leecopper
7 Replies

2. Shell Programming and Scripting

ksh scripting

Hi All, Can you please let me know what I missed in the below function? Whenever I try to execute the script i am getting syntax error at line 101 : `fi' unexpected Function is function DELNWE5O { export ORACLE_HOME=/ora00/app/oracle/product/11.2.0/grid_1 export... (9 Replies)
Discussion started by: pvmanikandan
9 Replies

3. Shell Programming and Scripting

AIX 5.3 ksh Scripting

Hi, I posted a request for sever OS types earlier, but got no response. In an attempt to at least have a starting point, I think scaling it to one OS is preferred. Once I see the gist of it I can modify to account for different cases. I need a script that will go and check to see if an LDAP... (2 Replies)
Discussion started by: tekster2
2 Replies

4. Shell Programming and Scripting

help with ksh shell scripting

I want to run a script that checks the env to see if I'm in a test or prod environment. From the command line I enter echo $host and it returns host name and I can tell by the name if I'm in test or prod. When I run the command from a script I get "not found" What's wrong with the script? if ... (2 Replies)
Discussion started by: Bperl1967
2 Replies

5. Shell Programming and Scripting

help in ksh scripting in aix

Hello gurus I am looking for a script : We need to generate a file list created by user id on a AIX box. Criteria 1: other than userid : dwimpid & aiadmin Criteria 2: Files older than 2 months ( it can be any user id ). File Path to Look: /project and /project1 Thx silu (7 Replies)
Discussion started by: silu
7 Replies

6. Shell Programming and Scripting

Need help in writing AIX ksh scripting

I need to write the script for the below constraints. Need your help urgently The PATH environment variable must conform to the following: • World-writeable directories (/tmp, /var/tmp etc) must not be placed in the PATH variable. • System directories must always be placed before local... (1 Reply)
Discussion started by: kmvinay
1 Replies

7. Shell Programming and Scripting

ksh scripting help

I have the file as below server1 no dr aix 5300-05-03 9119-595 20-18888 yes ftp-eagle server2 no dr aix 5300-05-03 9119-595 20-18888 yes ftp-eagle server3 yes dr aix 5300-05-03 9119-595 20-18888 yes ftp-eagle server4 ... (1 Reply)
Discussion started by: praveenbvarrier
1 Replies

8. Shell Programming and Scripting

Need help with KSH scripting

Hi I need to insert a page break into a file based on matching a phrase in the file. :confused: I am doing this with a ksh script on a Unix box. Any help would be greatly appreciated. Thanks (5 Replies)
Discussion started by: scrappycc
5 Replies

9. Shell Programming and Scripting

scripting guru's pls help me with scripting on AIX

can someone pls help me with the script for a files coming from one system to a particular directory and i want to write a script to move those files to another directory on different system by renaming the files... pls someone help me on this... thanking in anticipation.... (1 Reply)
Discussion started by: thatiprashant
1 Replies

10. Shell Programming and Scripting

KSH Scripting

Will a shell script written in shell for HP/UX run on Solaris? (1 Reply)
Discussion started by: dstaller
1 Replies
Login or Register to Ask a Question